# Randomly selects two stations and estimates power and effsize. 100 independent draws rm(list=ls()) library(compute.es) f0= read.table("R & rt Prev & CI.txt", header=T) pow= numeric(4); a1=numeric(4); size= numeric(4); diff=numeric(4); poder=numeric(4); efsize=numeric(4) f3= data.frame(size, diff, poder, efsize) lb= c("10x1", "10x2", "25x2", "50x2") for (j in 1:100) { for (i in seq_along(lb)) { # select two samples per each belt-transect dimension t1= f0[f0$size %in% lb[i],] t2= t1[sample(nrow(t1),2),] size[i]= lb[i] diff[i]= abs(t2[1,3] - t2[2,3]) # Difference in colony abundance pp= power.prop.test(n = t2[1,3] + t2[2,3], p1 = t2[1,4], p2 = t2[2,4]) #achieved power pow[i]= round(pp$power,2) a= propes(p1= t2[1,4], p2= t2[2,4], 100, 100, verbose= F) a1[i]= round(abs(a$cliffs.d),2)# effect size } f2= data.frame(size= unlist(size), diff= unlist(diff), poder= unlist(pow), efsize= unlist(a1)) f3= rbind(f3, f2) } f3= f3[-c(1:4),] write.table(f3, "power & efsize DATA.txt", quote=F, sep=" ", row.names=F)