[R] Question about Kolmogorov-Smirnov Test

Uwe Ligges ligges at statistik.tu-dortmund.de
Wed Nov 26 14:43:53 CET 2008



Ricardo Ríos wrote:
> Hi wizards
> 
> I have the following code for a Kolmogorov-Smirnov Test:
> 
> z<-c(1.6,10.3,3.5,13.5,18.4,7.7,24.3,10.7,8.4,4.9,7.9,12,16.2,6.8,14.7)
> ks.test(z,"pexp",1/10)$statistic
> 
> The Kolmogorov-Smirnov statistic is:
> 
>        D
> 0.293383
> 
> However, I have calculated the Kolmogorov-Smirnov statistic with the
> following R code:
> 
> z<-c(1.6,10.3,3.5,13.5,18.4,7.7,24.3,10.7,8.4,4.9,7.9,12,16.2,6.8,14.7)
> a<-sort(z)
> d<- pexp(a, rate = 1/10, lower.tail = TRUE, log.p = FALSE)
> w=numeric(length = length(a))
> for(i in 1:length(a)) w[i]=i/15
> max(abs(w-d))
> 
> But I have obtained the following result:
> 
> [1] 0.2267163
>
> Why these results are not equal?

w is calculated as follows:

w <- (seq(along=a)-1)/length(a)
[ {0, ..., n-1} rather than {1, ..., n} ]


Uwe Ligges


> Thanks in advance
>



More information about the R-help mailing list