public void AndersonDarlingConstructorTest()
{
// Test against a standard Uniform distribution
// References: http://www.math.nsysu.edu.tw/~lomn/homepage/class/92/kstest/kolmogorov.pdf
// Suppose we got a new sample, and we would like to test whether this
// sample seems to have originated from a uniform continuous distribution.
//
double[] sample =
{
0.621, 0.503, 0.203, 0.477, 0.710, 0.581, 0.329, 0.480, 0.554, 0.382
};
// First, we create the distribution we would like to test against:
//
var distribution = UniformContinuousDistribution.Standard;
// Now we can define our hypothesis. The null hypothesis is that the sample
// comes from a standard uniform distribution, while the alternate is that
// the sample is not from a standard uniform distribution.
//
var adtest = new AndersonDarlingTest(sample, distribution);
double statistic = adtest.Statistic; // 1.3891622091168489561
double pvalue = adtest.PValue; // 0.2052
bool significant = adtest.Significant; // false
// Since the null hypothesis could not be rejected, then the sample
// can perhaps be from a uniform distribution. However, please note
// that this doesn't means that the sample *is* from the uniform, it
// only means that we could not rule out the possibility.
Assert.AreEqual(distribution, adtest.TheoreticalDistribution);
Assert.AreEqual(DistributionTail.TwoTail, adtest.Tail);
Assert.AreEqual(1.3891622091168489561, statistic, 1e-10);
Assert.AreEqual(0.2052039626840637121, pvalue, 1e-10);
Assert.IsFalse(Double.IsNaN(pvalue));
// Tested against R's package ADGofTest
/*
X <- c( 0.621, 0.503, 0.203, 0.477, 0.710, 0.581, 0.329, 0.480, 0.554, 0.382)
ad.test(X)
Anderson-Darling GoF Test
data: X
AD = 1.3891999999999999904, p-value = 0.2052
alternative hypothesis: NA
*/
Assert.IsFalse(adtest.Significant);
}