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

From: Greg Snow <greg.snow_at_ihc.com>
Date: Wed 12 Oct 2005 - 04:46:30 EST


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@ihc.com
(801) 408-8111

>>> John Chen <jwcasl@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@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

R-help@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 Received on Wed Oct 12 05:04:09 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 18:41:12 EST