John Chen
2005-Oct-07 12:05 UTC
[R] permutational Kolmogorov-Smirnov p-value for paired data
Dear List, I am new to R and find it very powerful. I would like to compute the permutational p-value for paired data using Kolmogorov-Smirnov, but the built-in ks.test does not have this option, unlike the t.test which has a paired=TRUE flag. Has someone written a library or a routine that does this? Alternatively, if someone could show me how to do pair-wise permutations in R, then I can compute the ks statistic for each permutation, that'll work too. Thank you! John
Greg Snow
2005-Oct-11 18:46 UTC
[R] permutational Kolmogorov-Smirnov p-value for paired data
Here is one way to do a paired permutation test:
perm1 <- function(x,y){
rb <- rbinom(length(x),1,0.5)
xp <- ifelse(rb==1, x, y)
yp <- ifelse(rb==1, y, x)
ks.test(xp,yp)$statistic
}
my.x <- rnorm(100)
my.y <- my.x + rnorm(100, 0.2, 0.1)
mystat <- ks.test(my.x,my.y)$statistic
out <- replicate(1000, perm1(my.x,my.y) )
hist(out)
abline(v=mystat)
mean(out > mystat)
hope this helps,
Greg Snow, Ph.D.
Statistical Data Center, LDS Hospital
Intermountain Health Care
greg.snow at ihc.com
(801) 408-8111
>>> John Chen <jwcasl at gmail.com> 10/07/05 06:05AM >>>
Dear List,
I am new to R and find it very powerful. I would like to compute the
permutational p-value for paired data using Kolmogorov-Smirnov, but
the built-in ks.test does not have this option, unlike the t.test
which has a paired=TRUE flag. Has someone written a library or a
routine that does this? Alternatively, if someone could show me how to
do pair-wise permutations in R, then I can compute the ks statistic
for each permutation, that'll work too. Thank you!
John
______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
Possibly Parallel Threads
- How to calculate p-value for Kolmogorov Smirnov test statistics?
- apparently incorrect p-values from 2-sided Kolmogorov-Smirnov (PR#14158)
- apparently incorrect p-values from 2-sided Kolmogorov-Smirnov (PR#14157)
- apparently incorrect p-values from 2-sided Kolmogorov-Smirnov (PR#14178)
- Kolmogorov-Smirnov: calculate p value given as input the test statistic