KolmogorovSmirnovTest Class |
Namespace: Accord.Statistics.Testing
[SerializableAttribute] public class KolmogorovSmirnovTest : HypothesisTest<KolmogorovSmirnovDistribution>, IHypothesisTest<KolmogorovSmirnovDistribution>, IHypothesisTest
The KolmogorovSmirnovTest type exposes the following members.
Name | Description | |
---|---|---|
KolmogorovSmirnovTest(Double, IDistributionDouble) |
Creates a new One-Sample Kolmogorov test.
| |
KolmogorovSmirnovTest(Double, IDistributionDouble, KolmogorovSmirnovTestHypothesis) |
Creates a new One-Sample Kolmogorov test.
|
Name | Description | |
---|---|---|
CriticalValue |
Gets the critical value for the current significance level.
(Inherited from HypothesisTestTDistribution.) | |
EmpiricalDistribution |
Gets the empirical distribution measured from the sample.
| |
Hypothesis |
Gets the alternative hypothesis under test. If the test is
Significant, the null hypothesis can be rejected
in favor of this alternative hypothesis.
| |
PValue |
Gets the P-value associated with this test.
(Inherited from HypothesisTestTDistribution.) | |
Significant |
Gets whether the null hypothesis should be rejected.
(Inherited from HypothesisTestTDistribution.) | |
Size |
Gets the significance level for the
test. Default value is 0.05 (5%).
(Inherited from HypothesisTestTDistribution.) | |
Statistic |
Gets the test statistic.
(Inherited from HypothesisTestTDistribution.) | |
StatisticDistribution |
Gets the distribution associated
with the test statistic.
(Inherited from HypothesisTestTDistribution.) | |
Tail |
Gets the test type.
(Inherited from HypothesisTestTDistribution.) | |
TheoreticalDistribution |
Gets the theoretical, hypothesized distribution for the samples,
which should have been stated before any measurements.
|
Name | Description | |
---|---|---|
Equals | Determines whether the specified object is equal to the current object. (Inherited from Object.) | |
Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) | |
GetHashCode | Serves as the default hash function. (Inherited from Object.) | |
GetStatistic |
Gets the appropriate Kolmogorov-Sminorv D statistic for the samples and target distribution.
| |
GetType | Gets the Type of the current instance. (Inherited from Object.) | |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) | |
OneSideLower |
Gets the one-sided "Dn-" Kolmogorov-Sminorv statistic for the samples and target distribution.
| |
OneSideUpper |
Gets the one-sided "Dn+" Kolmogorov-Sminorv statistic for the samples and target distribution.
| |
OnSizeChanged |
Called whenever the test significance level changes.
(Inherited from HypothesisTestTDistribution.) | |
PValueToStatistic |
Converts a given p-value to a test statistic.
(Overrides HypothesisTestTDistributionPValueToStatistic(Double).) | |
StatisticToPValue |
Converts a given test statistic to a p-value.
(Overrides HypothesisTestTDistributionStatisticToPValue(Double).) | |
ToString |
Converts the numeric P-Value of this test to its equivalent string representation.
(Inherited from HypothesisTestTDistribution.) | |
ToString(String, IFormatProvider) |
Converts the numeric P-Value of this test to its equivalent string representation.
(Inherited from HypothesisTestTDistribution.) | |
TwoSide |
Gets the two-sided "Dn" Kolmogorov-Sminorv statistic for the samples and target distribution.
|
Name | Description | |
---|---|---|
HasMethod |
Checks whether an object implements a method with the given name.
(Defined by ExtensionMethods.) | |
IsEqual |
Compares two objects for equality, performing an elementwise
comparison if the elements are vectors or matrices.
(Defined by Matrix.) | |
To(Type) | Overloaded.
Converts an object into another type, irrespective of whether
the conversion can be done at compile time or not. This can be
used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.) | |
ToT | Overloaded.
Converts an object into another type, irrespective of whether
the conversion can be done at compile time or not. This can be
used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.) |
The Kolmogorov-Smirnov test tries to determine if a sample differs significantly from an hypothesized theoretical probability distribution. The Kolmogorov-Smirnov test has an interesting advantage in which it does not requires any assumptions about the data. The distribution of the K-S test statistic does not depend on which distribution is being tested.
The K-S test has also the advantage of being an exact test (other tests, such as the chi-square goodness-of-fit test depends on an adequate sample size). One disadvantage is that it requires a fully defined distribution which should not have been estimated from the data. If the parameters of the theoretical distribution have been estimated from the data, the critical region of the K-S test will be no longer valid.
This class uses an efficient and high-accuracy algorithm based on work by Richard Simard (2010). Please see KolmogorovSmirnovDistribution for more details.
References:
In this first example, suppose we got a new sample, and we would like to test whether this sample has been 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 kstest = new KolmogorovSmirnovTest(sample, distribution); double statistic = kstest.Statistic; // 0.29 double pvalue = kstest.PValue; // 0.3067 bool significant = kstest.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.
Before we could not rule out the possibility that the sample came from a uniform distribution, which means the sample was not very far from uniform. This would be an indicative that it would be far from what would be expected from a Normal distribution:
// First, we create the distribution we would like to test against: // NormalDistribution distribution = NormalDistribution.Standard; // Now we can define our hypothesis. The null hypothesis is that the sample // comes from a standard Normal distribution, while the alternate is that // the sample is not from a standard Normal distribution. // var kstest = new KolmogorovSmirnovTest(sample, distribution); double statistic = kstest.Statistic; // 0.580432 double pvalue = kstest.PValue; // 0.000999 bool significant = kstest.Significant; // true
Since the test says that the null hypothesis should be rejected, then this can be regarded as a strong indicative that the sample does not comes from a Normal distribution, just as we expected.