Sub topic 9
When to use nonparametric tests
This chapter assumes you can run a z-test or t-test on a mean, compare two means, and read a correlation coefficient. It also assumes you know the logic of null and alternative hypotheses, test statistics, and critical values. Here you learn when those tests stop being trustworthy and what to use in their place.
What "parametric" means
A parametric test makes a claim about a population parameter, such as a mean or variance. It also assumes a distribution for the data. The t-test on a mean assumes the population is normal, or that the sample is large enough for the central limit theorem to help. It also assumes the data are measured on an interval or ratio scale, so that averages mean something.
A nonparametric test relaxes one or more of those requirements. It either does not concern a parameter or makes few assumptions about the distribution. The usual price is lower power when the parametric assumptions actually hold. You are trading some sensitivity for reliability.
The four situations that call for a nonparametric test
- Assumptions about the distribution are violated. The sample is small and clearly skewed or has fat tails, so the t-test's normality assumption is doubtful.
- Outliers are present. A single extreme observation can dominate a mean and a standard deviation. Ranks limit its influence, because the largest value is just "rank n" however large it is.
- The data are ranks or ordinal. Examples are analyst ratings from 1 to 5, or funds ordered by performance. The distance between rank 1 and rank 2 is not necessarily the same as between rank 4 and rank 5, so a mean is not meaningful.
- The hypothesis is not about a parameter. Examples are whether a sequence of returns is random, or whether two categorical variables are independent.
Parametric tests and their nonparametric counterparts
| Question | Parametric test | Nonparametric alternative |
|---|---|---|
| Is a single mean (or median) equal to a value? | t-test on the mean | Wilcoxon signed-rank test, sign test |
| Do two independent samples differ in location? | t-test for the difference in means | Mann-Whitney U test |
| Do paired observations differ? | Paired t-test on the mean difference | Wilcoxon signed-rank test, sign test |
| Are two variables related? | Pearson correlation test | Spearman rank correlation test |
| Are two categorical variables independent? | None | Chi-square test of independence |
Ranks: the core idea
Most nonparametric tests replace each observation with its rank, from 1 for the smallest to n for the largest. Tied values share the average of the ranks they occupy. Once the data are ranks, the test statistic depends only on the order of the observations, not on their size. That is why the tests tolerate outliers and odd distributions.
Spearman rank correlation
The Spearman rank correlation applies the correlation idea to ranks. If d is the difference between the two ranks of each observation and n is the number of observations (with no ties), then:
r_s = 1 − 6 Σd² / (n(n² − 1))
It runs from −1 to +1. It measures whether the two variables move together in a consistent direction, not whether the relationship is a straight line. It is therefore useful when the relationship is monotonic but curved, or when outliers distort the Pearson coefficient.
To test H0: the population rank correlation is 0, use the same t-statistic as for the Pearson correlation, with n − 2 degrees of freedom:
t = rs √(n − 2) / √(1 − rs²)
Worked example
Eight analysts are ranked on forecasting skill (rank 1 is best) and, separately, by the later performance of their stock picks. The skill ranks are 1 through 8, and the performance ranks are 2, 1, 4, 3, 6, 5, 8, 7.
The rank differences are −1, 1, −1, 1, −1, 1, −1, 1, so each d² is 1 and Σd² = 8.
- r_s = 1 − 6(8) / (8 × 63) = 1 − 48/504 = 0.9048
- t = 0.9048 × √6 / √(1 − 0.8186) = 2.216 / 0.4259 = 5.20
- The two-tailed critical value at the 5% level with 6 degrees of freedom is 2.447.
Because 5.20 exceeds 2.447, you reject H0. The rank correlation is significantly different from zero.
import numpy as np
from scipy import stats
# Spearman rank correlation, checked against the hand calculation
skill = np.array([1, 2, 3, 4, 5, 6, 7, 8])
perf = np.array([2, 1, 4, 3, 6, 5, 8, 7])
n = len(skill)
d = skill - perf
r_manual = 1 - 6 * (d ** 2).sum() / (n * (n ** 2 - 1))
t_stat = r_manual * np.sqrt(n - 2) / np.sqrt(1 - r_manual ** 2)
t_crit = stats.t.ppf(1 - 0.05 / 2, df=n - 2)
rho, p_value = stats.spearmanr(skill, perf)
print(r_manual, rho, t_stat, t_crit, p_value)
print("Reject H0" if abs(t_stat) > t_crit else "Fail to reject H0")
# Wilcoxon signed-rank test on the fund returns from the earlier chapter
returns = np.array([1.2, -0.4, 0.8, 2.1, -1.0, 0.5, 1.7, 0.3, -0.2, 1.1])
w_stat, w_p = stats.wilcoxon(returns)
print(w_stat, w_p)Other tests you should recognize
- Wilcoxon signed-rank test. It tests whether a sample, or the paired differences, are centered on a hypothesized value. It ranks the absolute differences from the hypothesized value and sums the ranks separately for positive and negative differences. It uses more information than the sign test, so it has more power.
- Mann-Whitney U test. It compares two independent samples by pooling and ranking all the observations. If the groups have the same location, the ranks of one group should be spread evenly through the pooled ranking.
- Sign test. It counts only how many differences are positive and how many are negative. It ignores their size, so it is very robust but has little power.
- Runs test. It checks whether a sequence of outcomes, such as up and down months, looks random.
- Chi-square test of independence. It compares observed counts in a contingency table with the counts expected if the two classifications were independent. It is a nonparametric test because it concerns independence, not a parameter.
Common errors
- Using a nonparametric test only because the sample is small. A small sample does not rule out the t-test. If the population is known to be approximately normal, the t-test remains valid at any sample size.
- Reading the Spearman coefficient as a measure of linearity. A perfect monotonic but curved relationship gives r_s = 1, while the Pearson coefficient would be below 1.
- Forgetting that the tests answer a different question. Rank tests compare locations or ordering, not means. A significant Mann-Whitney result does not state a difference in means.
- Ignoring ties. The simple r_s formula assumes no ties. With many ties, use average ranks and a software routine that corrects for them.
- Dropping the effect of lost information. Converting returns to ranks discards the magnitudes. A large gap between two funds counts the same as a tiny one.
Decision criteria
Start from the question. If it concerns a parameter, the data are interval or ratio, outliers are absent, and the distribution is plausibly normal or the sample large, use the parametric test. If any of those fails, move to the rank-based counterpart in the table. If the hypothesis is about independence or randomness, use the chi-square or runs test. State your reasoning in each case. The exam rewards the match between the situation and the test.
Exercise
A researcher has 12 monthly returns for a fund that include one extreme outlier. She wants to test whether the center of the return distribution is zero. Name a suitable nonparametric test and explain why it is preferred to the t-test here.
Show answer
The Wilcoxon signed-rank test (or the sign test) is suitable. It works with ranks of the deviations from zero, so the outlier counts only as the largest rank and cannot dominate the statistic. The t-test uses the sample mean and standard deviation, both of which the outlier distorts, and the small sample gives little help from the central limit theorem.
Exercise
Two ranked lists of 10 stocks have Σd² = 30 and no ties. Compute the Spearman rank correlation and test at the 5% level (two-tailed, critical t = 2.306 for 8 degrees of freedom) whether it differs from zero.
Show answer
r_s = 1 − 6(30) / (10 × 99) = 1 − 180/990 = 0.8182. Then t = 0.8182 × √8 / √(1 − 0.6694) = 2.314 / 0.5750 = 4.02. Since 4.02 exceeds 2.306, reject H0. The rank correlation is significantly different from zero.