Re: [R] Power curve for a wilcoxon test

From: Ben Bolker <bolker_at_ufl.edu>
Date: Mon, 14 Apr 2008 13:15:38 +0000 (UTC)

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_at_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. Received on Mon 14 Apr 2008 - 13:20:18 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 14 Apr 2008 - 14:30:28 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive