-
-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add kruskal method * fix tests errors, add tests/testthat/helper-state.R * style and skip helper-state.R for this PR * comment helper-state.R * trigger tests again
- Loading branch information
Showing
7 changed files
with
143 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# report_table ----------------- | ||
|
||
.report_table_kruskal <- function(table_full, effsize) { | ||
table_full <- cbind(table_full, attributes(effsize)$table) | ||
list(table = NULL, table_full = table_full) | ||
} | ||
|
||
|
||
# report_effectsize --------------------- | ||
|
||
.report_effectsize_kruskal <- function(x, table, dot_args, rules = "funder2019") { | ||
args <- c(list(x), dot_args) | ||
table <- do.call(effectsize::effectsize, args) | ||
ci <- attributes(table)$ci | ||
estimate <- names(table)[1] | ||
|
||
rules <- ifelse(is.null(dot_args$rules), rules, dot_args$rules) | ||
|
||
# same as Pearson's r | ||
args <- c(list(table$rank_epsilon_squared), dot_args) | ||
interpretation <- do.call(effectsize::interpret_epsilon_squared, args) | ||
rules <- .text_effectsize(attr(attr(interpretation, "rules"), "rule_name")) | ||
|
||
main <- paste0("Epsilon squared (rank) = ", insight::format_value(table$rank_epsilon_squared)) | ||
statistics <- paste0( | ||
main, | ||
", ", | ||
insight::format_ci(table$CI_low, table$CI_high, ci) | ||
) | ||
|
||
table <- table[names(table)[-2]] | ||
|
||
list( | ||
table = table, statistics = statistics, interpretation = interpretation, | ||
rules = rules, ci = ci, main = main | ||
) | ||
} | ||
|
||
|
||
# report_model ---------------------------- | ||
|
||
.report_model_kruskal <- function(x, table) { | ||
# two-sample | ||
if ("Parameter1" %in% names(table)) { | ||
vars_full <- paste0(table$Parameter1[[1]], ", and ", table$Parameter2[[1]]) | ||
|
||
text <- paste0( | ||
trimws(x$method), | ||
" testing the difference in ranks between ", | ||
vars_full | ||
) | ||
} else { | ||
# one-sample | ||
vars_full <- paste0(table$Parameter[[1]]) | ||
|
||
text <- paste0( | ||
trimws(x$method), | ||
" testing the difference in rank for ", | ||
vars_full, | ||
" and true location of 0" | ||
) | ||
} | ||
|
||
text | ||
} | ||
|
||
.report_parameters_kruskal <- function(table, stats, effsize, ...) { | ||
text_full <- paste0( | ||
"statistically ", | ||
effectsize::interpret_p(table$p, rules = "default"), | ||
", and ", | ||
attributes(effsize)$interpretation, | ||
" (", | ||
paste0("Kruskal-Wallis ", stats), | ||
")" | ||
) | ||
|
||
text_short <- paste0( | ||
"statistically ", | ||
effectsize::interpret_p(table$p, rules = "default"), | ||
", and ", | ||
attributes(effsize)$interpretation, | ||
" (", | ||
paste0("Kruskal-Wallis ", summary(stats)), | ||
")" | ||
) | ||
|
||
list(text_short = text_short, text_full = text_full) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# report.htest-kruskal report | ||
|
||
Code | ||
report(x, verbose = FALSE) | ||
Output | ||
Effect sizes were labelled following Field's (2013) recommendations. | ||
The Kruskal-Wallis rank sum test testing the difference in ranks between | ||
airquality$Ozone and as.factor(airquality$Month) suggests that the effect is | ||
statistically significant, and large (Kruskal-Wallis chi2 = 29.27, p < .001; | ||
Epsilon squared (rank) = 0.25, 95% CI [0.15, 1.00]) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# testthat::set_state_inspector(function() { | ||
# list( | ||
# attached = search(), | ||
# connections = nrow(showConnections()), | ||
# cwd = getwd(), | ||
# envvars = Sys.getenv(), | ||
# libpaths = .libPaths(), | ||
# locale = Sys.getlocale(), | ||
# options = .Options, | ||
# packages = .packages(all.available = TRUE), | ||
# NULL | ||
# ) | ||
# }) | ||
## |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
test_that("report.htest-kruskal report", { | ||
x <- kruskal.test(airquality$Ozone ~ as.factor(airquality$Month)) | ||
|
||
set.seed(100) | ||
expect_snapshot( | ||
variant = "windows", | ||
report(x, verbose = FALSE) | ||
) | ||
}) |