# NOT RUN {
x<-data.frame(y=1:100,z=rnorm(100),group=c(rep(1,50),rep(2,50)))
stat<-function(x){ cor(x[,1],x[,2]) }
### nonparametric bootstrap test on correlation between y and z
### low p-value means that such a large correlation unlikely due to chance
resamp<-function(x){ n<-dim(x)[[1]] ; x[sample(1:n,replace=TRUE),] }
out<-MCtest(x,stat,resamp,extreme="geq")
out$p.value
out$p.value.ci
### permutation test, permuting y only within group
resamp<-function(x){
ug<-unique(x[,"group"])
y<- x[,"y"]
for (i in 1:length(ug)){
pick.strata<- x[,"group"]==ug[i]
y[pick.strata]<-sample(y[pick.strata],replace=FALSE)
}
x[,1]<-y
x
}
out<-MCtest.fixed(x,stat,resamp,N=199)
out$p.value
out$p.value.ci
# }
Run the code above in your browser using DataLab