friedman: Friedman Test for Repeated or Matched Measurements

View source: R/nonparametric.R

friedmanR Documentation

Friedman Test for Repeated or Matched Measurements

Description

Performs the Friedman rank-sum test for three or more repeated or matched measurements. Data may be supplied in wide form as several numeric variables, or in long form as one outcome, one occasion/treatment variable, and one subject/block identifier.

Usage

friedman(
  ...,
  by = NULL,
  id = NULL,
  data = NULL,
  digits = 3,
  p_digits = 3,
  show = TRUE,
  console = FALSE
)

Arguments

...

In wide form, two or more numeric repeated-measure variables. In long form, exactly one numeric outcome variable.

by

Long-form occasion or treatment variable.

id

Long-form subject or block identifier.

data

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

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.

Details

Wide form uses only rows complete across every repeated measurement. Long form must contain one observation for every subject-by-occasion combination; incomplete blocks are rejected by the underlying Friedman test.

Value

Invisibly returns an object of class r4vn_stat.

Examples

wide <- data.frame(
  baseline = c(22, 20, 19, 25, 23, 21),
  month1   = c(20, 18, 18, 22, 21, 20),
  month3   = c(18, 17, 16, 20, 19, 18)
)
friedman(baseline, month1, month3, data = wide)

long <- data.frame(
  id = rep(1:6, each = 3),
  time = factor(rep(c("Baseline", "Month 1", "Month 3"), 6),
                levels = c("Baseline", "Month 1", "Month 3")),
  score = as.vector(t(as.matrix(wide)))
)
friedman(score, by = time, id = id, data = long)

# Extended usage examples

wide <- data.frame(
  baseline = c(22, 20, 19, 25, 23, 21),
  month1 = c(20, 18, 18, 22, 21, 20),
  month3 = c(18, 17, 16, 20, 19, 18)
)

# Wide form: each row is a subject and each variable is an occasion
friedman(baseline, month1, month3, data = wide)

# Long form: outcome, occasion, and subject identifier
long <- data.frame(
  id = rep(1:6, each = 3),
  time = factor(rep(c("Baseline", "Month 1", "Month 3"), 6),
                levels = c("Baseline", "Month 1", "Month 3")),
  score = as.vector(t(as.matrix(wide)))
)
friedman(score, by = time, id = id, data = long)

usedf(wide)
friedman(baseline, month1, month3)


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