KW_TEST() tests whether the distribution of a continuous variable
differs across the levels of one or more grouping variables. It is the
rank-based, distribution-free analogue to one-way ANOVA. If KW_TEST is
supplied within the lazy-loaded pipeline, supply KW_TEST as a function
i.e. prepare_test(.test = KW_TEST).
Arguments
- .var_id
A variable mapper
<var_id>. Currently supportsx_by(). When supplied, the test executes immediately. If.var_idmaps multiple grouping variables, one Kruskal-Wallis test runs per grouping variable against the same continuous variable.- .data
A data frame. Only used on the standalone path.
- ...
Additional arguments passed to the implementation. See the Supported variable mapper section for the full list per path.
Value
A cld_exec object (in statim::conclude()), a stat_infer_spec
object, or a test_spec when .var_id = NULL. kwtest_def_xby's
baseline returns a class_kw_test object by default; its pairwise
variant instead returns a plain list (kw_test, comps) with its own
print method. kwtest_def_on's baseline returns a plain list
(statistic, df, p_value) with its own print method — neither
path shares a class between them.
Details
H0: all samples come from the same distribution (equal medians, under
the assumption of equal shape). H1: at least one sample is
stochastically greater than another.
Supported variable mapper <var_id>s
x_by(): grouped Kruskal-Wallis test, with optional pairwise comparisons. See details from kwtest-xby.on(): one-sample Kruskal-Wallis test via a compiled backend. See details from kwtest-on.
Examples
set.seed(123)
x = rcauchy(50, 1, 1.5)
g = sample(letters[1:5], size = 50, replace = TRUE)
KW_TEST(x_by(x, g))
#> -- Summary ---------------------------------------------------------------------
#>
#> ────────────────────────────────
#> vars statistic df p_value
#> ────────────────────────────────
#> g 1.022 4 0.906
#> ────────────────────────────────
#>
#>
# multiple grouping variables -> one test per grouping variable
# (confirm this call shape against your actual x_by() signature)
g2 = sample(c("control", "treatment"), size = 50, replace = TRUE)
KW_TEST(x_by(x, c(g, g2)))
#> -- Summary ---------------------------------------------------------------------
#>
#> ────────────────────────────────
#> vars statistic df p_value
#> ────────────────────────────────
#> g 1.022 4 0.906
#> g2 5.986 1 0.014
#> ────────────────────────────────
#>
#>