[R] Power curve for a wilcoxon test
Ben Bolker
bolker at ufl.edu
Mon Apr 14 15:15:38 CEST 2008
Louisa Hay <louisahay <at> msn.com> writes:
>
>
> Hi,
> I am trying to write R code to produce a power curve to show
> how the power of a
> Wilcoxon-test varies depending on the mean, with data
> generated from a uniform
> distribution. Any ideas
> how I should go about this?Louisa
Here's a brute-force approach that
seems to work reasonably well. Adapt to
suit yourself ...
wilcox.pval <- function(m2,m1=0,n=20) {
x1 <- runif(n,m1-0.5,m1+0.5)
x2 <- runif(n,m2-0.5,m2+0.5)
wilcox.test(x1,x2)$p.value
}
wilcox.pow <- function(m2,m1=0,n=20, alpha=0.05, N=500) {
pvals <- replicate(N,wilcox.pval(m2,m1,n))
sum(pvals<alpha)/N
}
mvec <- seq(0,0.5,by=0.05)
powvec <- sapply(mvec,wilcox.pow)
plot(mvec,powvec)
More information about the R-help
mailing list