“…resultList = checkfunc(1000, 20, i) finalp1 = finalp1 + resultList[1] finalp1_z = finalp1_z + resultList[2] finalp2 = finalp2 + resultList[3] finalp2_z = finalp2_z + resultList[4] finalp3 = finalp3 + resultList[5] finalp3_z = finalp3_z + resultList[6] } print(finalp1/500) print(finalp1_z/500) print(finalp2/500) print(finalp2_z/500) print(finalp3/500) print(finalp3_z/500)# S2myfunc <-function(n, seed) { design <-swDsn(clusters=c(5,5,5,5), extra.time=0, all.ctl.time0=TRUE) # first generate the original dataset with a time effect and 0 treatment effect, # rho is the correlation between slope and intercept swGenData.nScalar <-swSim(design,family=gaussian(link="identity"), n=10, mu0=3, mu1=3, time.effect=c(0,.2,.3,.4,.5), sigma=1, tau=2, eta=2, rho=0, seed = seed, retTimeOnTx=FALSE) data = swSummary(response.var, tx.var, time.var, cluster.var, swGenData.nScalar, type="mean", digits=3)$swDsn newdata = NULL listn=c(1:n) x = sample(listn) newdata=data[x,] return(newdata) } checkfunc = function(numberOfPermutation, nCluster, seed) { design <-swDsn(clusters=c(5,5,5,5), extra.time=0, all.ctl.time0=TRUE) # first generate the original dataset with a time effect and 0 treatment effect, # rho is the correlation between slope and intercept swdata <-swSim(design,family=gaussian(link="identity"), n=10, mu0=3, mu1=3, time.effect=c(0,.2,.3,.4,.5), sigma=1, tau=2, eta=2, rho=0, seed = seed, retTimeOnTx=FALSE) (nCluster, seed) mod1 <-gee(response.var~tx.var+as.factor(time.var), data = swdata, family = "gaussian",id = cluster.var, corstr = "independence") result1 = mod1$coefficients[[2]][1] zscore1 = summary(mod1)$coefficients[2,5] mod2 <-gee(response.var~tx.var+as.factor(time.var), data = swdata, family = "gaussian",id = cluster.var, corstr = "exchangeable") result2 = mod2$coefficients[[2]][1] zscore2 = summary(mod2)$coefficients[2,5] mod3 <-gee(response.var~tx.var, data = swdata, family = "gaussian",id = cluster.var, corstr = "independence") result3 = mod3$coefficients[[2]][1] zscore3 = summary(mod3)$coefficients[2,5] dataPerm = swdata # copy the original dataset result1_1 nCluster) x = sample(listn) newdata = matrix[x,] for(a in 1:nrow(newdata)) { for(b in 1:ncol(newdata)){ if(newdata[a,b]==0) { newtx = append(newtx, rep(0,10)) } else{ newtx = append(newtx, rep(1,10)) } } } dataPerm$tx.var = as.vector(t(newtx))mod1_1 <-gee(response.var~tx.var+as.factor(time.var), data = dataPerm, family = "gaussian",id = cluster.var, corstr = "independence")result1_1[i] = mod1_1$coefficients[[2]][1] zscore1_1[i] = summary(mod1_1)$coefficients[2,5]mod2_1 <-gee(response.var~tx.var+as.factor(time.var), data = dataPerm, family = "gaussian",id = cluster.var, corstr = "exchangeable")result2_1[i] = mod2_1$coefficients[[2]][1] zscore2_1[i] = summary(mod2_1)$coefficients[2,5]mod3_1 <-gee(response.var~tx.var, data = dataPerm, family = "gaussian",id = cluster.var, corstr = "independence")result3_1[i] = mod3_1$coefficients[[2]][1] zscore3_1[i] = summary(mod3_1)$coefficients[2,5] } sort1 = sort(result1_1) sort2 = sort(result2_1) sort3 = sort(result3_1) sortz1 = sort(zscore1_1) sortz2 = sort(zscore2_1) sortz3 = sort(zscore3_1) # z score if((zscore1< sortz1[25]) | (zscore1> sortz1[975])) { storep1_z = 1} else {storep1_z = 0} if((zscore2< sortz2[25]) | (zscore2> sortz2[975])) { storep2_z = 1} ...…”