Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kolmogorov-Smirnov test in R

Tags:

I tried to use the Kolmogorov-Smirnov test to test normality of a sample. This is a small simple example of what I do:

x <- rnorm(1e5, 1, 2) ks.test(x, "pnorm") 

Here is the result R gives me:

        One-sample Kolmogorov-Smirnov test  data:  x D = 0.3427, p-value < 2.2e-16 alternative hypothesis: two-sided 

The p-value is very low whereas the test should accept the null-hypothesis.

I do not understand why it does not work.

like image 854
gagaouthu Avatar asked Nov 03 '14 13:11

gagaouthu


People also ask

What is Kolmogorov-Smirnov test in R?

The Kolmogorov-Smirnov Test is a type of non-parametric test of the equality of discontinuous and continuous of a 1D probability distribution that is used to compare the sample with the reference probability test (known as one-sample K-S Test) or among two samples (known as two-sample K-S test).

How do you do a one sample KS test in R?

To perform a one-sample or two-sample Kolmogorov-Smirnov test in R we can use the ks. test() function.

What does Kolmogorov-Smirnov tell us?

The Kolmogorov-Smirnov test is used to test the null hypothesis that a set of data comes from a Normal distribution. The Kolmogorov Smirnov test produces test statistics that are used (along with a degrees of freedom parameter) to test for normality.

Why is Kolmogorov-Smirnov test used?

The Kolmogorov–Smirnov test is a nonparametric goodness-of-fit test and is used to determine wether two distributions differ, or whether an underlying probability distribution differes from a hypothesized distribution. It is used when we have two samples coming from two populations that can be different.


2 Answers

As pointed out in the ks.test help, you have to give to the ks.test function the arguments of pnorm. If you do not precise mean and standard variation, the test is done on a standard gaussian distribution.

Here you should write:

ks.test(x, "pnorm", 1, 2) #or ks.test(x, "pnorm", mean=1, sd=2)  
like image 156
Pop Avatar answered Oct 19 '22 13:10

Pop


I think it would be better to use mean=mean(x) and sd=sd(x) like

ks.test(x, "pnorm", mean=mean(x), sd=sd(x)) 
like image 29
Bappa Das Avatar answered Oct 19 '22 13:10

Bappa Das