Kolmogorov–Smirnov test

标签:
k-stest教育 |
分类: matlab及perl学习 |
柯尔莫可洛夫-斯米洛夫检验(K-S test)
分类:
1、Single sample Kolmogorov-Smirnov goodness-of-fit hypothesis test.
>> H = KSTEST(X,CDF,ALPHA,TAIL) % X为待检测样本,CDF可选:如果空缺,则默认为检测标准正态分布;
如果填写两列的矩阵,第一列是x的可能的值,第二列是相应的假设累计概率分布函数的值G(x)。ALPHA是显著性水平(默认0.05)。TAIL是表示检验的类型(默认unequal,不平衡)。还有larger,smaller可以选择。
例如,
x = -2:1:4
x =
[h,p,k,c] = kstest(x,[],0.05,0)
h =
p =
k =
c =
The test fails to reject the null hypothesis that the values come from a standard normal distribution.
2、Two-sample Kolmogorov-Smirnov test
>>[h,p,ks2stat] = kstest2(x1,x2,alpha,tail)
% x1,x2都为向量,ALPHA是显著性水平(默认0.05)。TAIL是表示检验的类型(默认unequal,不平衡)。
例如,x = -1:1:5
y = randn(20,1);
[h,p,k] = kstest2(x,y)
h =
p =
k =
wiki翻译起来太麻烦,还有可能曲解本意,最好看原版解释。
The two-sample KS test is one of the most useful and general nonparametric methods for comparing two samples, as it is sensitive to differences in both location and shape of the empirical cumulative distribution functions of the two samples.
The Kolmogorov–Smirnov test can be modified to serve as a goodness of fit test. In the special case of testing for normality of the distribution, samples are standardized and compared with a standard normal distribution. This is equivalent to setting the mean and variance of the reference distribution equal to the sample estimates, and it is known that using the sample to modify the null hypothesis reduces the power of a test. Correcting for this bias leads to the Lilliefors test. However, even Lilliefors' modification is less powerful than the Shapiro–Wilk test or Anderson–Darling test for testing normality.[1]
Kolmogorov–Smirnov statistic
The empirical distribution function Fn for n iid observations Xi is defined as
where http://upload.wikimedia.org/math/7/9/0/790f58e3dd7575eb52229c6b68d9c232.pngtest" />
is the indicator
function, equal to 1 if
Xi
The Kolmogorov–Smirnov statistic for a given cumulative distribution function F(x) is
where sup
Kolmogorov distribution
The Kolmogorov distribution is the distribution of the random variable
where B(t) is the Brownian bridge. The cumulative distribution function of K is given by
- http://upload.wikimedia.org/math/2/8/9/2899bf257fc0aa1f48b3ffcff8f783ae.pngtest" />
- Kolmogorov–Smirnov test
-
Under null hypothesis that the sample comes from the hypothesized distribution F(x),
in distribution, where B(t) is the Brownian bridge.
If F is continuous then under the null hypothesis http://upload.wikimedia.org/math/1/e/c/1ec425f3720cd63ffabd65504c798972.pngtest" /> converges to the Kolmogorov distribution, which does not depend on F. This result may also be known as the Kolmogorov theorem; see Kolmogorov's theorem for disambiguation.
The goodness-of-fit test or the Kolmogorov–Smirnov test is constructed by using the critical values of the Kolmogorov distribution.
The null hypothesis is rejected at level α if
where Kα is found from
The asymptotic power of this test is 1. If the form or parameters of F(x) are determined from the Xi, the inequality may not hold. In this case, Monte Carlo or other methods are required to determine the rejection level α.