{ } Raw JSON

bundles / scipy 1.18.0 / scipy / stats / _morestats / anderson

function

scipy.stats._morestats:anderson

source: /scipy/stats/_morestats.py:2369

Signature

def anderson(x, dist = norm, *, method = None)

Summary

Anderson-Darling test for data coming from a particular distribution.

Extended Summary

The Anderson-Darling test tests the null hypothesis that a sample is drawn from a population that follows a particular distribution. For the Anderson-Darling test, the critical values depend on which distribution is being tested against. This function works for normal, exponential, logistic, weibull_min, or Gumbel (Extreme Value Type I) distributions.

Parameters

x : array_like

Array of sample data.

dist : {'norm', 'expon', 'logistic', 'gumbel', 'gumbel_l', 'gumbel_r', 'extreme1', 'weibull_min'}, optional

The type of distribution to test against. The default is 'norm'. The names 'extreme1', 'gumbel_l' and 'gumbel' are synonyms for the same distribution.

method : str or instance of `MonteCarloMethod`

Defines the method used to compute the p-value. If method is "interpolated", the p-value is interpolated from pre-calculated tables. If method is an instance of MonteCarloMethod, the p-value is computed using scipy.stats.monte_carlo_test with the provided configuration options and other appropriate settings.

Returns

result : AndersonResult

If method is provided, this is an object with the following attributes:

statistic

The Anderson-Darling test statistic.

pvalue: float

The p-value corresponding with the test statistic, calculated according to the specified method.

If method is unspecified, this is an object with the following attributes:

statistic

The Anderson-Darling test statistic.

critical_values

The critical values for this distribution.

significance_level

The significance levels for the corresponding critical values in percents. The function returns critical values for a differing set of significance levels depending on the distribution that is being tested against.

fit_result

An object containing the results of fitting the distribution to the data.

Notes

Critical values provided when method is unspecified are for the following significance levels:

normal/exponential

15%, 10%, 5%, 2.5%, 1%

logistic

25%, 10%, 5%, 2.5%, 1%, 0.5%

gumbel_l / gumbel_r

25%, 10%, 5%, 2.5%, 1%

weibull_min

50%, 25%, 15%, 10%, 5%, 2.5%, 1%, 0.5%

If the returned statistic is larger than these critical values then for the corresponding significance level, the null hypothesis that the data come from the chosen distribution can be rejected. The returned statistic is referred to as 'A2' in the references.

For weibull_min, maximum likelihood estimation is known to be challenging. If the test returns successfully, then the first order conditions for a maximum likelihood estimate have been verified and the critical values correspond relatively well to the significance levels, provided that the sample is sufficiently large (>10 observations [7]). However, for some data - especially data with no left tail - anderson is likely to result in an error message. In this case, consider performing a custom goodness of fit test using scipy.stats.monte_carlo_test.

Examples

Test the null hypothesis that a random sample was drawn from a normal distribution (with unspecified mean and standard deviation).
import numpy as np
from scipy.stats import anderson
rng = np.random.default_rng(9781234521)
data = rng.random(size=35)
res = anderson(data, dist='norm', method='interpolate')
res.statistic
res.pvalue
✓
np.float64(0.012111200538380142)
The p-value is approximately 0.012,, so the null hypothesis may be rejected at a significance level of 2.5%, but not at a significance level of 1%.

See also

kstest

The Kolmogorov-Smirnov test for goodness-of-fit.

Aliases

  • scipy.stats.anderson

Referenced by