The execution of KS test _r language in R language

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.