Home
Products
Support
Blog
Resources
Company
NMath Stats User's Guide
TOC |  Previous |  Next |  Index

6.7 One Sample Kolmogorov-Smirnov Test

Class OneSampleKSTest performs a Kolmogorov-Smirnov test of the distribution of one sample. This class compares the distribution of a given sample to the hypothesized distribution defined by a specified cumulative distribution function (CDF). For each potential value x, the Kolmogorov-Smirnov test compares the proportion of values less than x with the expected number predicted by the specified CDF. The null hypothesis is that the given sample data follow the specified distribution. The alternative hypothesis that the data do not have that distribution.

Sample data can be passed to the constructor as a vector, numeric column in a data frame, or an array of doubles. The hypothesized distribution can be specified either by using an instance of ProbabilityDistribution or by supplying a delegate that encapsulates the CDF of the hypothesized distribution. For example, this code creates a OneSampleKSTest instance that compares the distribution of data to a standard normal distribution:

NormalDistribution norm = new NormalDistribution();
OneSampleKSTest ks = new OneSampleKSTest( data, norm );

If myDist.CDF() is the CDF for some distribution, this code creates a OneSampleKSTest instance that compares the distribution of the data in column 3 of DataFrame df to the hypothesized distribution:

OneSampleKSTest ks = new OneSampleKSTest( df[3],
  new NMathFunctions.DoubleUnaryFunction(myDist.CDF) );

By default, a OneSampleKSTest object performs the Kolmogorov-Smirnov test with . A different alpha level can be specified at the time of construction using constructor overloads, or after construction using the provided Alpha property.

Once you've constructed and configured a OneSampleKSTest object, you can access the various test results using the provided properties, as described in Section 6.1:

Console.WriteLine( "statistic = " + test.Statistic );
Console.WriteLine( "p-value = " + test.P );
Console.WriteLine( "alpha = " + test.Alpha );
Console.WriteLine( "reject the null hypothesis? " + test.Reject);

TOC |  Previous |  Next |  Index

Copyright © 2008 CenterSpace Software, LLC. All rights reserved.
All trademarks and registered trademarks mentioned on this web site are the property of their respective owners.
Contact Webmaster