View source: R/nonparametric.R
| friedman | R Documentation |
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.
friedman(
...,
by = NULL,
id = NULL,
data = NULL,
digits = 3,
p_digits = 3,
show = TRUE,
console = FALSE
)
... |
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 |
digits, p_digits |
Decimal places for estimates and p-values. |
show |
Logical; open the formatted result in the Viewer. Default |
console |
Logical; also print the traditional result in the Console. Default |
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.
Invisibly returns an object of class r4vn_stat.
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.