Description
Ks-kolmogorov-smirnow, this type of detection is often used to compare samples to a known distribution, while the two-sample KS detects a comparison of the cumulative distributions of two datasets. Generate normal distribution sample data (single sample)
Detects whether the dataset x conforms to the normal distribution, 100
x = Rnorm (M)
ks.test (x, "Pnorm")
one-sample Kolmogorov-smirnov test Data
: x
D = 0.12261, P-value = 0.09889
Detects whether the dataset x conforms to a normal distribution, 1000 number
x = rnorm (1000)
ks.test (x, "Pnorm"
one-sample Kolmogorov-smirnov test Data
: x
D = 0.018507, P-value = 0.8832
Alternative hypothesis:two-sided
#分析得, h0:u=u0; H1:u!=u0, the former is in accordance with normal distribution, the latter is not conform to the normal distribution
as the number increases, it is more close to the normal distribution.
Generate evenly distributed sample data (two-sample)
Set.seed (3)
x=runif (n=20,min = 0,max =) y=runif (n=20,min
= 0,max =)
plot (ECDF (x), Do.points=false, Verticals = T,xlim = C (0,20))
lines (ECDF (y), lty=3,do.points=false,verticals = T)
#p-value value is less than 0.05, so the cumulative distribution difference between the two sides is not significant
ks.test (x,y)
two-sample Kolmogorov-smirnov test
data: x and y
D = 0.3, P-value = 0.3356
alternative hypothesis:twd-sided '
#两级变化率相同, the P value is 1
x = C (1:100)
y = C (1:100)
ks.test (x,y)
ks.test (x,y)
two-sample Kolmogorov-smirnov Test
Data: x and y
D = 0, P-value = 1
Alternative hypothesis:two-sided
Summarize
KS test is a kind of nonparametric statistical test method, it is often used to compare the similarity between continuous probability distributions to determine whether a sample conforms to a known probability distribution (a single sample KS test), or to a direct comparison of two sample datasets (two-sample KS test), and to test the ECDF based on the empirical distribution function.