The t-tests we have already learned are considered parametric methods.
Nonparametric methods do not have distributional assumptions.
Why don’t we always use nonparametric methods?
They are often less efficient: a larger sample size is required to achieve the same probability of a Type I error.
They discard useful information :(
The Wilcoxon Rank Sum test is a nonparametric alternative to the two-sample t-test.
Instead of comparing group means, we will now turn to comparing the ranks of the data.
Let us first consider a simple example, x: \ 1, 7, 10, 2, 6, 8
Our first step is to reorder the data: x: \ 1, 2, 6, 7, 8, 10
Then, we replace with the ranks: R: \ 1, 2, 3, 4, 5, 6
What if all data values are not unique? We will assign the average rank for that group.
For example, x: 9, 8, 8, 0, 3, 4, 4, 8
Let’s reorder: x: 0, 3, 4, 4, 8, 8, 8, 9
Rank ignoring ties: R: 1, 2, 3, 4, 5, 6, 7, 8
Now, the final rank: R: 1, 2, 3.5, 3.5, 6, 6, 6, 8
T_0 = \sum R_{\text{1}} - \frac{n_1(n_1+1)}{2}
T = \sum R_{\text{sample 1}} - \frac{n_1(n_1+1)}{2}
where
Note that p = (calculated by R :))
We will use the independent_median_HT function from library(ssstats) to perform the necessary calculations for the hypothesis test.
Generic syntax:
wing_flap %>% independent_median_HT(continuous = apples,
grouping = target,
alternative = "greater",
m = 5,
alpha = 0.05)Wilcoxon Rank Sum Test for two independent medians
Null: H₀: M₁ - M₂ ≤ 5
Alternative: H₁: M₁ - M₂ > 5
Test statistic: T = 135.5
p-value: p < 0.001
Conclusion: Reject the null hypothesis (p = < 0.001 < α = 0.05)
Two-sample t-test for two independent means and equal variance:
Null: H₀: μ₁ − μ₂ ≤ 5
Alternative: H₁: μ₁ − μ₂ > 5
Test statistic: t(23) = 5.445
p-value: p < 0.001
Conclusion: Reject the null hypothesis (p = < 0.001 < α = 0.05)
Wilcoxon Rank Sum Test for two independent medians
Null: H₀: M₁ - M₂ ≤ 5
Alternative: H₁: M₁ - M₂ > 5
Test statistic: T = 135.5
p-value: p < 0.001
Conclusion: Reject the null hypothesis (p = < 0.001 < α = 0.05)
The Wilcoxon Signed Rank test is a nonparametric alternative to the dependent t-test.
Instead of examining the mean of the difference, we will now turn to examining the ranks of the differences.
Before ranking, we will find the difference between the paired observations and eliminate any 0 differences.
When ranking, we the differences are ranked based on the absolute value of the difference.
Then, ranks can be identified as “positive” or “negative” based on the direction of the difference.
| X | Y | D | |D| | Rank |
|---|---|---|---|---|
| 5 | 8 | -3 | 3 | - 1.5 |
| 8 | 5 | 3 | 3 | + 1.5 |
| 4 | 4 | 0 | 0 | ——— |
T_0 = \begin{cases} R_+ = \text{sum of positive ranks} & \text{if left-tailed} \\ R_- = \text{sum of negative ranks} & \text{if right-tailed} \\ \min(R_+, R_-) & \text{if two-tailed} \end{cases}
We will use the dependent_median_HT function from library(ssstats) to perform the necessary calculations for the hypothesis test.
Generic syntax:
Perform the appropriate hypothesis test to determine if there is a difference in wing-flap rate pre- and post-training. Test at the \alpha=0.01 level.
How should we change the following code?
Perform the appropriate hypothesis test to determine if there is a difference in wing-flap rate pre- and post-training. Test at the \alpha=0.01 level.
Our updated code,
wing_flap %>% dependent_median_HT(col1 = pre_training_wfr,
col2 = post_training_wfr,
alternative = "two",
m = 0,
alpha = 0.01)Wilcoxon Signed-Rank Test for the median of differences:
Null: H₀: M_d = 0
Alternative: H₁: M_d ≠ 0
Test statistic: T = 188
p-value: p = 0.501
Conclusion: Fail to reject the null hypothesis (p = 0.5011 ≥ α = 0.01)
Paired t-test for the mean of differences:
Null: H₀: μ_d = 0
Alternative: H₁: μ_d ≠ 0
Test statistic: t(24) = 0.859
p-value: p = 0.399
Conclusion: Fail to reject the null hypothesis (p = 0.3991 ≥ α = 0.01)
Wilcoxon Signed-Rank Test for the median of differences:
Null: H₀: M_d = 0
Alternative: H₁: M_d ≠ 0
Test statistic: T = 188
p-value: p = 0.501
Conclusion: Fail to reject the null hypothesis (p = 0.5011 ≥ α = 0.01)
STA4173 - Biostatistics - Fall 2025