Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed May 9, 2024
1 parent 1fa72dc commit c7d6a80
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
27 changes: 18 additions & 9 deletions R/chi_squared_test.R
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ chi_squared_test <- function(data,

# return result
out <- data.frame(
data = paste(select, "by", by),
statistic_name = "Chi-squared",
statistic = test_statistic,
effect_size_name = names(effect_size),
Expand Down Expand Up @@ -156,6 +157,11 @@ chi_squared_test <- function(data,

# return result
out <- data.frame(
data = paste(
select,
"against probabilities",
datawizard::text_concatenate(sprintf("%i%%", round(100 * probabilities)))
),
statistic_name = "Chi-squared",
statistic = test_statistic,
effect_size_name = "Fei",
Expand Down Expand Up @@ -183,21 +189,24 @@ print.sj_htest_chi <- function(x, ...) {
weight_string <- ""
}

# get length of method name, to align output
l <- max(nchar(c(x$statistic_name, x$effect_size_name, "p-value", "Observations")))
# headline
insight::print_color(sprintf(
"\n# Chi-Squared Test for %s%s\n\n",
attributes(x)$caption,
weight_string
), "blue")

stat_symbol <- .format_symbols(x$effect_size_name)
# data info
if (!is.null(x$data)) {
insight::print_color(sprintf(" Data: %s (n = %i)\n", x$data, round(x$n_obs)), "cyan")
}

# prepare and align strings
eff_symbol <- .format_symbols(x$effect_size_name)
stat_symbol <- .format_symbols(x$statistic_name)

# print test statistic
cat(sprintf(" %*s: %.4f\n", l, x$statistic_name, x$statistic))
cat(sprintf(" %*s: %.4f\n", l, stat_symbol, x$effect_size))
cat(sprintf(" %*s: %g\n", l, "df", x$df))
cat(sprintf(" %*s: %s\n", l, "p-value", insight::format_p(x$p, stars = TRUE, name = NULL)))
cat(sprintf(" %*s: %g\n", l, "Observations", x$n_obs))
cat(sprintf(
"\n %s = %.4f, %s = %.4f, df = %i, %s\n\n",
stat_symbol, x$statistic, eff_symbol, x$effect_size, round(x$df), insight::format_p(x$p)
))
}
1 change: 1 addition & 0 deletions R/helpfunctions.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ get_grouped_data <- function(x) {
x <- gsub("Omega", "ε", x, ignore.case = TRUE)
x <- gsub("R2", "", x, ignore.case = TRUE)
x <- gsub("Chi2", "χ²", x, ignore.case = TRUE)
x <- gsub("Chi-squared", "χ²", x, ignore.case = TRUE)
x <- gsub("Chi", "χ", x, ignore.case = TRUE)
x <- gsub("Sigma", "σ", x, ignore.case = TRUE)
x <- gsub("Rho", "ρ", x, ignore.case = TRUE)
Expand Down

0 comments on commit c7d6a80

Please sign in to comment.