#setwd(choose.dir()) ## set working directory where "Sx simulate unbalancedxx.r" can be found code01=TRUE #please choose docentralize=TRUE #please choose filename=ifelse(code01,"S3 simulate unbalanced01.r", #generate data with 0, 1 coding "S4 simulate unbalanced-11.r" ) #generate data with -1, 1 coding source(filename) source("S2 multichoose.r") #all possible combinations for 2x2 with 12 subjects, each cell >= 2 set.seed(1) # 1. No interaction eff=list(intercept=10, effectA=4, effectB=4, effectAB=0, #moderate interaction error=10) m3=createUnbalancedMatrix12(10) res=matrix(NA,nrow=nrow(m3), ncol=10) # Start the clock! ptm <- proc.time() for (i in 1:nrow(m3)){ des=list(c00=m3[i,]$"00",c10=m3[i,]$"10",c01=m3[i,]$"01",c11=m3[i,]$"11") rt=simulate_unbalanced2x2(des,eff, coding="contrast", centralize=docentralize) res[i,] = round(colMeans(rt), 3) cat(i,'.') } # Stop the clock round((proc.time() - ptm)/60, 2) m4=cbind(m3,rep(eff$effectAB, nrow(res)), res) colnames(m4)<- c(colnames(m3), "I", colnames(rt)) # 2. low interaction eff=list(intercept=10, effectA=4, effectB=4, effectAB=4, error=10) m3=createUnbalancedMatrix12(10) res=matrix(NA,nrow=nrow(m3), ncol=10) # Start the clock! ptm <- proc.time() for (i in 1:nrow(m3)){ des=list(c00=m3[i,]$"00",c10=m3[i,]$"10",c01=m3[i,]$"01",c11=m3[i,]$"11") rt=simulate_unbalanced2x2(des,eff, coding="contrast", centralize=docentralize) res[i,] = round(colMeans(rt), 3) cat(i,'.') } # Stop the clock round((proc.time() - ptm)/60, 2) m5=cbind(m3,rep(eff$effectAB, nrow(res)), res) colnames(m5)<- c(colnames(m3), "I", colnames(rt)) # 3. moderate interaction with contrast coding eff=list(intercept=10, effectA=4, effectB=4, effectAB=8, error=10) m3=createUnbalancedMatrix12(10) res=matrix(NA,nrow=nrow(m3), ncol=10) # Start the clock! ptm <- proc.time() for (i in 1:nrow(m3)){ des=list(c00=m3[i,]$"00",c10=m3[i,]$"10",c01=m3[i,]$"01",c11=m3[i,]$"11") rt=simulate_unbalanced2x2(des,eff, coding="contrast", centralize=docentralize) res[i,] = round(colMeans(rt), 3) cat(i,'.') } # Stop the clock round((proc.time() - ptm)/60, 2) m6=cbind(m3,rep(eff$effectAB, nrow(res)), res) colnames(m6)<- c(colnames(m3), "I", colnames(rt)) simdata=as.data.frame(rbind(m4,m5,m6)) filename = ifelse(!docentralize, ifelse(code01,"S6 simdata01.txt" , "S7 simdata-11.txt") , ifelse(code01,"S8 simdata01c.txt" , "S9 simdata-11c.txt")) write.table(simdata, file=filename )