Anderson-Darling Goodness-of-Fit Test β
The Anderson-Darling (A-D) test is a statistical method designed to evaluate whether a given sample of data follows a specified continuous probability distribution. It is especially sensitive to deviations in the tails of the distribution, making it effective for distributions with extreme values.
Test Procedure β
The Anderson-Darling test statistic
where:
is the number of observations in the dataset. represents the sorted observations in ascending order. is the cumulative distribution function (CDF) of the hypothesized distribution evaluated at .
Hypothesis Testing β
The hypotheses for the Anderson-Darling test are defined as:
- Null hypothesis
: The data follows the specified probability distribution. - Alternative hypothesis
: The data does not follow the specified probability distribution.
To determine the outcome, compare the calculated Anderson-Darling statistic to the critical value or p-value:
Critical value approach: If the test statistic
exceeds the critical value from the A-D distribution tables at the significance level (usually 0.05), the null hypothesis is rejected. p-value approach: Reject the null hypothesis if the calculated p-value is less than the chosen significance level.
Interpretation β
- Rejected (True): The dataset significantly deviates from the hypothesized distribution; reject the null hypothesis.
- Not Rejected (False): The dataset is consistent with the hypothesized distribution; accept the null hypothesis.
Implementation in Phitter β
In the Phitter library, the Anderson-Darling test is implemented through the method:
phi.get_test_anderson_darling(id_distribution: str) -> dict
Returned values: β
test_statistic
: The Anderson-Darling test statistic.critical_value
: The critical value from the Anderson-Darling distribution tables corresponding to the significance level.p_value
: The p-value associated with the test statistic.rejected
: Boolean indicating whether the null hypothesis is rejected (True
) or not (False
).
Example Usage β
import phitter
# Define dataset
data = [...]
# Fit distributions
phi = phitter.Phitter(data)
phi.fit()
# Anderson-Darling test for a specific distribution, e.g., "normal"
ad_results = phi.get_test_anderson_darling("normal")
print(ad_results)
This returns a dictionary containing the Anderson-Darling test statistic, critical value, p-value, and whether the null hypothesis is rejected.
Output:
{
"test_statistic": 4.621,
"critical_value": 11.070,
"p_value": 0.795,
"rejected": False
}
Apply Anderson Darling test to single distribution β
Continous case β
import phitter
# Define dataset
data = [...]
# Continous measures
continuous_measures = phitter.continuous.ContinuousMeasures(data)
# Define distribution instance
distribution_inst = phitter.continuous.Normal(continuous_measures=continuous_measures)
# Get test result
ad_results = phitter.continuous.evaluate_continuous_test_anderson_darling(distribution_inst, continuous_measures)
Additional Section: Insights from Evaluating the Anderson-Darling Distribution (Marsaglia & Marsaglia) β
In their paper Evaluating the Anderson-Darling Distribution, George Marsaglia and John C. W. Marsaglia present methods for accurately determining the distribution of the Anderson-Darling (AβD) test statisticβboth in the limiting case as the sample size
Below is a concise overview of the key ideas and the most relevant mathematical expressions from their work.
1. Limiting Distribution β
The Anderson-Darling statistic
Marsaglia & Marsaglia denote the cumulative distribution function (CDF) of
They show that
1.1. Asymptotic Formula β
A common form for
where
For
: For
:
These two pieces meet smoothly at
2. Finite- Correction β
Although
If
where
A simplified version of
where
3. Practical Relevance β
High Accuracy for P-Values
When using the Anderson-Darling statisticin hypothesis testing, the p-value can be computed as This formula yields a near-uniform distribution of p-values under the null hypothesis for sample sizes up to at least
(and beyond), thereby improving on simply using the large- tables or the raw limit. Better Finite-
Behavior
Marsaglia & Marsaglia show that directly applying the limiting distributionfor moderate can introduce systematic bias in the lower to middle quantiles. The correction mitigates this error. Algorithmic Simplicity
Although the derivations in the paper involve expansions and two-term recursions, the final βshortcutβ formulas forand are straightforward to implement. This makes them suitable for inclusion in codebases like Phitter where computational speed and simplicity are valuable.
References β
- Marsaglia, G. and Marsaglia, J. C. W. (2004). Evaluating the Anderson-Darling Distribution.