[R] permutational Kolmogorov-Smirnov p-value for paired data

Greg Snow greg.snow at ihc.com
Tue Oct 11 20:46:30 CEST 2005


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




More information about the R-help mailing list