
Compare Two Related Measurements Without Assuming Normality
Source:R/wilcoxon_test.R
wilcoxon_test.Rdwilcoxon_test() compares two paired measurements from the same
subjects when your data isn't normally distributed. It's the non-parametric
alternative to the paired t-test.
Think of it as:
A way to test whether scores changed between two time points
Comparing ratings of two items from the same respondents
A robust paired comparison that works with any data shape
The test tells you:
Whether scores are significantly different between the two measurements
How many subjects increased, decreased, or stayed the same
The strength of the effect (effect size r)
Arguments
- data
Your survey data (a data frame or tibble) in wide format, with one row per subject and the two measurements in separate columns
- x
The first measurement variable (e.g., pre-test, trust in government)
- y
The second measurement variable (e.g., post-test, trust in media). The difference is computed as
y - x- weights
Optional survey weights for population-representative results. Give a column name (unquoted or as a string), an expression such as
sampling_weight * 2, or a numeric vector with one weight per row.- conf.level
Not used. Rank tests report no confidence interval (SPSS
NPAR TESTSneither); kept for backward compatibility.
Value
Test results showing whether the two measurements differ, including:
Z statistic (standardized test statistic, normal approximation)
P-value (is there a significant difference?)
Effect size r (how strong is the difference?)
Rank statistics (negative ranks, positive ranks, ties)
Details
Understanding the Results
P-value: If p < 0.05, the two measurements are significantly different
p < 0.001: Very strong evidence of a difference
p < 0.01: Strong evidence of a difference
p < 0.05: Moderate evidence of a difference
p > 0.05: No significant difference found
Effect Size r (How strong is the difference?):
< 0.1: Negligible effect
0.1 - 0.3: Small effect
0.3 - 0.5: Medium effect
0.5 or higher: Large effect
Rank Categories:
Negative Ranks: subjects where y < x (decreased)
Positive Ranks: subjects where y > x (increased)
Ties: subjects where y = x (no change)
Z: as in SPSS, computed from the smaller of the two rank sums, so it
is never positive; z_based_on ("negative ranks" or "positive
ranks") names that sum, like SPSS's footnote. "Based on negative ranks"
means that increases (y > x) dominate.
When to Use This
Use Wilcoxon signed-rank test when:
Comparing two related measurements from the same subjects
Your data is not normally distributed
You have ordinal data (ratings, rankings)
Sample size is small
You want a robust alternative to the paired t-test
Relationship to Other Tests
For normally distributed paired data: Use paired t-test instead
For independent groups: Use
mann_whitney()instead
Weighted analyses
Weights are treated as frequency weights. With all weights equal to 1 the
weighted test reproduces the unweighted one exactly. Weighted results are
not compared with SPSS output; see vignette("spss-compatibility").
For 3+ related measurements: Use
friedman_test()instead
References
Wilcoxon, F. (1945). Individual comparisons by ranking methods. Biometrics Bulletin, 1(6), 80-83.
Fritz, C. O., Morris, P. E., & Richler, J. J. (2012). Effect size estimates: current use, calculations, and interpretation. Journal of Experimental Psychology: General, 141(1), 2.
See also
wilcox.test for the base R Wilcoxon test.
mann_whitney for comparing two independent groups.
Other hypothesis_tests:
ancova(),
binomial_test(),
chi_square(),
chisq_gof(),
factorial_anova(),
fisher_test(),
friedman_test(),
kruskal_wallis(),
mann_whitney(),
mcnemar_test(),
oneway_anova(),
t_test()
Examples
# Load required packages and data
library(dplyr)
data(survey_data)
# Compare trust in government vs trust in media
survey_data %>%
wilcoxon_test(x = trust_government, y = trust_media)
#> Wilcoxon Signed-Rank Test: trust_media - trust_government
#> Z = -5.097, p < 0.001 ***, r = 0.123 (small), N = 2227
#> Use summary() for detailed output.
# Weighted analysis
survey_data %>%
wilcoxon_test(x = trust_government, y = trust_media,
weights = sampling_weight)
#> Wilcoxon Signed-Rank Test: trust_media - trust_government [Weighted]
#> Z = -5.035, p < 0.001 ***, r = 0.121 (small), N = 2242
#> Use summary() for detailed output.
# Grouped analysis (separate test per region)
survey_data %>%
group_by(region) %>%
wilcoxon_test(x = trust_government, y = trust_media)
#> [region = East]
#> Wilcoxon Signed-Rank Test: trust_media - trust_government
#> Z = -2.727, p = 0.006 **, r = 0.147 (small), N = 435
#> [region = West]
#> Wilcoxon Signed-Rank Test: trust_media - trust_government
#> Z = -4.346, p < 0.001 ***, r = 0.117 (small), N = 1792
#> Use summary() for detailed output.