View source: R/nonparametric.R View source: R/zzz-r4vn-inference.R
| ranksum | R Documentation |
Performs the Wilcoxon rank-sum test, also known as the Mann-Whitney U test, for two independent samples. Samples may be supplied as two numeric variables or as one numeric outcome and a two-level grouping variable.
ranksum(
x,
y = NULL,
by = NULL,
data = NULL,
alternative = c("two.sided", "less", "greater"),
exact = NULL,
correct = TRUE,
conf.int = TRUE,
level = 0.95,
digits = 3,
p_digits = 3,
show = TRUE,
console = FALSE
)
x |
Numeric outcome or first numeric sample. |
y |
Optional second numeric sample. |
by |
Optional two-level grouping variable. Use either |
data |
Data frame. If |
alternative |
Alternative hypothesis: |
exact |
Use an exact p-value when possible. |
correct |
Apply continuity correction for the normal approximation. |
conf.int |
Report the Hodges-Lehmann location-shift estimate and its confidence interval when available. |
level |
Confidence level. |
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 |
With by, the first observed factor level is sample 1 and the second level is
sample 2. Use factor() or labvar(..., ref = ...) to control level order.
Missing values are removed independently when x and y are supplied, and
complete cases are used when by is supplied.
Invisibly returns an object of class r4vn_stat.
d <- data.frame(
score = c(12, 15, 11, 19, 18, 21, 14, 17),
group = factor(rep(c("Control", "Intervention"), each = 4)),
score2 = c(10, 13, 12, 14, 19, 20, 18, 22)
)
ranksum(score, by = group, data = d)
ranksum(score, score2, data = d)
ranksum(score, by = group, data = d, alternative = "less")
# Extended usage examples
d <- data.frame(
score = c(10, 11, 12, 13, 18, 19, 20, 21),
score2 = c(9, 10, 12, 11, 17, 18, 19, 22),
group = factor(rep(c("Control", "Intervention"), each = 4))
)
# Two independent variables or one outcome by a two-level group
ranksum(score, score2, data = d)
ranksum(score, by = group, data = d)
# One-sided alternatives, approximation controls, and confidence interval
ranksum(score, by = group, data = d, alternative = "less")
ranksum(score, by = group, data = d, exact = FALSE, correct = FALSE)
ranksum(score, by = group, data = d, conf.int = FALSE)
# Active data and hidden console output
usedf(d)
result <- ranksum(score, by = group, show = FALSE)
result$raw$test
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.