Skip to content

Commit

Permalink
oneway.test: `Error in paste0(out$interpretation, " (", out$statistic…
Browse files Browse the repository at this point in the history
…s, ")"): object 'out' not found` (#441)

* oneway.test: `Error in paste0(out$interpretation, " (", out$statistics, ")"): object 'out' not found`
Fixes #394

* fix
  • Loading branch information
strengejacke authored Jun 27, 2024
1 parent d8feb3f commit 4c60ac3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 44 deletions.
2 changes: 1 addition & 1 deletion R/report.htest.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ report_effectsize.htest <- function(x, ...) {

# TODO: Chi-squared test -------------

if (model_info$is_proptest || (model_info$is_xtab && !model_info$is_chi2test)) {
if (model_info$is_proptest || (model_info$is_xtab && !model_info$is_chi2test) || model_info$is_onewaytest) {
stop(insight::format_message(
"This test is not yet supported. Please open an issue at {.url https://github.com/easystats/report/issues}."
), call. = FALSE)
Expand Down
73 changes: 30 additions & 43 deletions R/report_htest_chi2.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,46 +9,35 @@
# report_effectsize ---------------------

.report_effectsize_chi2 <- function(x, table, dot_args, rules = "funder2019") {
if (chi2_type(x) %in% c("pearson", "probabilities")) {
args <- c(list(x), dot_args)
table <- do.call(effectsize::effectsize, args)
table_footer <- attributes(table)$table_footer
ci <- attributes(table)$ci
estimate <- names(table)[1]
rules <- ifelse(is.null(dot_args$rules), rules, dot_args$rules)

args <- c(list(table, rules = rules), dot_args)
interpretation <- do.call(effectsize::interpret, args)$Interpretation
rules <- .text_effectsize(attr(attr(interpretation, "rules"), "rule_name"))
} else {
stop(insight::format_message(
if (!chi2_type(x) %in% c("pearson", "probabilities")) {
insight::format_error(
"This test is not yet supported. Please open an issue at {.url https://github.com/easystats/report/issues}."
), call. = FALSE)
}

if (estimate == "Cramers_v_adjusted") {
main <- paste0("Adjusted Cramer's v = ", insight::format_value(table[[estimate]]))
} else if (estimate == "Fei") {
main <- paste0("Fei = ", insight::format_value(table[[estimate]]))
} else if (estimate == "Tschuprows_t") {
main <- paste0("Tschuprow's t = ", insight::format_value(table[[estimate]]))
} else if (estimate == "Tschuprows_t_adjusted") {
main <- paste0("Adjusted Tschuprow's t = ", insight::format_value(table[[estimate]]))
} else if (estimate == "Pearsons_c") {
main <- paste0("Pearson's c = ", insight::format_value(table[[estimate]]))
} else if (estimate == "phi_adjusted") {
main <- paste0("Adjusted Phi = ", insight::format_value(table[[estimate]]))
} else if (estimate == "Cohens_h") {
main <- paste0("Cohen's h = ", insight::format_value(table[[estimate]]))
} else if (estimate == "Odds_ratio") {
main <- paste0("Odds ratio = ", insight::format_value(table[[estimate]]))
} else if (estimate == "Ris_kratio") {
main <- paste0("Risk ratio = ", insight::format_value(table[[estimate]]))
} else if (estimate == "cohens_h") {
main <- paste0("Cohen's w = ", insight::format_value(table[[estimate]]))
} else {
main <- paste0(estimate, " = ", insight::format_value(table[[estimate]]))
)
}
es_args <- c(list(x), dot_args)
table <- do.call(effectsize::effectsize, es_args)
table_footer <- attributes(table)$table_footer
ci <- attributes(table)$ci
estimate <- names(table)[1]
rules <- ifelse(is.null(dot_args$rules), rules, dot_args$rules)

es_args <- c(list(table, rules = rules), dot_args)
interpretation <- do.call(effectsize::interpret, es_args)$Interpretation
rules <- .text_effectsize(attr(attr(interpretation, "rules"), "rule_name"))

main <- switch(estimate,
Cramers_v_adjusted = paste0("Adjusted Cramer's v = ", insight::format_value(table[[estimate]])),
Fei = paste0("Fei = ", insight::format_value(table[[estimate]])),
Tschuprows_t = paste0("Tschuprow's t = ", insight::format_value(table[[estimate]])),
Tschuprows_t_adjusted = paste0("Adjusted Tschuprow's t = ", insight::format_value(table[[estimate]])),
Pearsons_c = paste0("Pearson's c = ", insight::format_value(table[[estimate]])),
phi_adjusted = paste0("Adjusted Phi = ", insight::format_value(table[[estimate]])),
Cohens_h = paste0("Cohen's h = ", insight::format_value(table[[estimate]])),
Odds_ratio = paste0("Odds ratio = ", insight::format_value(table[[estimate]])),
Ris_kratio = paste0("Risk ratio = ", insight::format_value(table[[estimate]])),
cohens_h = paste0("Cohen's w = ", insight::format_value(table[[estimate]])),
paste0(estimate, " = ", insight::format_value(table[[estimate]]))
)

statistics <- paste0(
main,
Expand Down Expand Up @@ -79,24 +68,22 @@
vars_full <- paste0(names(attributes(x$observed)$dimnames), collapse = " and ")
} else if (chi2_type(x) == "probabilities") {
type <- " / goodness of fit of "
dist <- ifelse(
distr <- ifelse(
grepl("non", attr(table, "table_footer"), fixed = TRUE), "a uniform distribution",
paste0("a distribution of [", paste0(
names(x$expected), ": n=", x$expected,
collapse = ", "
), "]")
)

vars_full <- paste(x$data.name, "to", dist)
vars_full <- paste(x$data.name, "to", distr)
}

text <- paste0(
paste0(
trimws(x$method),
type,
paste0(" ", vars_full)
)

text
}

chi2_type <- function(x) {
Expand Down

0 comments on commit 4c60ac3

Please sign in to comment.