h = adtest(x) returns
a test decision for the null hypothesis that the data in vector x is
from a population with a normal distribution, using the Anderson-Darling test.
The alternative hypothesis is that x is not from
a population with a normal distribution. The result h is 1 if
the test rejects the null hypothesis at the 5% significance level,
or 0 otherwise.

h = adtest(x,Name,Value) returns
a test decision for the Anderson-Darling test with additional options
specified by one or more name-value pair arguments. For example, you
can specify a null distribution other than normal, or select an alternative
method for calculating the p-value.

Load the data set. Create a vector containing the first
column of the students' exam grades data.

load examgrades;
x = grades(:,1);

Test the null hypothesis that the exam grades come from
an extreme value distribution. You do not need to specify values for
the population parameters.

[h,p] = adtest(x,'Distribution','ev')

h =
0
p =
0.0714

The returned value of h = 0 indicates that adtest fails
to reject the null hypothesis at the default 5% significance level.

Sample data, specified as a vector. Missing observations in x,
indicated by NaN, are ignored.

Data Types: single | double

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments.
Name is the argument
name and Value is the corresponding
value. Name must appear
inside single quotes (' ').
You can specify several name and value pair
arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: 'Alpha',0.01,'MCTol',0.01 conducts
the hypothesis test at the 1% significance level, and determines the
p-value, p, using a Monte Carlo simulation with
a maximum Monte Carlo standard error for p of 0.01.

Hypothesized distribution of data vector x,
specified as the comma-separated pair consisting of 'Distribution' and
one of the following.

'norm'

Normal distribution

'exp'

Exponential distribution

'ev'

Extreme value distribution

'logn'

Lognormal distribution

'weibull'

Weibull distribution

In this case, you do not need to specify population parameters.
Instead, adtest estimates the distribution parameters
from the sample data and tests x against a composite
hypothesis that it comes from the selected distribution family with
parameters unspecified.

Alternatively, you can specify any continuous probability distribution
object for the null distribution. In this case, you must specify all
the distribution parameters, and adtest tests x against
a simple hypothesis that it comes from the given distribution with
its specified parameters.

Maximum Monte
Carlo standard error for the p-value, p,
specified as the comma-separated pair consisting of 'MCTol' and
a positive scalar value. If you use MCTol, adtest determines p using
a Monte Carlo simulation, and the name-value pair argument Asymptotic must
have the value false.

Method for calculating the p-value of the
Anderson-Darling test, specified as the comma-separated pair consisting
of 'Asymptotic' and either true or false.
If you specify 'true', adtest estimates
the p-value using the limiting distribution of
the Anderson-Darling test statistic. If you specify false, adtest calculates
the p-value based on an analytical formula. For
sample sizes greater than 120, the limiting distribution estimate
is likely to be more accurate than the small sample size approximation
method.

If you specify a distribution family with unknown
parameters for the Distribution name-value pair, Asymptotic must
be false.

If you use MCTol to calculate the p-value
using a Monte Carlo simulation, Asymptotic must
be false.

p-value of the Anderson-Darling test, returned
as a scalar value in the range [0,1]. p is the
probability of observing a test statistic as extreme as, or more extreme
than, the observed value under the null hypothesis. p is
calculated using one of these methods:

If the hypothesized distribution is a fully specified
probability distribution object, adtest calculates p analytically.
If 'Asymptotic' is true, adtest uses
the asymptotic distribution of the test statistic. If you specify
a value for 'MCTol', adtest uses
a Monte Carlo simulation.

If the hypothesized distribution is specified as a
distribution family with unknown parameters, adtest retrieves
the critical value from a table and uses inverse interpolation to
determine the p-value. If you specify a value for 'MCTol', adtest uses
a Monte Carlo simulation.

Test statistic for the Anderson-Darling test, returned as a
scalar value.

If the hypothesized distribution is a fully specified
probability distribution object, adtest computes adstat using
specified parameters.

If the hypothesized distribution is specified as a
distribution family with unknown parameters, adtest computes adstat using
parameters estimated from the sample data.

Critical value for the Anderson-Darling test at the significance
level Alpha, returned as a scalar value. adtest determines cv by
interpolating into a table based on the specified Alpha significance
level.

The Anderson-Darling test is commonly used
to test whether a data sample comes from a normal distribution. However,
it can be used to test for another hypothesized distribution, even
if you do not fully specify the distribution parameters. Instead,
the test estimates any unknown parameters from the data sample.

The test statistic belongs to the family of quadratic empirical
distribution function statistics, which measure the distance between
the hypothesized distribution, F(x)
and the empirical cdf, F_{n}(x)
as

over the ordered sample values , where w(x)
is a weight function and n is the number of data
points in the sample.

The weight function for the Anderson-Darling test is

which places greater weight on the observations
in the tails of the distribution, thus making the test more sensitive
to outliers and better at detecting departure from normality in the
tails of the distribution.

The Anderson-Darling test statistic is

where are the ordered
sample data points and n is the number of data
points in the sample.

In adtest, the decision to reject or not
reject the null hypothesis is based on comparing the p-value
for the hypothesis test with the specified significance level, not
on comparing the test statistic with the critical value.

The Monte Carlo standard error is the error
due to simulating the p-value.

The Monte Carlo standard error is calculated as

where is
the estimated p-value of the hypothesis test, and mcreps is
the number of Monte Carlo replications performed.

adtest chooses the number of Monte Carlo
replications, mcreps, large enough to make the
Monte Carlo standard error for less
than the value specified for MCTol.