Re: [R] Power curve for a wilcoxon test

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

Louisa Hay <louisahay <at>> 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.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) mailing list PLEASE do read the posting guide 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 Please read the posting guide before posting to the list.

list of date sections of archive