Anderson Darling Test Class
Definition
Assembly: Numerics.NET (in Numerics.NET.dll) Version: 9.0.7
public sealed class AndersonDarlingTest : OneSampleTest
- Inheritance
- Object → HypothesisTest → OneSampleTest<Double> → OneSampleTest → AndersonDarlingTest
Remarks
The Anderson-Darling test is a statistical test used to determine if a sample of data comes from a specific distribution, in this case, the normal distribution. The null hypothesis for this test is that the sample is drawn from a population that follows the specified distribution.
The test statistic is calculated based on the cumulative distribution function (CDF) of the specified distribution. The Anderson-Darling test gives more weight to the tails of the distribution than the Kolmogorov-Smirnov test, making it more sensitive to deviations in the tails.
The distribution of the test statistic under the null hypothesis is used to determine the p-value, which indicates the probability of observing the test statistic as extreme as, or more extreme than, the value calculated from the sample data, assuming the null hypothesis is true.
Applications of the Anderson-Darling test include testing for normality in quality control, finance, and other fields where the assumption of normality is critical. The test can also be applied to other distributions by specifying the appropriate distribution type.
The AndersonDarlingDistribution class implements the distribution of the Anderson-Darling test statistic for various distributions.
Use the AndersonDarlingTest class to test whether a sample comes from a normal distribution. The Anderson-Darling test is a variation of the Kolmogorov-Smirnov test that gives more weight to the tails of the distribution. In addition, the parameters of the distribution may be estimated from the sample. This makes the test more applicable in a larger number of cases.
The Mean and StandardDeviation of the distribution may be specified, but this is not necessary.
Example
The following example demonstrates how to use the Anderson-Darling test with different constructors and how to access its properties and methods.
using Numerics.NET.Statistics;
using Numerics.NET.Statistics.Tests;
using Numerics.NET.Statistics.Distributions;
// Example 1: Using the default constructor
Vector<double> data1 = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];
var test1 = new AndersonDarlingTest(data1);
double statistic1 = test1.CalculateStatistic();
double pValue1 = test1.GetPValue(HypothesisType.OneTailedUpper);
Console.WriteLine($"Statistic: {statistic1}, P-Value: {pValue1}");
// Example 2: Using the constructor with a specified distribution
Vector<double> data2 = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];
var normalDist = new NormalDistribution(0, 1);
var test2 = new AndersonDarlingTest(data2, normalDist);
double statistic2 = test2.CalculateStatistic();
double pValue2 = test2.GetPValue(HypothesisType.OneTailedUpper);
Console.WriteLine($"Statistic: {statistic2}, P-Value: {pValue2}");
// Example 3: Using the constructor with a specified CDF function
Vector<double> data3 = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];
Func<double, double> cdf = x => new NormalDistribution(0, 1).DistributionFunction(x);
var test3 = new AndersonDarlingTest(data3, cdf);
double statistic3 = test3.CalculateStatistic();
double pValue3 = test3.GetPValue(HypothesisType.OneTailedUpper);
Console.WriteLine($"Statistic: {statistic3}, P-Value: {pValue3}");
// Example 4: Using the constructor with specified mean and standard deviation
Vector<double> data4 = [ 1.0, 2.0, 3.0, 4.0, 5.0 ];
var test4 = new AndersonDarlingTest(data4, 2, 3);
double statistic4 = test4.CalculateStatistic();
double pValue4 = test4.GetPValue(HypothesisType.OneTailedUpper);
Console.WriteLine($"Statistic: {statistic4}, P-Value: {pValue4}");
Constructors
Anderson | Constructs a new Anderson-Darling test of normality. |
Anderson | Constructs a new Anderson-Darling test of normality. |
Anderson | Constructs a new Anderson-Darling test for the specified distribution. |
Anderson | Constructs a new Anderson-Darling test for the specified distribution function. |
Anderson | Constructs a new Anderson-Darling test of normality. |
Properties
Distribution |
Gets the probability distribution used in the hypothesis test.
(Inherited from HypothesisTest) |
Hypothesis |
Gets or sets whether the test is one or two-tailed.
(Inherited from HypothesisTest) |
Mean | Gets or sets the mean of the distribution being tested. |
Name |
Gets the name of the hypothesis test.
(Overrides HypothesisTest.Name) |
PValue |
Gets the probability that the test statistic would take on the calculated value under the alternate hypothesis.
(Inherited from HypothesisTest) |
Sample |
Gets or sets the variable the test is to be applied to.
(Inherited from OneSampleTest<T>) |
Significance |
Gets the significance level used to test the null hypothesis.
(Inherited from HypothesisTest) |
Standard | Gets or sets the standard deviation of the distribution being tested. |
Statistic |
Gets the value of the test statistic.
(Inherited from HypothesisTest) |
Methods
Equals | Determines whether the specified object is equal to the current object. (Inherited from Object) |
Get |
Returns the confidence interval for the test parameter for the default confidence level.
(Inherited from HypothesisTest) |
Get |
Returns the confidence interval for the test parameter for the specified confidence level.
(Inherited from HypothesisTest) |
Get | Serves as the default hash function. (Inherited from Object) |
Get |
Gets the lower critical value for the hypothesis test's current significance level.
(Inherited from HypothesisTest) |
Get |
Gets the lower critical value for the hypothesis test at the specified significance level.
(Inherited from HypothesisTest) |
Get |
Gets the probability that the test statistic would take on the calculated value under the specified alternate hypothesis.
(Inherited from HypothesisTest) |
Get | Gets the Type of the current instance. (Inherited from Object) |
Get |
Gets the upper critical value for the test statistic at the hypothesis test's current significance level.
(Inherited from HypothesisTest) |
Get |
Gets the upper critical value for the test statistic at the specified significance level.
(Inherited from HypothesisTest) |
Reject() |
Returns whether the null hypothesis is rejected
using the default significance level.
(Inherited from HypothesisTest) |
Reject( |
Returns whether the null hypothesis is rejected using the specified significance level.
(Inherited from HypothesisTest) |
Summarize() |
Returns a string containing a human-readable summary of the object.
(Inherited from HypothesisTest) |
Summarize( |
Returns a string containing a human-readable summary of the object
using the specified options.
(Inherited from OneSampleTest<T>) |
ToString | Returns a string that represents the current object. (Inherited from HypothesisTest) |