library(mirt) pcm_analysis <- function(df=NULL,treatment='TT',irtmodel='PCM2',method='MML') { 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') { tam1 <- tam.mml(resp=resp,Y=df[,treatment],irtmodel = irtmodel,est.variance = T,verbose=F) } if (method=='JML') { tam1 <- tam.jml(resp=resp,group=1+df[,treatment]) } if (method!='MML' & method!='JML') { stop('Invalid method. Please choose among MML or JML') } return(tam1) } dff <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_5A_50.csv') dfff <- dff[dff$replication==1,] facets <- dfff$TT dfff$item2_noTT <- NA dfff$item2_TT <- NA dfff[dfff$TT==0,]$item2_noTT <- dfff[dfff$TT==0,"item2"] dfff[dfff$TT==1,]$item2_TT <- dfff[dfff$TT==1,"item2"] mml.mod <- tam.mml(resp=dfff[,c('item1','item2_noTT','item2_TT',"item3","item4")],Y=dfff$TT,constraint='cases' ,irtmodel = "PCM2",est.variance = T,verbose=F)