returndat$se.beta <- 1.413612*sapply(seq(1,max(df[,sequence])),function(k) tam.se(tam1[[k]])$beta$se.Dim1[2] ) returndat$low.ci.beta <- returndat$beta-1.96*returndat$se.beta returndat$high.ci.beta <- returndat$beta+1.96*returndat$se.beta returndat$true.value.in.ci <- 1*(truebeta>returndat$low.ci.beta & truebetareturndat$low.ci.beta & 0returndat$low.ci.beta & truebetareturndat$low.ci.beta & 0returndat$low.ci.beta & truebetareturndat$low.ci.beta & 0returndat$low.ci.beta & truebetareturndat$low.ci.beta & 0returndat$low.ci.beta & truebetareturndat$low.ci.beta & 0returndat$low.ci.beta & truebetareturndat$low.ci.beta & 0returndat$low.ci.beta & truebetareturndat$low.ci.beta & 0returndat$low.ci.beta & truebetareturndat$high.ci.beta) if (truebeta==0) { returndat$beta.same.sign.truebeta <- NA } else { returndat$beta.same.sign.truebeta <- 1*(sign(truebeta)==sign(returndat$beta)) } returndat2 <- data.frame(J=rep(nbitems,max(df[,sequence])), M=1+max(df$item1), N=nrow(df[df$replication==1,])/2, eff.size=eff.size, dif.size= difsize, nb.dif= nbdif ) returndat <- cbind(returndat2,returndat) return(returndat) } replicate_pcm_analysis_m2 <- function(df=NULL,treatment='TT',irtmodel='PCM2',method='MML',sequence='replication',truebeta=0,eff.size=0,difsize=NA,nbdif=0) { nbitems <- sum(sapply(1:20,function(x) paste0('item',x)) %in% colnames(df)) resp <- df[,sapply(seq(1,nbitems),function(x) paste0('item',x))] if (method=='MML') { n <- max(df[,sequence]) print(n) tam1 <- pbmclapply(seq(1,n), function(x) pcm_analysis(df=df[df[,sequence]==x,],treatment=treatment,irtmodel=irtmodel) ) } listitems <- sapply(seq(1,nbitems),function(x) paste0('item',x)) returndat <- data.frame(matrix(nrow=max(df[,sequence]),ncol=length(listitems))) colnames(returndat) <- listitems for (s in seq(1,max(df[,sequence]))) { for (k in seq(1,nbitems)) { returndat[s,paste0('item',k)] <- tam1[[s]]$xsi$xsi[k] } } returndat$beta <- sapply(seq(1,max(df[,sequence])),function(k) tam1[[k]]$beta[2]) returndat$se.beta <- 1.413612*sapply(seq(1,max(df[,sequence])),function(k) tam.se(tam1[[k]])$beta$se.Dim1[2] ) returndat$low.ci.beta <- returndat$beta-1.96*returndat$se.beta returndat$high.ci.beta <- returndat$beta+1.96*returndat$se.beta returndat$true.value.in.ci <- 1*(truebeta>returndat$low.ci.beta & truebetareturndat$high.ci.beta) if (truebeta==0) { returndat$beta.same.sign.truebeta <- NA } else { returndat$beta.same.sign.truebeta <- 1*(sign(truebeta)==sign(returndat$beta)) } returndat2 <- data.frame(J=rep(nbitems,max(df[,sequence])), M=1+max(df$item1), N=nrow(df[df$replication==1,])/2, eff.size=eff.size, dif.size= difsize, nb.dif= nbdif ) returndat <- cbind(returndat2,returndat) return(returndat) } ####################################### ## SCENARIO ANALYSIS ####################################### registerDoMC(4) replicate_pcm_analysis_m4(dat1[dat1$replication==1,]) dat1 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N100/scenario_4A_100.csv') replicate_pcm_analysis_m4(dat1[dat1$replication==1,])