Anderson–Darling test explained

The Anderson–Darling test is a statistical test of whether a given sample of data is drawn from a given probability distribution. In its basic form, the test assumes that there are no parameters to be estimated in the distribution being tested, in which case the test and its set of critical values is distribution-free. However, the test is most often used in contexts where a family of distributions is being tested, in which case the parameters of that family need to be estimated and account must be taken of this in adjusting either the test-statistic or its critical values. When applied to testing whether a normal distribution adequately describes a set of data, it is one of the most powerful statistical tools for detecting most departures from normality.[1] [2] K-sample Anderson–Darling tests are available for testing whether several collections of observations can be modelled as coming from a single population, where the distribution function does not have to be specified.

In addition to its use as a test of fit for distributions, it can be used in parameter estimation as the basis for a form of minimum distance estimation procedure.

The test is named after Theodore Wilbur Anderson (1918–2016) and Donald A. Darling (1915–2014), who invented it in 1952.[3]

The single-sample test

The Anderson–Darling and Cramér–von Mises statistics belong to the class ofquadratic EDF statistics (tests based on the empirical distribution function).[2] If the hypothesized distribution is

F

, and empirical (sample) cumulative distribution function is

Fn

, then the quadratic EDF statistics measure the distance between

F

and

Fn

by

n

infty
\int
-infty

(Fn(x)-F(x))2w(x)dF(x),

where

n

is the number of elements in the sample, and

w(x)

is a weighting function. When the weighting function is

w(x)=1

, the statisticis the Cramér–von Mises statistic. The Anderson–Darling (1954) test[4] is based on the distance

A2=n

infty
\int
-infty
(Fn(x)-F(x))2
F(x)(1-F(x))

dF(x),

which is obtained when the weight function is

w(x)=[F(x)(1-F(x))]-1

. Thus, compared with the Cramér–von Mises distance, the Anderson–Darling distance places more weight on observations in the tails of the distribution.

Basic test statistic

A

to assess if data

\{Y1<<Yn\}

(note that the data must be put in order) comes from a CDF

F

is

A2=-n-S,

where

n
S=\sum
i=1
2i-1
n

\left[ln(F(Yi))+ln\left(1-F(Yn+1-i)\right)\right].

The test statistic can then be compared against the critical values of the theoretical distribution. In this case, no parameters are estimated in relation to the cumulative distribution function

F

.

Tests for families of distributions

Essentially the same test statistic can be used in the test of fit of a family of distributions, but then it must be compared against the critical values appropriate to that family of theoretical distributions and dependent also on the method used for parameter estimation.

Test for normality

Empirical testing has found[5] that the Anderson–Darling test is not quite as good as the Shapiro–Wilk test, but is better than other tests. Stephens[1] found

A2

to be one of the best empirical distribution function statistics for detecting most departures from normality.

The computation differs based on what is known about the distribution:[6]

\mu

and the variance

\sigma2

are both known.

\sigma2

is known, but the mean

\mu

is unknown.

\mu

is known, but the variance

\sigma2

is unknown.

\mu

and the variance

\sigma2

are unknown.

The n observations,

Xi

, for

i=1,\ldotsn

, of the variable

X

must be sorted such that

X1\leqX2\leq...\leqXn

and the notation in the following assumes that Xi represent the ordered observations. Let

\hat{\mu}= \begin{cases} \mu,&ifthemeanisknown.\\ \bar{X}=

1
n
n
\sum
i=1

Xi,&otherwise. \end{cases}

\hat{\sigma}2= \begin{cases} \sigma2,&ifthevarianceisknown.\\

1
n
n
\sum
i=1

(Xi-\mu)2,&ifthevarianceisnotknown,butthemeanis.\\

1
n-1
n
\sum
i=1

(Xi-\bar{X})2,&otherwise. \end{cases}

The values

Xi

are standardized to create new values

Yi

, given by
Y
i=Xi-\hat{\mu
}.With the standard normal CDF

\Phi

,

A2

is calculated using

A2=-n-

1
n
n
\sum
i=1

(2i-1)(ln\Phi(Yi)+ln(1-\Phi(Yn+1-i))).

An alternative expression in which only a single observation is dealt with at each step of the summation is:

A2=-n-

1
n
n\left[(2i-1)ln\Phi(Y
\sum
i)+(2(n-i)+1)ln(1-\Phi(Y

i))\right].

A modified statistic can be calculated using

A*2=

2\left(1+4
n
\begin{cases} A-
25
n2

\right),&ifthevarianceandthemeanarebothunknown.\\ A2,&otherwise. \end{cases}

If

A2

or

A*2

exceeds a given critical value, then the hypothesis of normality is rejected withsome significance level. The critical values are given in the table below for values of

A*2

.[1] [7]

Note 1: If

\hat{\sigma}

= 0 or any

\Phi(Yi)=

(0 or 1) then

A2

cannot be calculated and is undefined.

Note 2: The above adjustment formula is taken from Shorack & Wellner (1986, p239). Care is required in comparisons across different sources as often the specific adjustment formula is not stated.

Note 3: Stephens[1] notes that the test becomes better when the parameters are computed from the data, even if they are known.

