(This article was first published on [R] tricks, and kindly contributed to R-bloggers)
WelshPerm <- function(response,variable,nperm=999,...){
base <- oneway.test(response~variable,...)
base.p <- base$p.value
base.W <- base$statistic
count <- 1
# Permutation loop
for(i in 1:nperm){
SAMPLE <- sample(response)
welsh.perm<-oneway.test(SAMPLE~variable,...)
welsh.perm.p<-welsh.perm$p.value
welsh.perm.W<-welsh.perm$statistic if(abs(welsh.perm.W) >= abs(base.W)) {count <- count+1}
}
result=count/(nperm+1)
return(result)
}
To leave a comment for the author, please follow the link and comment on his blog: [R] tricks.
R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series,ecdf, trading) and more...

Zero Inflated Models and Generalized Linear Mixed Models with R.
Zuur, Saveliev, Ieno (2012).