ADescribe · Guide test 119
Anderson–Darling k sample test
Tests whether several independent samples share a distribution.
Do it in CodeSplash
In the app, set it up in Analyze with this method:
- Compare distributions (two or more groups) — Do the groups come from the same distribution — anywhere, not only in their centers?
In Compare distributions (two or more groups), choose Test = Anderson–Darling k-sample.
Do it in CodeSplash Run this test on your own data, in Python or R.
Bench
Change the design, drag the data, move α. The statistic, its reference distribution and the verdict follow.
Bench · Anderson–Darling k sample test
Group i has true mean (i − 1) × spread.
Your data
Drag a point or use ↑/↓ to change itIf H₀ were true
- The reference: how A² varies across samples when H₀ is true, 999 relabelings of the pooled values (permutation null on the shared Wichmann–Hill stream).
- Your statistic, from the data above.
- The p-value: the area at least as extreme as yours (p = .225).
- The hatched rejection region at α = .050: statistics landing here reject H₀.
The formula
With your numbers
- mid-rank count of sample i at or below the j-th distinct value
- multiplicity of the j-th distinct value
The verdict
A² = 2.60, p = .225
p > α = .050: compatible with H₀
Scholz and Stephens' k-sample Anderson–Darling compares whole distributions, not only centers. The p here relabels the pooled values on the shared stream.
- Statistic
- 2.600
- p-value
- 0.2250
Anderson–Darling k sample test on Group 1: n = 12; Group 2: n = 12; Group 3: n = 12: A² = 2.60, p = .225. The p-value is above α = .050, so the data are compatible with H₀.
Question and hypotheses
H0: k samples share a common distribution.
Assumptions
Independent observations and groups; ties handled by an appropriate midrank/discrete variant.
Formula
Parameters and notation
HΝ=ΣnjFj/N is pooled CDF. The finite sample statistic uses rank endpoint conventions that avoid division by zero.
Structure of the method
Construct each group EDF and the pooled EDF, then aggregate weighted discrepancies relative to the pooled tail variance. Software may return a standardized Scholz–Stephens statistic rather than the raw sum, and tie variants change endpoint conventions.
Estimated and nuisance parameters
Group and pooled distributions are empirically estimated without a parametric family. Group sample sizes and pooled ranks determine centering, variance and the reference; there are no learned neural parameters.
Settings and design choices
Choose the midrank/discrete convention, asymptotic-table versus permutation calibration, significance level and resampling count. Keep group definitions fixed; multiplicity arises if many subsets or pairwise follow-ups are examined.
Fitting and adaptation
Under a common-distribution null with independent exchangeable observations, shuffle group labels while preserving group sizes. Recompute the exact chosen statistic for each permutation. For new groups rerun the full calculation; do not transfer critical values across differing k or sample configurations without justification. Follow-up comparisons require a separate multiple-comparison plan.
Sensitivity and robustness
Very unequal group sizes, extensive ties and small groups can weaken tabulated approximations. Some implementations bound interpolated p-values rather than computing arbitrary tails; permutation can improve resolution. Clustering within groups requires a different resampling unit, and a rejection does not locate the discrepant groups.
How to use and calibrate
Use Scholz–Stephens calibration or group label permutation; large values reject.
Example application
Compare several group distributions with sensitivity to tail differences.
Interpretation and pitfalls
Watch out
Raw, standardized and tie-adjusted statistics differ across software. Do not use one sample AD critical values.
What changed in edition 2
- New sections: structure of the method, estimated and nuisance parameters, settings and design choices, fitting and adaptation, sensitivity and robustness.
Python and R
k-sample distributional equality; Python requests a permutation p-value rather than the default tabulated approximation.
Validated — Executed successfully in the validation environment · needs numpy, scipy
import numpy as np
from scipy import stats
rng = np.random.default_rng(2026)
groups = [rng.normal(m,1,20) for m in (0,.4,.8)]
print(stats.anderson_ksamp(groups,method=stats.PermutationMethod(n_resamples=999,rng=rng)))
Output
Anderson_ksampResult(statistic=np.float64(7.310309140754521), critical_values=array([0.44925884, 1.3052767 , 1.9434184 , 2.57696569, 3.41634856,
4.07210043, 5.56419101]), pvalue=np.float64(0.001))Validated — Executed successfully in the validation environment · needs kSamples
set.seed(2026)
d <- data.frame(value=c(rnorm(20),rnorm(20,.4),rnorm(20,.8)), group=factor(rep(c("A","B","C"),each=20)))
print(kSamples::ad.test(split(d$value,d$group)))
Output
Anderson-Darling k-sample test.
Number of samples: 3
Sample sizes: 20, 20, 20
Number of ties: 0
Mean of Anderson-Darling Criterion: 2
Standard deviation of Anderson-Darling Criterion: 1.03502
T.AD = ( Anderson-Darling Criterion - mean)/sigma
Null Hypothesis: All samples come from a common population.
AD T.AD asympt. P-value
version 1: 7.3441 5.1633 0.0015747
version 2: 7.4100 5.2296 0.0014731Sources
- SciPy — SciPy · anderson_ksampdocs.scipy.org
- scipy.stats.anderson_ksampdocs.scipy.org
- ad.testsearch.r-project.org
- Statistics guide v4 (historical):
- R: Executed successfully in the validation environment
- Reference's record:
- Edition 2 review: Python: executed · R: not executed (Rscript unavailable). Python: Ran in the reference's review, on this exact code. R: Reviewed but not run: R wasn't available to the reference's authors.
From the CodeSplash statistics guide (v4), entry 119, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT119.