25

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.

avalokan
  • 3
  • 1
gagaouthu
  • 299
  • 1
  • 3
  • 9
  • 4
    you're testing against a standard normal above; try `ks.test(x,"pnorm",1,2)` – Ben Bolker Nov 03 '14 at 14:10
  • You may also find this interesting: http://stats.stackexchange.com/questions/2492/is-normality-testing-essentially-useless – rnso Nov 03 '14 at 14:40

2 Answers2

33

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) 
Pop
  • 12,135
  • 5
  • 55
  • 68
12

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))
UseR10085
  • 7,120
  • 3
  • 24
  • 54