kwallis: Kruskal-Wallis Test

View source: R/nonparametric.R View source: R/zzz-r4vn-inference.R

kwallisR Documentation

Kruskal-Wallis Test

Description

Performs the Kruskal-Wallis rank-sum test for a numeric outcome across two or more independent groups. Optional Dunn or pairwise Wilcoxon post-hoc tests and rank-based effect sizes can be requested. With by = vars(region, sex, treatment), region and sex are nested strata and treatment is the innermost Kruskal-Wallis factor.

Usage

kwallis(
  x, by, data = NULL, posthoc = c("none", "dunn", "wilcoxon"),
  adjust = "holm", effect = FALSE, digits = 3, p_digits = 3, show = TRUE,
  console = FALSE
)

Arguments

x

Numeric outcome.

by

Grouping variable with at least two observed groups, or hierarchical vars(...) specification.

data

Data frame. If NULL, active R4VN data is used.

posthoc

Post-hoc method: "none", "dunn", or "wilcoxon".

adjust

Multiplicity adjustment accepted by stats::p.adjust().

effect

Logical; add epsilon-squared and eta-squared(H).

digits, p_digits

Decimal places for estimates and p-values.

show

Logical; open the formatted result in the Viewer. Default TRUE.

console

Logical; also print the traditional result in the Console. Default FALSE.

Value

Invisibly returns an object of class r4vn_stat.

Examples

d <- data.frame(
  score = c(10, 12, 11, 18, 17, 20, 25, 24, 27),
  group = factor(rep(c("A", "B", "C"), each = 3))
)
kwallis(score, by = group, data = d, posthoc = "dunn", effect = TRUE)

# Extended usage examples

d <- data.frame(
  score = c(10, 12, 11, 18, 17, 20, 25, 24, 27),
  treatment = factor(rep(c("A", "B", "C"), each = 3))
)
kwallis(score, by = treatment, data = d)
usedf(d)
result <- kwallis(score, by = treatment, show = FALSE)
result$raw$test


R4VN documentation built on Sept. 30, 2026, 5:13 p.m.