Example of Permutation test

# Permutation test for the 2 groups—NVLA total –1st year of research
no.int<- c(21.00,23.00,22.00,21.00,31.00,29.00,23.00,42.00,32.00,-4.00,6.00,26.00)
int<- c(19.00,39.00,19.00,40.00,53.00,47.00,67.00,80,8.00,11.00,16.00)
n1<-length(no.int)
n2<-length(int)
data=c(no.int, int)
N=100000
counter=0
diff=mean(no.int)-mean(int)
diff
diff2=diff^2
stat=numeric(N)
stat2=numeric(N)
for (i in 1:N) {
  no.intB=sample(data,n1,replace=T)
  intB=sample(data,n2,replace=T)
  stat[i]=mean(no.intB)-mean(intB)
  stat2[i]=stat[i]^2
  if (stat2[i]>diff2) counter=counter+1}
pvalue=counter/N
pvalue
quantile (stat,probs=c(.05,.95))