(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 their blog: [R] tricks.
R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...