Note 4: Marsaglia & Marsaglia[7] provide a more accurate result for Case 0 at 85% and 99%.

Case n 15% 10% 5% 2.5% 1%
0 ≥ 5 1.621 1.933 2.492 3.070 3.878
1 0.908 1.105 1.304 1.573
2 ≥ 5 1.760 2.323 2.904 3.690
3 10 0.514 0.578 0.683 0.779 0.926
20 0.528 0.591 0.704 0.815 0.969
50 0.546 0.616 0.735 0.861 1.021
100 0.559 0.631 0.754 0.884 1.047

infty

0.576 0.656 0.787 0.918 1.092

Alternatively, for case 3 above (both mean and variance unknown), D'Agostino (1986) [6] in Table 4.7 on p. 123 and on pages 372–373 gives the adjusted statistic:

A*2

2\left(1+0.75
n
=A+
2.25
n2

\right).

and normality is rejected if

A*2

exceeds 0.631, 0.754, 0.884, 1.047, or 1.159 at 10%, 5%, 2.5%, 1%, and 0.5% significance levels, respectively; the procedure is valid for sample size at least n=8. The formulas for computing the p-values for other values of

A*2

are given in Table 4.9 on p. 127 in the same book.

Tests for other distributions

Above, it was assumed that the variable

Xi

was being tested for normal distribution. Any other family of distributions can be tested but the test for each family is implemented by using a different modification of the basic test statistic and this is referred to critical values specific to that family of distributions. The modifications of the statistic and tables of critical values are given by Stephens (1986)[2] for the exponential, extreme-value, Weibull, gamma, logistic, Cauchy, and von Mises distributions. Tests for the (two-parameter) log-normal distribution can be implemented by transforming the data using a logarithm and using the above test for normality. Details for the required modifications to the test statistic and for the critical values for the normal distribution and the exponential distribution have been published by Pearson & Hartley (1972, Table 54). Details for these distributions, with the addition of the Gumbel distribution, are also given by Shorack & Wellner (1986, p239). Details for the logistic distribution are given by Stephens (1979). A test for the (two parameter) Weibull distribution can be obtained by making use of the fact that the logarithm of a Weibull variate has a Gumbel distribution.

Non-parametric k-sample tests

Fritz Scholz and Michael A. Stephens (1987) discuss a test, based on the Anderson–Darling measure of agreement between distributions, for whether a number of random samples with possibly different sample sizes may have arisen from the same distribution, where this distribution is unspecified.[8] The R package kSamples and the Python package Scipy implements this rank test for comparing k samples among several other such rank tests.[9] [10]

For

k

samples the statistic can be computed as follows under the assumption that the distribution function

Fi

of

i

-th sample is continuous
2
A
kN

=

1
N
k
\sum
i=1
1
ni
N-1
\sum
j=1
(NM-
2
jn
i)
ij
j(N-j)

where

ni

is the number of observations in the

i

-th sample

N

is the total number of observations in all samples

Z1<<ZN

is the pooled ordered sample

Mij

is the number of observations in the

i

-th sample that are not greater than

Zj

.[8]

See also

Further reading

External links

Notes and References

  1. M. A. . Stephens . 1974 . EDF Statistics for Goodness of Fit and Some Comparisons . Journal of the American Statistical Association . 69 . 347 . 730–737 . 10.2307/2286009. 2286009 .
  2. Book: D'Agostino, R. B. . Stephens, M. A. . 1986. Goodness-of-Fit Techniques. Tests Based on EDF Statistics. M. A. Stephens. Marcel Dekker. New York. 0-8247-7487-6.
  3. T. W. . Anderson . Theodore W. Anderson . Darling, D. A. . Donald Allan Darling . 1952 . Asymptotic theory of certain "goodness-of-fit" criteria based on stochastic processes . Annals of Mathematical Statistics . 23 . 2 . 193–212 . 10.1214/aoms/1177729437 . free .
  4. Anderson, T.W. . Darling, D.A.. A Test of Goodness-of-Fit. Journal of the American Statistical Association. 1954. 49. 268 . 765–769. 10.2307/2281537. 2281537 .
  5. Razali . Nornadiah . Wah, Yap Bee . Power comparisons of Shapiro–Wilk, Kolmogorov–Smirnov, Lilliefors and Anderson–Darling tests . Journal of Statistical Modeling and Analytics . 2011 . 2 . 1 . 21–33.
  6. Book: D'Agostino, R.B. . Stephens, M.A. . 1986. Goodness-of-Fit Techniques. Tests for the Normal Distribution. Ralph B. D'Agostino. Marcel Dekker. New York. 0-8247-7487-6.
  7. G.. Marsaglia. 2004 . Evaluating the Anderson-Darling Distribution . Journal of Statistical Software . 9 . 2 . 730–737 . 10.18637/jss.v009.i02. free. 10.1.1.686.1363.
  8. Scholz . F. W. . Stephens . M. A. . 1987 . K-sample Anderson–Darling Tests . . 82 . 399 . 918–924 . 10.1080/01621459.1987.10478517 .
  9. Web site: kSamples: K-Sample Rank Tests and their Combinations . R Project .
  10. Web site: The Anderson-Darling test for k-samples. Scipy package. .