| A | 1 | 4 | 6 | 7 | 8 | 9 |
| B | 1 | 4 | 6 | 7 | 8 | 39 |
| - | ||||||
| rank(A) | 1 | 2 | 3 | 4 | 5 | 6 |
| rank(B) | 1 | 2 | 3 | 4 | 5 | 6 |
University of Amsterdam
2025-10-21
In this lecture we aim to:
Reading: Chapter 15
| Attribute | Parametric | Nonparametric |
|---|---|---|
| distribution | normally distributed | any distribution |
| sampling | random sample | random sample |
| sensitivity to outliers | yes | no |
| works with | large data sets | small and large data sets |
| speed | fast | slow |
| A | 1 | 4 | 6 | 7 | 8 | 9 |
| B | 1 | 4 | 6 | 7 | 8 | 39 |
| - | ||||||
| rank(A) | 1 | 2 | 3 | 4 | 5 | 6 |
| rank(B) | 1 | 2 | 3 | 4 | 5 | 6 |
| index | 1 | 2.0 | 3.0 | 4 | 5.0 | 6.0 | 7 | 8 | 9 |
| x | 11 | 42.0 | 42.0 | 62 | 73.0 | 73.0 | 84 | 84 | 84 |
| ranks | 1 | 2.5 | 2.5 | 4 | 5.5 | 5.5 | 8 | 8 | 8 |
\[\frac{2 + 3}{2} = 2.5, \frac{5 + 6}{2} = 5.5, \frac{7 + 8 + 9}{3} = 8\]
Independent 2 samples
Also known as the Mann-Whitney U test
Developed by Frank Wilcoxon the rank-sum test is an nonparametric alternative to the independent samples t-test.
By ranking all values and then summing the ranks per group, one would expect under the null hypothesis, that the sum of ranks is approximately equal.
After standardizing the test statistic (summed ranks for one group), we can use the standard normal distribution as the sampling distribution.
Drug rankedBDI
1 Alcohol 90.5
2 Ecstasy 119.5
We can take the sum of ranks for the first group as W:
JASP reports the value of U, which is W with its minimum value subtracted:
To calculate the Z-score we need to standardize the W. To do so we need the mean W and the standard error of W.
For this we need the sample sizes for each group.
\[\bar{W}_s=\frac{n_1(n_1+n_2+1)}{2}\]
\[{SE}_{\bar{W}_s}=\sqrt{ \frac{n_1 n_2 (n_1+n_2+1)}{12} }\]
\[z = \frac{W - \bar{W}}{{SE}_W}\]
Which looks a lot like
\[\frac{X - \bar{X}}{{SE}_X} \text{or} \frac{b - \mu_{b}}{{SE}_b} \]
\[r_{bs} = 1 - \frac{2*W}{n_1*n_2}\]
Paired 2 samples
The Wilcoxon signed-rank test is a nonparametric alternative to the paired samples t-test. It assigns + or - signs to the difference between two repeated measures. By ranking the absolute differences and summing these ranks for the positive group, the null hypothesis is tested that both positive and negative differences are equal.
# Calculate difference in scores between first and second measure
data$diff = data$Sunday - data$Wednesday
# Calculate absolute difference in scores between first and second measure
data$abs.diff = abs(data$Sunday - data$Wednesday)
# Remove observations where the difference is 0
data <- data[data$diff != 0, ]
# Create rank variable
data$rank <- rank(data$abs.diff)
# Assign a '+' or a '-' to those values
data$sign <- sign(data$Sunday - data$Wednesday)[1] 0
[1] 8
How likely is it to observe the lowest possible rank sum (0), for \(n=8\), if there is no difference in BDI between Sunday and Wednesday?
\[\bar{T} = \frac{n(n+1)}{4}\]
T_mean is the middle point between the minimum (0) and maximum possible (36) value for T
\[{SE}_{T} = \sqrt{\frac{n(n+1)(2n+1)}{24}}\]
\[z = \frac{T_+ - \bar{T}}{{SE}_T}\]
\[r = \frac{T_+ - T_- }{T_+ + T_-}\]
Here \(T_+\) is the sum of the positive ranks (i.e., where Sunday > Wednesday), which do not exist. \(T_-\) is the sum of the negative ranks, which is 36. We have a maximum negative correlation (i.e., everybody scored lower on Wednesday).
Independent >2 samples
Created by William Henry Kruskal (L) and Wilson Allen Wallis (R), the Kruskal-Wallis test is a nonparametric alternative to the independent one-way ANOVA.
The Kruskal-Wallis test essentially subtracts the expected mean ranking from each oberved mean ranking, which is \(\chi^2\) distributed.
\[H = \frac{12}{N(N+1)} \sum_{i=1}^k \frac{R_i^2}{n_i} - 3(N+1)\]
\[H = \frac{12}{N(N+1)} \sum_{i=1}^k \frac{R_i^2}{n_i} - 3(N+1)\]
And the degrees of freedom
Paired >2 samples
Created by William Frederick Friedman the Friedman’s ANOVA is a nonparametric alternative to the repeated one-way ANOVA.
Just like the Kruskal-Wallis test, Friedman’s ANOVA, subtracts the expected mean ranking from the calculated observed mean ranking, which is also \(\chi^2\) distributed.
Rank within each participant (i.e., within each row).
\[F_r = \left[ \frac{12}{Nk(k+1)} \sum_{i=1}^k R_i^2 \right] - 3N(k+1)\]
–> We sum the ranks for each of the three experimental conditions (and apply some standardizations).
Calculate ranks sum per condition and \(N\).
\[F_r = \left[ \frac{12}{Nk(k+1)} \sum_{i=1}^k R_i^2 \right] - 3N(k+1)\]
\[ \frac{(k-1) \sum_i^k (R_i - \frac{b(k+1))}{2})^2}{\sum_i^b \sum_j^k (R_{ij}^2) - \frac{bk(k+1)^2}{4}} \]
k <- 3
b <- 10
F.r <- (sum ((R.i - ((b*(k+1))/2) )^2) * (k-1)) / (sum((ranks^2)) - (b*k *(k+1)^2) / 4)
F.r[1] 0.2
And the degrees of freedom

Scientific & Statistical Reasoning