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) ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.