[R] calculation of the p value in ks.test()

Uwe Ligges ligges at statistik.uni-dortmund.de
Wed Sep 17 08:58:39 CEST 2003


Rajarshi Guha wrote:

> Hi,
>   I'm working with the ks.test() function and I have also implemented
> the test using Conover as the reference. My D value matches that
> produced by R. However to calculate the p value I am using the code
> described in Numerical Recipes in C++ (2nd Ed.) pg 631.
> 
> The p value produced by the NRC code is generally larger than that
> produced by R by a factor of 10. Currently I am not in a position to
> download the R source and look at it - lack of space :(

Cannot believe: Lack of *_space_*???


> has anybody used the NRC code? The text mentions that it calculates the
> sum
> 
> Q(L) = 2 \sum^{-\infty}_{j=1} (-1)^(j-1) \exp^{-2 j^2 L^2}
> 
> and the value of L is given by
> 
> [ sqrt(n) + 0.12 + 0.11 / sqrt(n) ] * D
> 
> where n = n1*n2/(n1+n2) .. n1, n2 are lengths of the vectors
> and D is the calculated statistic.
> 
> Is this the same definition as used in R?


No. Since you have a working copy of R (obviously a binary version?), 
you only need the file ks.c. If that 3kB file won't flood your harddisk, 
I'll send it in a private message.

Uwe Ligges




More information about the R-help mailing list