Stats andersondarling test - CyrilB1531/lodestar GitHub Wiki
Development build. This page describes
main, not a released package. The latest published Lodestar.Stats is 0.5.0 ā read its documentation.
Home āŗ Stats āŗ Hypothesis tests
Tests a sample against the normal distribution, fitting its mean and spread.
public static AndersonResult Test(ReadOnlySpan<double> x)Parameters ā x is the sample, at least one value; the span is read, never modified. One
value or a constant sample has no spread to standardise by, and answers a NaN statistic and p-value
with the table, as scipy's does.
Returns ā AndersonResult: the A² statistic, the p-value interpolated from Stephens' table,
and the table itself ā the critical values for this sample size, and the significance levels they
belong to. A NaN or an infinity in the sample makes the statistic and the p-value NaN, as scipy's are,
and leaves the table unchanged.
Exceptions ā ArgumentException when the sample is empty.
Example ā ten heights, and the table they are read against.
using Lodestar.Stats;
double[] heights = [172.0, 168.0, 175.0, 180.0, 169.0, 171.0, 177.0, 165.0, 173.0, 179.0];
AndersonResult result = AndersonDarling.Test(heights);
double squared = Math.Round(result.Statistic, 4); // => 0.1373
double smallest = result.CriticalValues[0]; // => 0.511
double atFivePercent = result.CriticalValues[2]; // => 0.6850.1373 is below every critical value in the table, so the sample is consistent with a normal one
at every level the table covers.
Remarks ā read the critical values, not the p-value. The interpolation runs over a table from
15% down to 1%, and clamps at both ends, so the p-value cannot be reported outside [0.01, 0.15]
however far from normal the sample is. A sample that is wildly non-normal and one that is merely
suspicious both come back at 0.01.
using Lodestar.Stats;
double[] skewed = [1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 40.0];
double clamped = Math.Round(AndersonDarling.Test(skewed).PValue, 4); // => 0.01
double shapiro = Math.Round(ShapiroWilk.Test(skewed).PValue, 8); // => 1.7E-07Both reject. Only ShapiroWilk.Test says how emphatically, which is why
that one is the member to reach for when the number matters beyond "reject or not". This family's
own answer is the statistic against the table, and that is what
AndersonResult.CriticalValues is for.
The critical values depend on the sample size, because the distribution is fitted rather than
given: they are Stephens' constants divided by 1 + 0.75/n + 2.25/n² and rounded to three
decimals, exactly as scipy scales them. A table read from a textbook without that scaling is the
asymptotic one and is wrong for a short sample.
Applies to ā net10.0, netstandard2.0.
See also ā ShapiroWilk.Test, AndersonResult,
Bartlett.Test, the Python equivalence table.