Products & Services Industries Academia Support User Community Company

Learn more about Statistics Toolbox   

kstest2 - Two-sample Kolmogorov-Smirnov test

Syntax

h = kstest2(x1,x2)
h = kstest2(x1,x2,alpha,type)
[h,p] = kstest2(...)
[h,p,ks2stat] = kstest2(...)

Description

h = kstest2(x1,x2) performs a two-sample Kolmogorov-Smirnov test to compare the distributions of the values in the two data vectors x1 and x2. The null hypothesis is that x1 and x2 are from the same continuous distribution. The alternative hypothesis is that they are from different continuous distributions. The result h is 1 if the test rejects the null hypothesis at the 5% significance level; 0 otherwise.

The test statistic is:

where is the proportion of x1 values less than or equal to x and is the proportion of x2 values less than or equal to x.

h = kstest2(x1,x2,alpha) specifies the significance level alpha for the test. The default is 0.05.

h = kstest2(x1,x2,alpha,type) specifies the type of test using one of the following values for the string type:

[h,p] = kstest2(...) also returns the asymptotic p-value p. The asymptotic p-value becomes very accurate for large sample sizes, and is believed to be reasonably accurate for sample sizes n1 and n2 such that (n1*n2)/(n1 + n2) >= 4.

[h,p,ks2stat] = kstest2(...) also returns the p-value p and the test statistic ks2stat.

Examples

The following test compares the distributions of a small evenly-spaced sample and a larger normal sample:

x = -1:1:5
y = randn(20,1);
[h,p,k] = kstest2(x,y)
h =
     0
p =
    0.0774
k =
    0.5214

The following figure illustrates the test statistic:

F1 = cdfplot(x);
hold on
F2 = cdfplot(y)
set(F1,'LineWidth',2,'Color','r')
set(F2,'LineWidth',2)
legend([F1 F2],'F1(x)','F2(x)','Location','NW')

The test statistic k is the maximum difference between the curves.

References

[1] Massey, F. J. "The Kolmogorov-Smirnov Test for Goodness of Fit." Journal of the American Statistical Association. Vol. 46, No. 253, 1951, pp. 68–78.

[2] Miller, L. H. "Table of Percentage Points of Kolmogorov Statistics." Journal of the American Statistical Association. Vol. 51, No. 273, 1956, pp. 111–121.

[3] Marsaglia, G., W. Tsang, and J. Wang. "Evaluating Kolmogorov's Distribution." Journal of Statistical Software. Vol. 8, Issue 18, 2003.

[4] Stephens, M. A. "Use of the Kolmogorov-Smirnov, Cramer-Von Mises and Related Statistics Without Extensive Tables." Journal of the Royal Statistical Society. Series B, Vol. 32, No. 1, 1970, pp. 115–122.

See Also

kstest, lillietest

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS