Skip to content

ADescribe · Guide test 118

Anderson–Darling general goodness of fit test

Tests a specified distribution using a tail weighted empirical discrepancy; critical values depend on the null and fitting.

Runs in CodeSplashPython example validatedR example validated

Do it in CodeSplash

In the app, set it up in Analyze with this method:

In Fit a distribution (goodness of fit), choose Parameters = Specified in advance.

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 general goodness of fit test

40
0.30
1.00
0.050

Your data

Drag a point or use ↑/↓ to change it
D = 0.227F₀ = N(0, 1)

If H₀ were true

A² = 4.27
  1. The reference: how A² varies across samples when H₀ is true, A² for n = 40 (Marsaglia & Marsaglia).
  2. Your statistic, from the data above.
  3. The p-value: the area at least as extreme as yours (p = .007).
  4. The hatched rejection region at α = .050: statistics landing here reject H₀.

The formula

A2=−n−1n∑i(2i−1)[ln⁡F0(x(i))+ln⁡(1−F0(x(n+1−i)))]A^2=-n-\dfrac1n\sum_i(2i-1)\left[\ln F_0(x_{(i)})+\ln\left(1-F_0(x_{(n+1-i)})\right)\right]

With your numbers

A2=4.27,n=40A^2 = 4.27,\qquad n = 40
F0F_0
the hypothesized CDF, with no parameters estimated
x(i)x_{(i)}
the sorted data

The verdict

A² = 4.27, p = .007

p ≤ α = .050: reject H₀

An ECDF distance that weighs the tails heavily. The p (Marsaglia & Marsaglia 2004) is valid only when F0 is fully specified; estimated parameters need other tables.

Statistic
4.267
p-value
0.0065
Anderson–Darling general goodness of fit test on Sample: n = 40: A² = 4.27, p = .007. The p-value is below α = .050, so the data are hard to reconcile with H0.

Anderson–Darling general goodness of fit test on Sample: n = 40: A² = 4.27, p = .007. The p-value is below α = .050, so the data are hard to reconcile with H₀.

Question and hypotheses

H0: a specified continuous CDF F0 is correct.

Assumptions

Independent observations; use a null calibration appropriate to whether parameters are known or estimated.

Formula

A2=n∫[Fn(x)−F0(x)]2F0(x)[1−F0(x)] dF0(x)A^2=n\int\frac{[F_n(x)-F_0(x)]^2}{F_0(x)[1-F_0(x)]}\,dF_0(x)

Parameters and notation

Tail weighting 1/[F0(1−F0)] distinguishes Anderson–Darling; the ordered sample equation is entry 109 with ui=F0(x(i)).

Structure of the method

Integrate the squared empirical-versus-null CDF discrepancy with inverse binomial-variance weighting. For continuous observations the ordered-probability log formula evaluates the integral efficiently. The chosen distribution and parameter-estimation regime identify the actual Anderson–Darling test.

Estimated and nuisance parameters

The null CDF may be fully specified or depend on fitted location, scale and shape. Those nuisance estimates must be recorded; their estimation changes the law of the statistic.

Settings and design choices

Fix the candidate distribution, fitting algorithm, tail treatment, correction and significance threshold. Choose Monte Carlo repetitions if tables do not match. Searching among distributions and reporting the best-fitting p-value needs separate interpretation.

Fitting and adaptation

Under a known CDF, simulate directly from that fixed model. Under a composite null, fit, simulate from the fitted model and refit every replicate before computing AD. Any censoring, parameter boundary or adaptive threshold must also be reproduced. Adaptation means re-estimating and recalibrating the null, not learning weights that maximize acceptance.

Sensitivity and robustness

Tail probabilities can underflow or round to one; compute log-CDF and log-survival directly. Tail weighting makes a few observations influential. Fitting a misspecified family, ignoring dependence, or borrowing critical values from another family can materially distort type-I error.

How to use and calibrate

Use a distribution/estimation-specific reference or a parametric bootstrap repeating all fitting steps.

Example application

Assess a lifetime distribution while emphasizing tail fit.

Interpretation and pitfalls

Watch out

There is no universal fitted-parameter Anderson–Darling p-value formula covering all distributions.

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

General goodness-of-fit example against fully specified N(0,1), calibrated by Monte Carlo. This differs from a normality test that estimates mean and variance.

Python · native

Validated — Executed successfully in the validation environment · needs numpy, scipy

import numpy as np
from scipy import stats
rng = np.random.default_rng(2026)
x=rng.normal(size=60)
def ad(x):
    u=np.sort(stats.norm.cdf(x));n=len(x)
    return -n-np.sum((2*np.arange(1,n+1)-1)*(np.log(u)+np.log1p(-u[::-1])))/n
t=ad(x);B=999;null=np.array([ad(rng.normal(size=len(x))) for _ in range(B)])
print(t,(1+np.sum(null>=t))/(B+1))
Output
1.4830755087936751 0.163
R

Validated — Executed successfully in the validation environment · needs Base/standard library

set.seed(2026)
x <- rnorm(60)
AD<-function(x) {u<-sort(pnorm(x));n<-length(x);-n-sum((2*seq_len(n)-1)*(log(u)+log1p(-rev(u))))/n}
T<-AD(x);B<-999;null<-replicate(B,AD(rnorm(length(x))))
print(c(AD=T,p=(1+sum(null>=T))/(B+1)))
Output
       AD         p 
0.7632261 0.5370000

Sources

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 118, updated from the reference's edition 2 (reviewed 14 November 2026) as STAT118.