When normality is doubtful in Python
Rank-based tests make fewer assumptions than a t-test.
import numpy as np
from scipy import stats
rng = np.random.default_rng(2)
skewed = rng.exponential(scale=20, size=30)
other = rng.exponential(scale=30, size=30)
print(round(stats.shapiro(skewed).pvalue, 5))
print(round(stats.mannwhitneyu(skewed, other).pvalue, 5))
print(round(stats.wilcoxon(skewed, other).pvalue, 5))
print(round(stats.ks_2samp(skewed, other).pvalue, 5))
print(round(stats.kruskal(skewed, other).pvalue, 5))
How it works
mannwhitneyuis the rank alternative tottest_ind.wilcoxonis the paired version.shapiroandks_2samptest the assumptions themselves.
Keywords and builtins used here
asprintround
The run, in numbers
- Lines
- 12
- Characters to type
- 427
- Tokens
- 134
- Three-star pace
- 105 tpm
At the three-star pace of 105 tokens a minute, this run takes about 77 seconds.
Step 2 of 4 in Hypothesis tests, step 5 of 23 in Scientific computing with SciPy.