diff --git a/RProject/.RData b/RProject/.RData index 2bf4797..fca6731 100644 Binary files a/RProject/.RData and b/RProject/.RData differ diff --git a/RProject/.Rhistory b/RProject/.Rhistory index 5f66ad1..d6992b7 100644 --- a/RProject/.Rhistory +++ b/RProject/.Rhistory @@ -1,201 +1,3 @@ -stop("Models RSM and GRSM cannot be used for unequal numbers of response categories!") -} -design_list <- design_GPCMlasso(formula = formula, data = data, -Y = Y, RSM = RSM, GPCM = GPCM, DSF = DSF, all.dummies = control$all.dummies, -main.effects = main.effects) -if (design_list$m == 0) { -control$lambda <- 0 -control$adaptive <- FALSE -cv <- FALSE -} -if (length(control$lambda) == 1) { -cv <- FALSE -} -loglik_fun <- loglikPCMlasso -score_fun <- scorePCMlasso -log_score_fun <- loglikscorePCMlasso2 -if (all(k == 2)) { -loglik_fun <- loglikDIFlasso -score_fun <- scoreDIFlasso -log_score_fun <- loglikscoreDIFlasso2 -} -fit <- fit_GPCMlasso(model = model, loglik_fun = loglik_fun, acoefs2 = acoefs2, -score_fun = score_fun, log_score_fun, design_list = design_list, -control = control, start = NULL, scale_fac = 1, main.effects = main.effects) -if (is.null(control$lambda)) { -control$lambda <- fit$lambda -} -coefficients <- fit$coefficients -coef.rescal <- fit$coef.rescal -logLik <- fit$logLik -df <- fit$df -BIC <- -2 * logLik + log(design_list$n) * df -AIC <- -2 * logLik + 2 * df -cAIC <- -2 * logLik + 2 * df + 2 * df * (df - 1)/(design_list$n - -df - 1) -if (cv) { -cv_error <- fit_cv_GPCMlasso(model, design_list, control, -score_fun, loglik_fun, log_score_fun, Y) -} -else { -cv_error <- NULL -} -ret.list <- list(coefficients = coefficients, logLik = logLik, -cv_error = cv_error, call = match.call(), model = model, -data = data, control = control, DSF = DSF, formula = formula, -item.names = item.names, Y = Y, design_list = design_list, -AIC = AIC, BIC = BIC, cAIC = cAIC, df = df, coef.rescal = coef.rescal, -main.effects = main.effects) -class(ret.list) <- "GPCMlasso" -return(ret.list) -} -GPCMlasso2 <- function (formula, data, DSF = FALSE, model = c("PCM", "RSM", -"GPCM", "GRSM", "RM", "2PL"), control = ctrl_GPCMlasso(), -cv = FALSE, main.effects = TRUE,acoefs2=NULL) -{ -if (!is.data.frame(data)) -stop("data has to be a data.frame!") -Y <- model.response(model.frame(formula, data = data)) -for (i in 1:ncol(Y)) { -Y[, i] <- as.factor(Y[, i]) -} -item.names <- colnames(Y) -model <- match.arg(model) -RSM <- GPCM <- FALSE -if (model %in% c("GRSM", "RSM")) { -RSM <- TRUE -} -if (model %in% c("GRSM", "GPCM", "2PL")) { -GPCM <- TRUE -} -k <- apply(Y, 2, function(x) { -length(levels(as.factor(x))) -}) -if (all(k == 2) | model %in% c("RM", "2PL")) { -DSF <- FALSE -control$cv.crit <- "deviance" -} -if (length(unique(k)) > 1 & RSM) { -stop("Models RSM and GRSM cannot be used for unequal numbers of response categories!") -} -design_list <- design_GPCMlasso(formula = formula, data = data, -Y = Y, RSM = RSM, GPCM = GPCM, DSF = DSF, all.dummies = control$all.dummies, -main.effects = main.effects) -if (design_list$m == 0) { -control$lambda <- 0 -control$adaptive <- FALSE -cv <- FALSE -} -if (length(control$lambda) == 1) { -cv <- FALSE -} -loglik_fun <- loglikPCMlasso -score_fun <- scorePCMlasso -log_score_fun <- loglikscorePCMlasso2 -if (all(k == 2)) { -loglik_fun <- loglikDIFlasso -score_fun <- scoreDIFlasso -log_score_fun <- loglikscoreDIFlasso2 -} -fit <- fit_GPCMlasso(model = model, loglik_fun = loglik_fun, acoefs2 = acoefs2, -score_fun = score_fun, log_score_fun, design_list = design_list, -control = control, start = NULL, scale_fac = 1, main.effects = main.effects) -if (is.null(control$lambda)) { -control$lambda <- fit$lambda -} -coefficients <- fit$coefficients -coef.rescal <- fit$coef.rescal -logLik <- fit$logLik -df <- fit$df -BIC <- -2 * logLik + log(design_list$n) * df -AIC <- -2 * logLik + 2 * df -cAIC <- -2 * logLik + 2 * df + 2 * df * (df - 1)/(design_list$n - -df - 1) -if (cv) { -cv_error <- fit_cv_GPCMlasso(model, design_list, control, -score_fun, loglik_fun, log_score_fun, Y) -} -else { -cv_error <- NULL -} -ret.list <- list(coefficients = coefficients, logLik = logLik, -cv_error = cv_error, call = match.call(), model = model, -data = data, control = control, DSF = DSF, formula = formula, -item.names = item.names, Y = Y, design_list = design_list, -AIC = AIC, BIC = BIC, cAIC = cAIC, df = df, coef.rescal = coef.rescal, -main.effects = main.effects) -class(ret.list) <- "GPCMlasso" -return(ret.list) -} -GPCMlasso2(formula = cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control=ctrl_GPCMlasso(lambda=0.0000000000001),acoefs2 = u) -u -## create responses for acat from ordinal values -createResponse <- function(Y){ -Y <- as.factor(Y) -model.matrix(~0+Y)[,-length(levels(Y))] -} -design_GPCMlasso <- function(formula = formula, Y=Y, data = data, RSM = RSM, -GPCM = GPCM, DSF = DSF, all.dummies = TRUE, main.effects = main.effects){ -## extract covariates -if(all.dummies){ -term.labels <- attr(terms(formula), "term.labels") -X <- matrix(rep(1,nrow(data))) -for(ij in 1:length(term.labels)){ -x.now <- data[,term.labels[ij], drop = FALSE] -if(is.factor(x.now[,1])){ -if(nlevels(x.now[,1])==2){ -X <- cbind(X,model.matrix(~.,data=x.now)[,-1,drop=FALSE]) -}else{ -X <- cbind(X,model.matrix(~0+.,data=x.now)) -} -}else{ -X <- cbind(X,model.matrix(~.,data=x.now)[,-1,drop=FALSE]) -} -} -X <- X[,-1,drop = FALSE] -}else{ -X <- model.matrix(formula, data = data) -if(ncol(X)>=1){ -if(colnames(X)[1]=="(Intercept)"){ -X <- X[,-1,drop = FALSE] -} -} -} -x.names <- colnames(X) -## factorize response vector -## initialize basic parameters -k <- apply(Y, 2, function(x){length(levels(as.factor(x)))}) -q <- k-1 -n <- nrow(Y) -I <- ncol(Y) -m <- ncol(X) -n_sigma <- 1 -if(GPCM){ -n_sigma <- I -} -## get final response vector -if(all(q==1)){ -response <- as.numeric(as.factor(c(t(Y))))-1 -}else{ -response <- lapply(as.data.frame(Y),createResponse) -response <- c(t(do.call("cbind",response))) -} -## total number of parameters to be optimized -px <- sum(q)+n_sigma -if(RSM){ -px <- q[1]+I+n_sigma-1 -} -## scale X and save standard deviations for re-scaling -# X <- scale(X, center = FALSE) -X <- scale(X, center = FALSE, scale = apply(X, 2, sd, na.rm = TRUE)) -sd.vec <- attributes(X)$scale -sd.vec <- create.sd.vec(sd.vec, DSF, px, n_sigma, I, q, main.effects) -## create design matrix for basic item parameters -if(!RSM){ -design <- -diag(px-n_sigma) -}else{ -design <- -cbind(matrix(rep(diag(I),each=q[1]),ncol=I), -matrix(rep(diag(q[1]),I),ncol=q[1],byrow = TRUE))[,-(I+1)] } ## create design matrix for covariate part if(m>=1){ @@ -510,3 +312,201 @@ GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT:item1tt+TT:item2TT+TT:item3t GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT:item1tt+TT:item2tt+TT:item3tt+TT:item4tt,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0),DSF = F,cv=F) GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT*item1tt,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0),DSF = F,cv=F) GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT*item1tt+TT*item2tt+TT*item3tt+TT*item4tt,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0),DSF = F,cv=F) +library(mirt) +model.pcm <- "hrqol = 1-4" +mirt(data = aaaa[,paste0("item",1:4)]) +mirt(data = aaaa[,paste0("item",1:4)],model=model.pcm,itemtype = "Rasch",SE=T) +coef(mirt(data = aaaa[,paste0("item",1:4)],model=model.pcm,itemtype = "Rasch",SE=T)) +coef(mirt(data = aaaa[,paste0("item",1:4)],model=model.pcm,itemtype = "PCM",SE=T)) +coef(mirt(data = aaaa[,paste0("item",1:4)],model=model.pcm,itemtype = "GPCM",SE=T)) +coef(mirt(data = aaaa[,paste0("item",1:4)],model=model.pcm,itemtype = "Rasch",SE=T)) +coef.pcm <- coef(mirt(data = aaaa[,paste0("item",1:4)],model=model.pcm,itemtype = "Rasch",SE=T),IRTpars=T,simplify=T) +coef.pcm +coef.pcm <- coef(multipleGroup(data = aaaa[,paste0("item",1:4)],group="TT",model=model.pcm,itemtype = "Rasch",SE=T),IRTpars=T,simplify=T) +multipleGroup(data = aaaa[,paste0("item",1:4)],group="TT",model=model.pcm,itemtype = "Rasch",SE=T) +coef.pcm <- coef(multipleGroup(data = aaaa[,paste0("item",1:4)],group=aaaa$TT,model=model.pcm,itemtype = "Rasch",SE=T),IRTpars=T,simplify=T) +coef.pcm <- coef(multipleGroup(data = aaaa[,paste0("item",1:4)],group=as.character(aaaa$TT),model=model.pcm,itemtype = "Rasch",SE=T),IRTpars=T,simplify=T) +coef.pcm +library(TAM) +tam.mml(resp=aaaa[,c("item1","item2","item3","item4")],group=aaaa$TT) +coef.pcm +coef.pcm <- coef(mirt(data = aaaa[,paste0("item",1:4)],covdata=aaaa$TT,formula=hrqol~TT,model=model.pcm,itemtype = "Rasch",SE=T),IRTpars=T,simplify=T) +coef.pcm <- coef(mirt(data = aaaa[,paste0("item",1:4)],covdata=aaaa,formula=hrqol~TT,model=model.pcm,itemtype = "Rasch",SE=T),IRTpars=T,simplify=T) +coef.pcm <- coef(mirt(data = aaaa[,paste0("item",1:4)],covdata=aaaa,formula=c(hrqol=as.formula("~TT")),model=model.pcm,itemtype = "Rasch",SE=T),IRTpars=T,simplify=T) +coef.pcm <- coef(mirt(data = aaaa[,paste0("item",1:4)],covdata=aaaa,formula=c(hrqol=as.formula("~TT")),model=model.pcm,itemtype = "Rasch",SE=T)) +mirt(data = aaaa[,paste0("item",1:4)],covdata=aaaa,formula=c(hrqol=as.formula("~TT")),model=model.pcm,itemtype = "Rasch",SE=T) +mirt(data = aaaa[,paste0("item",1:4)],covdata=aaaa,formula=~TT,model=model.pcm,itemtype = "Rasch",SE=T) +mirt(data = aaaa[,paste0("item",1:4)],covdata=aaaa,formula=~TT,model=model.pcm,itemtype = "Rasch") +coef(mirt(data = aaaa[,paste0("item",1:4)],covdata=aaaa,formula=~TT,model=model.pcm,itemtype = "Rasch")) +tam.mml(resp=aaaa[,c("item1","item2","item3","item4")],group=aaaa$TT) +mirt(data = aaaa[,paste0("item",1:4)],covdata=aaaa,formula=~TT,model=model.pcm,itemtype = "Rasch") +aaa <- read.csv(paste0('/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N',100,'/scenario_',"6A_100",'.csv')) +aaaa <- aaa[aaa$replication==1,] +tam.mml(resp=aaaa[,c("item1","item2","item3","item4")],group=aaaa$TT) +mirt(data = aaaa[,paste0("item",1:4)],covdata=aaaa,formula=~TT,model=model.pcm,itemtype = "GPCM") +mirt(data = aaaa[,paste0("item",1:4)],covdata=aaaa,formula=~TT,model=model.pcm,itemtype = "Rasch") +coef(mirt(data = aaaa[,paste0("item",1:4)],covdata=aaaa,formula=~TT,model=model.pcm,itemtype = "Rasch")) +coef(mirt(data = aaaa[,paste0("item",1:4)],covdata=aaaa,formula=~TT,model=model.pcm,itemtype = "Rasch"),simplify=T) +coef(tam.mml(resp=aaaa[,c("item1","item2","item3","item4")],group=aaaa$TT)) +coef(mirt(data = aaaa[,paste0("item",1:4)],covdata=aaaa,formula=~TT,model=model.pcm,itemtype = "Rasch"),simplify=T) +model.pcm <- "hrqol = 1*TT+2-4" +coef(mirt(data = aaaa[,paste0("item",1:4)],covdata=aaaa,formula=~TT,model=model.pcm,itemtype = "Rasch"),simplify=T) +model.pcm <- "hrqol = 1-4" +coef(mirt(data = aaaa[,paste0("item",1:4)],covdata=aaaa,formula=~TT,model=model.pcm,itemtype = "Rasch"),simplify=T) +coef(mirt(data = aaaa[,paste0("item",1:4)],covdata=aaaa,formula=~TT+TT:item1,model=model.pcm,itemtype = "Rasch"),simplify=T) +aaaa$dif1 +coef(mirt(data = aaaa[,paste0("item",1:4)],covdata=aaaa,formula=~TT+TT:item4,model=model.pcm,itemtype = "Rasch"),simplify=T) +tam.mml(resp=aaaa[,c("item1","item2","item3","item4")],group=aaaa$TT) +aaaa[aaaa$TT==1,]$item4TT <- aaaa[aaaa$TT==1,]$item4 +aaaa +aaaa[aaaa$TT==1,]$item4TT <- aaaa[aaaa$TT==1,]$item4 +aaaa[aaaa$TT==1,]$item4 +aaaa +aaaa[aaaa$TT==1,]$item4TT <- 0 +aaaa[aaaa$TT==1,]$item4TT +aaaa[aaaa$TT==1,] +aaaa[aaaa$TT==1,"item4tt"] <- aaaa[aaaa$TT==1,"item4"] +aaaa +aaaa[aaaa$TT==0,"item4nott"] <- aaaa[aaaa$TT==0,"item4"] +tam.mml(resp=aaaa[,c("item1","item2","item3","item4tt","item4nott")],group=aaaa$TT) +Summary(tam.mml(resp=aaaa[,c("item1","item2","item3","item4tt","item4nott")],group=aaaa$TT)) +summary(tam.mml(resp=aaaa[,c("item1","item2","item3","item4tt","item4nott")],group=aaaa$TT)) +coef(mirt(data = aaaa[,paste0("item",1:4)],covdata=aaaa,formula=~TT+TT:item4,model=model.pcm,itemtype = "Rasch"),simplify=T,IRTpars=T) +coef(mirt(data = aaaa[,paste0("item",1:4)],covdata=aaaa,formula=~TT+TT:item4,model=model.pcm,itemtype = "Rasch"),simplify=T,IRTpars=T) +aaaa +coef(mirt(data = aaaa[,paste0("item",1:4)],covdata=aaaa[,1:9],formula=~TT+TT:item4,model=model.pcm,itemtype = "Rasch"),simplify=T,IRTpars=T) +summary(tam.mml(resp=aaaa[,c("item1","item2","item3","item4tt","item4nott")],group=aaaa$TT)) +coef(mirt(data = aaaa[,paste0("item",1:4)],covdata=aaaa[,1:9],formula=~TT+TT:item4,model=model.pcm,itemtype = "Rasch"),simplify=T,IRTpars=T) +coef(mirt(data = aaaa[,paste0("item",1:4)],covdata=aaaa[,1:9],formula=~TT+TT*item4,model=model.pcm,itemtype = "Rasch"),simplify=T,IRTpars=T) +coef(mirt(data = aaaa[,paste0("item",1:4)],covdata=aaaa[,1:9],formula=~TT+TT:item4,model=model.pcm,itemtype = "Rasch"),simplify=T,IRTpars=T) +coef(mirt(data = aaaa[,paste0("item",1:4)],covdata=aaaa[,1:9],formula=~TT,model=model.pcm,itemtype = "Rasch"),simplify=T,IRTpars=T) +model.pcm <- "hrqol = 1-4" +multipleGroup(data = aaaa[,paste0("item",1:4)],group=as.character(aaaa$TT),model=model.pcm,itemtype = "Rasch") +zzz <- multipleGroup(data = aaaa[,paste0("item",1:4)],group=as.character(aaaa$TT),model=model.pcm,itemtype = "Rasch") +DIF(zzz,items2test = 4,groups2test = "TT") +DIF(zzz,items2test = 4,groups2test = "TT",which.par = c("a1","d")) +DIF(zzz,items2test = 4,groups2test = "TT",which.par = c("hrqol")) +DIF(zzz,items2test = 4,groups2test = "TT",which.par = c("item1")) +zzz +coef(zzz) +DIF(zzz,items2test = 4,groups2test = "TT",which.par = c("a1")) +DIF(zzz,items2test = 4,which.par = c("a1")) +DIF(zzz,items2test = 4,which.par = c("a1"),return_models = T) +DIF(zzz,items2test = 4,which.par = c("a1"),return_models = T) +DIF(zzz,items2test = 4,which.par = c("a1"),return_models = F) +zzzz<- DIF(zzz,items2test = 4,which.par = c("a1")) +zzzz<- DIF(zzz,items2test = 4,which.par = c("a1"),return_seq_model = T) +zzzz<- DIF(zzz,items2test = 4,which.par = c("g"),return_seq_model = T) +coef(zzz) +zzzz<- DIF(zzz,items2test = 4,which.par = c("d1","d2","d3"),return_model = T) +zzzz<- DIF(zzz,items2test = 4,which.par = c("d1","d2","d3")) +zzzz +install.packages('/home/corentin/Documents/These/Packages/GPCMlasso_0.1-7.tar.gz') +library(GPCMlasso) +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0),DSF = F,cv=F) +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 1000),DSF = F,cv=F) +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 1000000000),DSF = F,cv=F) +tam.mml(aaaa[,c("item1","item2","item3",'item4')],group=aaaa$TT) +library(TAM) +tam.mml(aaaa[,c("item1","item2","item3",'item4')],group=aaaa$TT) +coef(tam.mml(aaaa[,c("item1","item2","item3",'item4')],group=aaaa$TT)) +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0.1),DSF = F,cv=F) +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0),DSF = F,cv=F) +?GPCMlasso +?GPCMlasso +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0),DSF = F,cv=F,main.effects = F) +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 1000),DSF = F,cv=F,main.effects = F) +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0),DSF = F,cv=F) +GPCMlasso(formula=cbind(item1,item2,item3,item4,item4tt)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0),DSF = F,cv=F) +aaaa[aaaa$TT==1,"item4tt"] <- aaaa[aaaa$TT==1,"item4"] +GPCMlasso(formula=cbind(item1,item2,item3,item4,item4tt)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0),DSF = F,cv=F) +GPCMlasso(formula=cbind(item1,item2,item3,item4,item4tt)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0),DSF = F,cv=F) +GPCMlasso(formula=cbind(item1,item2,item3,item4tt)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0),DSF = F,cv=F) +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0),DSF = F,cv=F) +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 10),DSF = F,cv=F) +0.265*log(10) +0.265*log(100) +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 1000),DSF = F,cv=F) +0.265/1/log(100) +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 1000),DSF = F,cv=F)$coef.rescal +tam.mml(aaaa[,c("item1","item2","item3",'item4')],group=aaaa$TT) +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 1000),DSF = F,cv=F) +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 100000000000),DSF = F,cv=F) +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0),DSF = F,cv=F) +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0),DSF = F,cv=F)$coef.rescal +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0),DSF = F,cv=F)$coefficients +install.packages("/home/corentin/Documents/These/Packages/GPCMlasso_0.1-7.tar.gz") +library(GPCMlasso) +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0),DSF = F,cv=F) +tam.mml(aaaa[,c("item1","item2","item3",'item4')],group=aaaa$TT) +library(TAM) +tam.mml(aaaa[,c("item1","item2","item3",'item4')],group=aaaa$TT) +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0),DSF = F,cv=F) +tam.mml(aaaa[,c("item1","item2","item3",'item4')]) +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0,lambda2=0),DSF = F,cv=F) +install.packages("/home/corentin/Documents/These/Packages/GPCMlasso_0.1-7.tar.gz") +library(GPCMlasso) +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0,lambda2=0),DSF = F,cv=F) +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 1000,lambda2=0),DSF = F,cv=F) +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0,lambda2=1000),DSF = F,cv=F) +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0,lambda2=0),DSF = F,cv=F) +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0,lambda2=100),DSF = F,cv=F) +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 100,lambda2=0),DSF = F,cv=F) +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 100,lambda2=0,adaptative=F),DSF = F,cv=F) +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 100,lambda2=0,adaptive=F),DSF = F,cv=F) +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 10000,lambda2=0,adaptive=F),DSF = F,cv=F) +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 10000,adaptive=F),DSF = F,cv=F) +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0,adaptive=F),DSF = F,cv=F) +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 10000,adaptive=F),DSF = F,cv=F) +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 10000,adaptive=F),DSF = F,cv=F)$coefficients +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 10000,adaptive=F),DSF = F,cv=F)$coef.rescal +library(TAM) +tam.mml(aaaa[,c("item1","item2","item3",'item4')],group=aaaa$TT) +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 10000,lambda2=1e-8,adaptive=F),DSF = F,cv=F)$coef.rescal +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 10000,lambda2=1e-4,adaptive=F),DSF = F,cv=F)$coef.rescal +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 10000,lambda2=1e-18,adaptive=F),DSF = F,cv=F)$coef.rescal +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 10000,lambda2=1e-2,adaptive=F),DSF = F,cv=F)$coef.rescal +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 10000,lambda2=1e-3,adaptive=F),DSF = F,cv=F)$coef.rescal +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 10000,lambda2=1e-2.5,adaptive=F),DSF = F,cv=F)$coef.rescal +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 10000,lambda2=0.0005,adaptive=F),DSF = F,cv=F)$coef.rescal +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 10000,lambda2=0.001,adaptive=F),DSF = F,cv=F)$coef.rescal +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 10000,lambda2=0.01,adaptive=F),DSF = F,cv=F)$coef.rescal +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 10000,lambda2=0.005,adaptive=F),DSF = F,cv=F)$coef.rescal +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 10000,lambda2=0.002,adaptive=F),DSF = F,cv=F)$coef.rescal +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 10000,lambda2=-1,adaptive=F),DSF = F,cv=F)$coef.rescal +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 10000,lambda2=-0.1,adaptive=F),DSF = F,cv=F)$coef.rescal +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 10000,lambda2=-0.0001,adaptive=F),DSF = F,cv=F)$coef.rescal +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 10000,lambda2=-10,adaptive=F),DSF = F,cv=F)$coef.rescal +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 10000,lambda2=-10000,adaptive=F),DSF = F,cv=F)$coef.rescal +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 10000,lambda2=-100000,adaptive=F),DSF = F,cv=F)$coef.rescal +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 10000,lambda2=0,adaptive=F),DSF = F,cv=F)$coef.rescal +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 10000,lambda2=10000000000000000000000000000000000000000,adaptive=F),DSF = F,cv=F)$coef.rescal +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 10000,lambda2=-10000000000000000000000000000000000000000,adaptive=F),DSF = F,cv=F)$coef.rescal +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 10000,lambda2=0,adaptive=F),DSF = F,cv=F)$coef.rescal +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 10000,ada.lambda=0,adaptive=T),DSF = F,cv=F)$coef.rescal +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 10000,ada.lambda=1000,adaptive=T),DSF = F,cv=F)$coef.rescal +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 10000,ada.lambda=-1000,adaptive=T),DSF = F,cv=F)$coef.rescal +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 10000,ada.lambda=-10,adaptive=T),DSF = F,cv=F)$coef.rescal +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 10000,ada.lambda=0,adaptive=T),DSF = F,cv=F)$coef.rescal +0.265/0.09 +tam.mml(aaaa[,c("item1","item2","item3",'item4')],group=aaaa$TT) +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 10000,ada.lambda=0,adaptive=T),DSF = F,cv=F)$coef.rescal +1.1479/0.4403 +0.265/0.09 +0.265/0.036 +tam.mml(aaaa[,c("item1","item2","item3",'item4')],group=aaaa$TT) +1.1479/0.0001 +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 10000,ada.power=2,adaptive=T),DSF = F,cv=F)$coef.rescal +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 10000,cvalue=0,adaptive=T),DSF = F,cv=F)$coef.rescal +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 10000,cvalue=0.000001,adaptive=T),DSF = F,cv=F)$coef.rescal +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 10000,cvalue=1,adaptive=T),DSF = F,cv=F)$coef.rescal +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 10000,cvalue=10000,adaptive=T),DSF = F,cv=F)$coef.rescal +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="RM",control = ctrl_GPCMlasso(lambda = 10000,cvalue=10000,adaptive=T),DSF = F,cv=F)$coef.rescal +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="GRM",control = ctrl_GPCMlasso(lambda = 10000,cvalue=10000,adaptive=T),DSF = F,cv=F)$coef.rescal +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="2PL",control = ctrl_GPCMlasso(lambda = 10000,cvalue=10000,adaptive=T),DSF = F,cv=F)$coef.rescal +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="GPCM",control = ctrl_GPCMlasso(lambda = 10000,cvalue=10000,adaptive=T),DSF = F,cv=F)$coef.rescal +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="GPCM",control = ctrl_GPCMlasso(lambda = 10000,cvalue=10000,adaptive=T),DSF = F,cv=F) +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="GPCM",control = ctrl_GPCMlasso(lambda = 10000,adaptive=F),DSF = F,cv=F) +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="GPCM",control = ctrl_GPCMlasso(lambda = 10000000,adaptive=F),DSF = F,cv=F) +GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="GRSM",control = ctrl_GPCMlasso(lambda = 10000,adaptive=F),DSF = F,cv=F) +tam.mml(aaaa[,c("item1","item2","item3",'item4')],group=aaaa$TT) diff --git a/RProject/resali.R b/RProject/Scripts/resali.R similarity index 100% rename from RProject/resali.R rename to RProject/Scripts/resali.R diff --git a/Scripts/Analysis/DIF-RESIDUS/pcm_dif_residus.do b/Scripts/Analysis/DIF-RESIDUS/pcm_dif_residus.do index a936341..53e0e26 100644 --- a/Scripts/Analysis/DIF-RESIDUS/pcm_dif_residus.do +++ b/Scripts/Analysis/DIF-RESIDUS/pcm_dif_residus.do @@ -1,1513 +1,364 @@ - *================================================================================================================================================= - * Date : 2024-01-23 - * Stata version : Stata 18 SE - * - * This program analyses simulated data accounting for DIF through a partial credit model - * - * ado-files needed : - pcm (version 5.5 October 25, 2023, available on gitea) - * - * - *================================================================================================================================================ - - * Load pcm.ado - adopath+"/home/corentin/Documents/These/Recherche/Simulations/Modules/" - - *========================== - * Scenarios with : J=4 - *========================== - - ****** Scenarios with DIF on 1 item - - ** Scenario 5: J = 4 items / M = 2 modalities / DIF size 0.3 - local N = "100 200 300" - foreach Nnn in `N' { - local Nn = `Nnn' - local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N`Nn'" - local path_res = "/home/corentin/Documents/These/Recherche/Simulations/Analysis/DIF/N`Nn'" - local scenarios = "A B C D E F G" - foreach scen in `scenarios' { - clear - import delim "`path_data'/scenario_5`scen'_`Nn'.csv", encoding(ISO-8859-2) case(preserve) clear - rename TT tt - - * Matrice de taille 1000 * 4 items + 1 DIF + beta + std beta + 1 dif - local nbitems = 4 - local nbdif = 1 - local taillemat = `nbitems'+`nbdif'+3 - mat outmat = J(1000,`taillemat',.) - mat colnames outmat = "item1" "item2" "item3" "item4" "dif1" "beta" "se_beta" "dif_item_1" - di "Scenario 5`scen' / N=`Nnn'" - forvalues k=1/1000 { - if (mod(`k',100)==0) { - di "`k'/1000" - } - preserve - qui keep if replication==`k' - local difitems1=dif1 - local mod "gsem " - forvalues i=1/`nbitems' { - if (`i'==`difitems1') { - local mod = "`mod'"+"(1.item`i'<-THETA@1 tt)" - } - else { - local mod = "`mod'"+"(1.item`i'<-THETA@1)" - } - } - local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent" - qui `mod' - mat V=r(table) - mat W=V[1..2,1...] - forvalues j=1/`nbitems' { - if (`j'<`difitems1') { - mat outmat[`k',`j'] = W[1,3*`j'] // items avant le premier dif - } - else { - mat outmat[`k',`j'] = W[1,1+3*`j'] // items après le premier dif - } - } - mat outmat[`k',`nbitems'+1] = W[1,3*`difitems1'-1] // coef de dif - mat outmat[`k',`nbitems'+2] = W[1,3*`nbitems'+2] // beta - mat outmat[`k',`nbitems'+3] = W[2,3*`nbitems'+2] // se beta - mat outmat[`k',`nbitems'+4] = `difitems1' // numéro item de dif - restore - } - putexcel set "`path_res'/5`scen'_`Nn'.xls", sheet("outmat") replace - putexcel A1=matrix(outmat), colnames -} -} - - -** Scenario 6: J = 4 items / M = 4 modalities / DIF size 0.3 -local N = "100 200 300" -foreach Nnn in `N' { -local Nn = `Nnn' -local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N`Nn'" -local path_res = "/home/corentin/Documents/These/Recherche/Simulations/Analysis/DIF/N`Nn'" -local scenarios = "A B C D E F G" -foreach scen in `scenarios' { -clear -import delim "`path_data'/scenario_6`scen'_`Nn'.csv", encoding(ISO-8859-2) case(preserve) clear -rename TT tt - -* Matrice de taille 1000 * 4 items + 1 DIF + beta + std beta + 1 dif -local nbitems = 4 -local nbdif = 1 -local taillemat = 3*`nbitems'+`nbdif'+3+2 -mat outmat = J(1000,`taillemat',.) -mat colnames outmat = "item1_1" "item1_2" "item1_3" "item2_1" "item2_2" "item2_3" "item3_1" "item3_2" "item3_3" "item4_1" "item4_2" "item4_3" "dif1_1" "dif1_2" "dif1_3" "beta" "se_beta" "dif_item_1" -di "Scenario 6`scen' / N=`Nnn'" -forvalues k=1/1000 { - if (mod(`k',100)==0) { - di "`k'/1000" - } - preserve - qui keep if replication==`k' - local difitems1=dif1 - forvalues i=1/`nbitems' { - if (`i'==`difitems1') { - local constrnt = "constraint 1 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))" - local constrnt2 = "constraint 2 3*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([3.item`i']_cons-([3.item`i']_cons+[3.item`i'] tt))" - } - } - local mod "gsem " - forvalues i=1/`nbitems' { - if (`i'==`difitems1') { - local mod = "`mod'"+"(1.item`i'<-THETA@1 tt)(2.item`i'<-THETA@2 tt)(3.item`i'<-THETA@3 tt)" - } - else { - local mod = "`mod'"+"(1.item`i'<-THETA@1)(2.item`i'<-THETA@2)(3.item`i'<-THETA@3)" - } - } - local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent constraint(1 2)" - qui `constrnt' - qui `constrnt2' - qui `mod' - mat V=r(table) - mat W=V[1..2,1...] - forvalues j=1/`nbitems' { - if (`j'<`difitems1') { - mat outmat[`k',3*`j'-2] = W[1,7*(`j'-1)+3] // items avant le premier dif - mat outmat[`k',3*`j'-1] = W[1,7*(`j'-1)+5] // items avant le premier dif - mat outmat[`k',3*`j'] = W[1,7*(`j'-1)+7] // items avant le premier dif - } - else if (`j'==`difitems1') { - mat outmat[`k',3*`j'-2] = W[1,7*(`j'-1)+4] // items du le premier dif - mat outmat[`k',3*`j'-1] = W[1,7*(`j'-1)+7] // items du le premier dif - mat outmat[`k',3*`j'] = W[1,7*(`j'-1)+10] // items du le premier dif } - } - else { - mat outmat[`k',3*`j'-2] = W[1,7*(`j'-1)+6] // items avant le premier dif - mat outmat[`k',3*`j'-1] = W[1,7*(`j'-1)+8] // items avant le premier dif - mat outmat[`k',3*`j'] = W[1,7*(`j'-1)+10] // items avant le premier dif - } - } - mat outmat[`k',3*`nbitems'+1] = W[1,7*(`difitems1'-1)+2] // coef de dif - mat outmat[`k',3*`nbitems'+2] = W[1,7*(`difitems1'-1)+5] // coef de dif - mat outmat[`k',3*`nbitems'+3] = W[1,7*(`difitems1'-1)+8] // coef de dif - mat outmat[`k',3*`nbitems'+4] = W[1,7*`nbitems'+4] // beta - mat outmat[`k',3*`nbitems'+5] = W[2,7*`nbitems'+4] // se beta - mat outmat[`k',3*`nbitems'+6] = `difitems1' // numéro item de dif - restore -} -putexcel set "`path_res'/6`scen'_`Nn'.xls", sheet("outmat") replace -putexcel A1=matrix(outmat), colnames -} -} - - -** Scenario 7: J = 4 items / M = 2 modalities / DIF size 0.5 - local N = "100 200 300" - foreach Nnn in `N' { - local Nn = `Nnn' - local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N`Nn'" - local path_res = "/home/corentin/Documents/These/Recherche/Simulations/Analysis/DIF/N`Nn'" - local scenarios = "A B C D E F G" - foreach scen in `scenarios' { - clear - import delim "`path_data'/scenario_7`scen'_`Nn'.csv", encoding(ISO-8859-2) case(preserve) clear - rename TT tt - - * Matrice de taille 1000 * 4 items + 1 DIF + beta + std beta + 1 dif - local nbitems = 4 - local nbdif = 1 - local taillemat = `nbitems'+`nbdif'+3 - mat outmat = J(1000,`taillemat',.) - mat colnames outmat = "item1" "item2" "item3" "item4" "dif1" "beta" "se_beta" "dif_item_1" - di "Scenario 7`scen' / N=`Nnn'" - forvalues k=1/1000 { - if (mod(`k',100)==0) { - di "`k'/1000" - } - preserve - qui keep if replication==`k' - local difitems1=dif1 - local mod "gsem " - forvalues i=1/`nbitems' { - if (`i'==`difitems1') { - local mod = "`mod'"+"(1.item`i'<-THETA@1 tt)" - } - else { - local mod = "`mod'"+"(1.item`i'<-THETA@1)" - } - } - local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent" - qui `mod' - mat V=r(table) - mat W=V[1..2,1...] - forvalues j=1/`nbitems' { - if (`j'<`difitems1') { - mat outmat[`k',`j'] = W[1,3*`j'] // items avant le premier dif - } - else { - mat outmat[`k',`j'] = W[1,1+3*`j'] // items après le premier dif - } - } - mat outmat[`k',`nbitems'+1] = W[1,3*`difitems1'-1] // coef de dif - mat outmat[`k',`nbitems'+2] = W[1,3*`nbitems'+2] // beta - mat outmat[`k',`nbitems'+3] = W[2,3*`nbitems'+2] // se beta - mat outmat[`k',`nbitems'+4] = `difitems1' // numéro item de dif - restore - } - putexcel set "`path_res'/7`scen'_`Nn'.xls", sheet("outmat") replace - putexcel A1=matrix(outmat), colnames -} -} - - -** Scenario 8: J = 4 items / M = 4 modalities / DIF size 0.5 -local N = "100 200 300" -foreach Nnn in `N' { -local Nn = `Nnn' -local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N`Nn'" -local path_res = "/home/corentin/Documents/These/Recherche/Simulations/Analysis/DIF/N`Nn'" -local scenarios = "A B C D E F G" -foreach scen in `scenarios' { -clear -import delim "`path_data'/scenario_8`scen'_`Nn'.csv", encoding(ISO-8859-2) case(preserve) clear -rename TT tt - -* Matrice de taille 1000 * 4 items + 1 DIF + beta + std beta + 1 dif -local nbitems = 4 -local nbdif = 1 -local taillemat = 3*`nbitems'+`nbdif'+3+2 -mat outmat = J(1000,`taillemat',.) -mat colnames outmat = "item1_1" "item1_2" "item1_3" "item2_1" "item2_2" "item2_3" "item3_1" "item3_2" "item3_3" "item4_1" "item4_2" "item4_3" "dif1_1" "dif1_2" "dif1_3" "beta" "se_beta" "dif_item_1" -di "Scenario 8`scen' / N=`Nnn'" -forvalues k=1/1000 { - if (mod(`k',100)==0) { - di "`k'/1000" - } - preserve - qui keep if replication==`k' - local difitems1=dif1 - forvalues i=1/`nbitems' { - if (`i'==`difitems1') { - local constrnt = "constraint 1 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))" - local constrnt2 = "constraint 2 3*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([3.item`i']_cons-([3.item`i']_cons+[3.item`i'] tt))" - } - } - local mod "gsem " - forvalues i=1/`nbitems' { - if (`i'==`difitems1') { - local mod = "`mod'"+"(1.item`i'<-THETA@1 tt)(2.item`i'<-THETA@2 tt)(3.item`i'<-THETA@3 tt)" - } - else { - local mod = "`mod'"+"(1.item`i'<-THETA@1)(2.item`i'<-THETA@2)(3.item`i'<-THETA@3)" - } - } - local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent constraint(1 2)" - qui `constrnt' - qui `constrnt2' - qui `mod' - mat V=r(table) - mat W=V[1..2,1...] - forvalues j=1/`nbitems' { - if (`j'<`difitems1') { - mat outmat[`k',3*`j'-2] = W[1,7*(`j'-1)+3] // items avant le premier dif - mat outmat[`k',3*`j'-1] = W[1,7*(`j'-1)+5] // items avant le premier dif - mat outmat[`k',3*`j'] = W[1,7*(`j'-1)+7] // items avant le premier dif - } - else if (`j'==`difitems1') { - mat outmat[`k',3*`j'-2] = W[1,7*(`j'-1)+4] // items du le premier dif - mat outmat[`k',3*`j'-1] = W[1,7*(`j'-1)+7] // items du le premier dif - mat outmat[`k',3*`j'] = W[1,7*(`j'-1)+10] // items du le premier dif } - } - else { - mat outmat[`k',3*`j'-2] = W[1,7*(`j'-1)+6] // items avant le premier dif - mat outmat[`k',3*`j'-1] = W[1,7*(`j'-1)+8] // items avant le premier dif - mat outmat[`k',3*`j'] = W[1,7*(`j'-1)+10] // items avant le premier dif - } - } - mat outmat[`k',3*`nbitems'+1] = W[1,7*(`difitems1'-1)+2] // coef de dif - mat outmat[`k',3*`nbitems'+2] = W[1,7*(`difitems1'-1)+5] // coef de dif - mat outmat[`k',3*`nbitems'+3] = W[1,7*(`difitems1'-1)+8] // coef de dif - mat outmat[`k',3*`nbitems'+4] = W[1,7*`nbitems'+4] // beta - mat outmat[`k',3*`nbitems'+5] = W[2,7*`nbitems'+4] // se beta - mat outmat[`k',3*`nbitems'+6] = `difitems1' // numéro item de dif - restore -} -putexcel set "`path_res'/8`scen'_`Nn'.xls", sheet("outmat") replace -putexcel A1=matrix(outmat), colnames -} -} - - -****** Scenarios with DIF on 2 items - -* Load pcm.ado -adopath+"/home/corentin/Documents/These/Recherche/Simulations/Modules/" - -** Scenario 9: J = 4 items / M = 2 modalities / DIF size 0.3 x2 - local N = "100 200 300" - foreach Nnn in `N' { - local Nn = `Nnn' - local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N`Nn'" - local path_res = "/home/corentin/Documents/These/Recherche/Simulations/Analysis/DIF/N`Nn'" - local scenarios = "A B C D E F G" - foreach scen in `scenarios' { - clear - import delim "`path_data'/scenario_9`scen'_`Nn'.csv", encoding(ISO-8859-2) case(preserve) clear - rename TT tt - - * Matrice de taille 1000 * 4 items + 1 DIF + beta + std beta + 1 dif - local nbitems = 4 - local nbdif = 2 - local taillemat = `nbitems'+`nbdif'+4 - mat outmat = J(1000,`taillemat',.) - mat colnames outmat = "item1" "item2" "item3" "item4" "dif1" "dif2" "beta" "se_beta" "dif_item_1" "dif_item_2" - di "Scenario 9`scen' / N=`Nnn'" - forvalues k=1/1000 { - if (mod(`k',100)==0) { - di "`k'/1000" - } - preserve - qui keep if replication==`k' - local difitems1=dif1 - local difitems2=dif2 - if (`difitems1'<`difitems2') { - local difitemsmin `difitems1' - local difitemsmax `difitems2' - } - else { - local difitemsmin `difitems2' - local difitemsmax `difitems1' - } - local mod "gsem " - forvalues i=1/`nbitems' { - if (`i'==`difitemsmin' | `i'==`difitemsmax') { - local mod = "`mod'"+"(1.item`i'<-THETA@1 tt)" - } - else { - local mod = "`mod'"+"(1.item`i'<-THETA@1)" - } - } - local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent" - qui `mod' - mat V=r(table) - mat W=V[1..2,1...] - forvalues j=1/`nbitems' { - if (`j'<`difitemsmin') { - mat outmat[`k',`j'] = W[1,3*`j'] // items avant le premier dif - } - else if (`j'<`difitemsmax') { - mat outmat[`k',`j'] = W[1,1+3*`j'] // items après le premier dif - } - else { - mat outmat[`k',`j'] = W[1,2+3*`j'] // items après le deuxieme dif - } - } - mat outmat[`k',`nbitems'+1] = W[1,3*`difitemsmin'-1] // coef de dif - mat outmat[`k',`nbitems'+2] = W[1,3*`difitemsmax'] // coef de dif - mat outmat[`k',`nbitems'+3] = W[1,3*`nbitems'+3] // beta - mat outmat[`k',`nbitems'+4] = W[2,3*`nbitems'+3] // se beta - mat outmat[`k',`nbitems'+5] = `difitemsmin' // numéro item de dif - mat outmat[`k',`nbitems'+6] = `difitemsmax' // numéro item de dif - restore - } - putexcel set "`path_res'/9`scen'_`Nn'.xls", sheet("outmat") replace - putexcel A1=matrix(outmat), colnames -} -} - - - -** Scenario 10: J = 4 items / M = 4 modalities / DIF size 0.3 x2 -local N = "100 200 300" -foreach Nnn in `N' { -local Nn = `Nnn' -local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N`Nn'" -local path_res = "/home/corentin/Documents/These/Recherche/Simulations/Analysis/DIF/N`Nn'" -local scenarios = "A B C D E F G" -foreach scen in `scenarios' { -clear -import delim "`path_data'/scenario_10`scen'_`Nn'.csv", encoding(ISO-8859-2) case(preserve) clear -rename TT tt - -* Matrice de taille 1000 * 4 items + 1 DIF + beta + std beta + 1 dif -local nbitems = 4 -local nbdif = 2 -local taillemat = 3*`nbitems'+6+2+`nbdif' -mat outmat = J(1000,`taillemat',.) -mat colnames outmat = "item1_1" "item1_2" "item1_3" "item2_1" "item2_2" "item2_3" "item3_1" "item3_2" "item3_3" "item4_1" "item4_2" "item4_3" "dif1_1" "dif1_2" "dif1_3" "dif2_1" "dif2_2" "dif2_3" "beta" "se_beta" "dif_item_1" "dif_item_2" -di "Scenario 10`scen' / N=`Nnn'" -forvalues k=1/1000 { - if (mod(`k',100)==0) { - di "`k'/1000" - } - preserve - qui keep if replication==`k' - local difitems1=dif1 - local difitems2=dif2 - if (`difitems1'<`difitems2') { - local difitemsmin `difitems1' - local difitemsmax `difitems2' - } - else { - local difitemsmin `difitems2' - local difitemsmax `difitems1' - } - forvalues i=1/`nbitems' { - if (`i'==`difitemsmin') { - local constrnt = "constraint 1 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))" - local constrnt2 = "constraint 2 3*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([3.item`i']_cons-([3.item`i']_cons+[3.item`i'] tt))" - } - } - forvalues i=1/`nbitems' { - if (`i'==`difitemsmax') { - local constrn3 = "constraint 3 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))" - local constrnt4 = "constraint 4 3*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([3.item`i']_cons-([3.item`i']_cons+[3.item`i'] tt))" - } - } - local mod "gsem " - forvalues i=1/`nbitems' { - if (`i'==`difitemsmin' | `i'==`difitemsmax') { - local mod = "`mod'"+"(1.item`i'<-THETA@1 tt)(2.item`i'<-THETA@2 tt)(3.item`i'<-THETA@3 tt)" - } - else { - local mod = "`mod'"+"(1.item`i'<-THETA@1)(2.item`i'<-THETA@2)(3.item`i'<-THETA@3)" - } - } - local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent constraint(1 2 3 4)" - qui `constrnt' - qui `constrnt2' - qui `constrnt3' - qui `constrnt4' - qui `mod' - mat V=r(table) - mat W=V[1..2,1...] - forvalues j=1/`nbitems' { - if (`j'<`difitemsmin') { - mat outmat[`k',3*`j'-2] = W[1,7*(`j'-1)+3] // items avant le premier dif - mat outmat[`k',3*`j'-1] = W[1,7*(`j'-1)+5] // items avant le premier dif - mat outmat[`k',3*`j'] = W[1,7*(`j'-1)+7] // items avant le premier dif - } - else if (`j'==`difitemsmin') { - mat outmat[`k',3*`j'-2] = W[1,7*(`j'-1)+4] // items du le premier dif - mat outmat[`k',3*`j'-1] = W[1,7*(`j'-1)+7] // items du le premier dif - mat outmat[`k',3*`j'] = W[1,7*(`j'-1)+10] // items du le premier dif } - } - else if (`j'<`difitemsmax') { - mat outmat[`k',3*`j'-2] = W[1,7*(`j'-1)+6] // items avant le premier dif - mat outmat[`k',3*`j'-1] = W[1,7*(`j'-1)+8] // items avant le premier dif - mat outmat[`k',3*`j'] = W[1,7*(`j'-1)+10] // items avant le premier dif - } - else if (`j'==`difitemsmax') { - mat outmat[`k',3*`j'-2] = W[1,7*(`j'-1)+7] // items avant le premier dif - mat outmat[`k',3*`j'-1] = W[1,7*(`j'-1)+10] // items avant le premier dif - mat outmat[`k',3*`j'] = W[1,7*(`j'-1)+13] // items avant le premier dif - } - else { - mat outmat[`k',3*`j'-2] = W[1,7*(`j'-1)+9] // items avant le premier dif - mat outmat[`k',3*`j'-1] = W[1,7*(`j'-1)+11] // items avant le premier dif - mat outmat[`k',3*`j'] = W[1,7*(`j'-1)+13] // items avant le premier dif - } - } - mat outmat[`k',3*`nbitems'+1] = W[1,7*(`difitemsmin'-1)+2] // coef de dif - mat outmat[`k',3*`nbitems'+2] = W[1,7*(`difitemsmin'-1)+5] // coef de dif - mat outmat[`k',3*`nbitems'+3] = W[1,7*(`difitemsmin'-1)+8] // coef de dif - mat outmat[`k',3*`nbitems'+4] = W[1,7*(`difitemsmax'-1)+5] // coef de dif - mat outmat[`k',3*`nbitems'+5] = W[1,7*(`difitemsmax'-1)+8] // coef de dif - mat outmat[`k',3*`nbitems'+6] = W[1,7*(`difitemsmax'-1)+11] // coef de dif - mat outmat[`k',3*`nbitems'+7] = W[1,7*`nbitems'+7] // beta - mat outmat[`k',3*`nbitems'+8] = W[2,7*`nbitems'+7] // se beta - mat outmat[`k',3*`nbitems'+9] = `difitemsmin' // numéro item de dif - mat outmat[`k',3*`nbitems'+10] = `difitemsmax' // numéro item de dif - restore -} -putexcel set "`path_res'/10`scen'_`Nn'.xls", sheet("outmat") replace -putexcel A1=matrix(outmat), colnames -} -} - - - -** Scenario 11: J = 4 items / M = 2 modalities / DIF size 0.5 x2 - local N = "100 200 300" - foreach Nnn in `N' { - local Nn = `Nnn' - local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N`Nn'" - local path_res = "/home/corentin/Documents/These/Recherche/Simulations/Analysis/DIF/N`Nn'" - local scenarios = "A B C D E F G" - foreach scen in `scenarios' { - clear - import delim "`path_data'/scenario_11`scen'_`Nn'.csv", encoding(ISO-8859-2) case(preserve) clear - rename TT tt - - * Matrice de taille 1000 * 4 items + 1 DIF + beta + std beta + 1 dif - local nbitems = 4 - local nbdif = 2 - local taillemat = `nbitems'+`nbdif'+4 - mat outmat = J(1000,`taillemat',.) - mat colnames outmat = "item1" "item2" "item3" "item4" "dif1" "dif2" "beta" "se_beta" "dif_item_1" "dif_item_2" - di "Scenario 11`scen' / N=`Nnn'" - forvalues k=1/1000 { - if (mod(`k',100)==0) { - di "`k'/1000" - } - preserve - qui keep if replication==`k' - local difitems1=dif1 - local difitems2=dif2 - if (`difitems1'<`difitems2') { - local difitemsmin `difitems1' - local difitemsmax `difitems2' - } - else { - local difitemsmin `difitems2' - local difitemsmax `difitems1' - } - local mod "gsem " - forvalues i=1/`nbitems' { - if (`i'==`difitemsmin' | `i'==`difitemsmax') { - local mod = "`mod'"+"(1.item`i'<-THETA@1 tt)" - } - else { - local mod = "`mod'"+"(1.item`i'<-THETA@1)" - } - } - local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent" - qui `mod' - mat V=r(table) - mat W=V[1..2,1...] - forvalues j=1/`nbitems' { - if (`j'<`difitemsmin') { - mat outmat[`k',`j'] = W[1,3*`j'] // items avant le premier dif - } - else if (`j'<`difitemsmax') { - mat outmat[`k',`j'] = W[1,1+3*`j'] // items après le premier dif - } - else { - mat outmat[`k',`j'] = W[1,2+3*`j'] // items après le deuxieme dif - } - } - mat outmat[`k',`nbitems'+1] = W[1,3*`difitemsmin'-1] // coef de dif - mat outmat[`k',`nbitems'+2] = W[1,3*`difitemsmax'] // coef de dif - mat outmat[`k',`nbitems'+3] = W[1,3*`nbitems'+3] // beta - mat outmat[`k',`nbitems'+4] = W[2,3*`nbitems'+3] // se beta - mat outmat[`k',`nbitems'+5] = `difitemsmin' // numéro item de dif - mat outmat[`k',`nbitems'+6] = `difitemsmax' // numéro item de dif - restore - } - putexcel set "`path_res'/11`scen'_`Nn'.xls", sheet("outmat") replace - putexcel A1=matrix(outmat), colnames -} -} - - - -** Scenario 12: J = 4 items / M = 4 modalities / DIF size 0.5 x2 -local N = "100 200 300" -foreach Nnn in `N' { -local Nn = `Nnn' -local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N`Nn'" -local path_res = "/home/corentin/Documents/These/Recherche/Simulations/Analysis/DIF/N`Nn'" -local scenarios = "A B C D E F G" -foreach scen in `scenarios' { -clear -import delim "`path_data'/scenario_12`scen'_`Nn'.csv", encoding(ISO-8859-2) case(preserve) clear -rename TT tt - -* Matrice de taille 1000 * 4 items + 1 DIF + beta + std beta + 1 dif -local nbitems = 4 -local nbdif = 2 -local taillemat = 3*`nbitems'+6+2+`nbdif' -mat outmat = J(1000,`taillemat',.) -mat colnames outmat = "item1_1" "item1_2" "item1_3" "item2_1" "item2_2" "item2_3" "item3_1" "item3_2" "item3_3" "item4_1" "item4_2" "item4_3" "dif1_1" "dif1_2" "dif1_3" "dif2_1" "dif2_2" "dif2_3" "beta" "se_beta" "dif_item_1" "dif_item_2" -di "Scenario 12`scen' / N=`Nnn'" -forvalues k=1/1000 { - if (mod(`k',100)==0) { - di "`k'/1000" - } - preserve - qui keep if replication==`k' - local difitems1=dif1 - local difitems2=dif2 - if (`difitems1'<`difitems2') { - local difitemsmin `difitems1' - local difitemsmax `difitems2' - } - else { - local difitemsmin `difitems2' - local difitemsmax `difitems1' - } - forvalues i=1/`nbitems' { - if (`i'==`difitemsmin') { - local constrnt = "constraint 1 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))" - local constrnt2 = "constraint 2 3*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([3.item`i']_cons-([3.item`i']_cons+[3.item`i'] tt))" - } - } - forvalues i=1/`nbitems' { - if (`i'==`difitemsmax') { - local constrn3 = "constraint 3 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))" - local constrnt4 = "constraint 4 3*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([3.item`i']_cons-([3.item`i']_cons+[3.item`i'] tt))" - } - } - local mod "gsem " - forvalues i=1/`nbitems' { - if (`i'==`difitemsmin' | `i'==`difitemsmax') { - local mod = "`mod'"+"(1.item`i'<-THETA@1 tt)(2.item`i'<-THETA@2 tt)(3.item`i'<-THETA@3 tt)" - } - else { - local mod = "`mod'"+"(1.item`i'<-THETA@1)(2.item`i'<-THETA@2)(3.item`i'<-THETA@3)" - } - } - local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent constraint(1 2 3 4)" - qui `constrnt' - qui `constrnt2' - qui `constrnt3' - qui `constrnt4' - qui `mod' - mat V=r(table) - mat W=V[1..2,1...] - forvalues j=1/`nbitems' { - if (`j'<`difitemsmin') { - mat outmat[`k',3*`j'-2] = W[1,7*(`j'-1)+3] // items avant le premier dif - mat outmat[`k',3*`j'-1] = W[1,7*(`j'-1)+5] // items avant le premier dif - mat outmat[`k',3*`j'] = W[1,7*(`j'-1)+7] // items avant le premier dif - } - else if (`j'==`difitemsmin') { - mat outmat[`k',3*`j'-2] = W[1,7*(`j'-1)+4] // items du le premier dif - mat outmat[`k',3*`j'-1] = W[1,7*(`j'-1)+7] // items du le premier dif - mat outmat[`k',3*`j'] = W[1,7*(`j'-1)+10] // items du le premier dif } - } - else if (`j'<`difitemsmax') { - mat outmat[`k',3*`j'-2] = W[1,7*(`j'-1)+6] // items avant le premier dif - mat outmat[`k',3*`j'-1] = W[1,7*(`j'-1)+8] // items avant le premier dif - mat outmat[`k',3*`j'] = W[1,7*(`j'-1)+10] // items avant le premier dif - } - else if (`j'==`difitemsmax') { - mat outmat[`k',3*`j'-2] = W[1,7*(`j'-1)+7] // items avant le premier dif - mat outmat[`k',3*`j'-1] = W[1,7*(`j'-1)+10] // items avant le premier dif - mat outmat[`k',3*`j'] = W[1,7*(`j'-1)+13] // items avant le premier dif - } - else { - mat outmat[`k',3*`j'-2] = W[1,7*(`j'-1)+9] // items avant le premier dif - mat outmat[`k',3*`j'-1] = W[1,7*(`j'-1)+11] // items avant le premier dif - mat outmat[`k',3*`j'] = W[1,7*(`j'-1)+13] // items avant le premier dif - } - } - mat outmat[`k',3*`nbitems'+1] = W[1,7*(`difitemsmin'-1)+2] // coef de dif - mat outmat[`k',3*`nbitems'+2] = W[1,7*(`difitemsmin'-1)+5] // coef de dif - mat outmat[`k',3*`nbitems'+3] = W[1,7*(`difitemsmin'-1)+8] // coef de dif - mat outmat[`k',3*`nbitems'+4] = W[1,7*(`difitemsmax'-1)+5] // coef de dif - mat outmat[`k',3*`nbitems'+5] = W[1,7*(`difitemsmax'-1)+8] // coef de dif - mat outmat[`k',3*`nbitems'+6] = W[1,7*(`difitemsmax'-1)+11] // coef de dif - mat outmat[`k',3*`nbitems'+7] = W[1,7*`nbitems'+7] // beta - mat outmat[`k',3*`nbitems'+8] = W[2,7*`nbitems'+7] // se beta - mat outmat[`k',3*`nbitems'+9] = `difitemsmin' // numéro item de dif - mat outmat[`k',3*`nbitems'+10] = `difitemsmax' // numéro item de dif - restore -} -putexcel set "`path_res'/12`scen'_`Nn'.xls", sheet("outmat") replace -putexcel A1=matrix(outmat), colnames -} -} - - - -*========================== -* Scenarios with : J=7 -*========================== - - -****** Scenarios with DIF on 2 items - -* Load pcm.ado -adopath+"/home/corentin/Documents/These/Recherche/Simulations/Modules/" - -** Scenario 13: J = 7 items / M = 2 modalities / DIF size 0.3 x2 - local N = "100 200 300" - foreach Nnn in `N' { - local Nn = `Nnn' - local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N`Nn'" - local path_res = "/home/corentin/Documents/These/Recherche/Simulations/Analysis/DIF/N`Nn'" - local scenarios = "A B C D E F G" - foreach scen in `scenarios' { - clear - import delim "`path_data'/scenario_13`scen'_`Nn'.csv", encoding(ISO-8859-2) case(preserve) clear - rename TT tt - - * Matrice de taille 1000 * 4 items + 1 DIF + beta + std beta + 1 dif - local nbitems = 7 - local nbdif = 2 - local taillemat = `nbitems'+`nbdif'+4 - mat outmat = J(1000,`taillemat',.) - mat colnames outmat = "item1" "item2" "item3" "item4" "item5" "item6" "item7" "dif1" "dif2" "beta" "se_beta" "dif_item_1" "dif_item_2" - di "Scenario 13`scen' / N=`Nnn'" - forvalues k=1/1000 { - if (mod(`k',100)==0) { - di "`k'/1000" - } - preserve - qui keep if replication==`k' - local difitems1=dif1 - local difitems2=dif2 - if (`difitems1'<`difitems2') { - local difitemsmin `difitems1' - local difitemsmax `difitems2' - } - else { - local difitemsmin `difitems2' - local difitemsmax `difitems1' - } - local mod "gsem " - forvalues i=1/`nbitems' { - if (`i'==`difitemsmin' | `i'==`difitemsmax') { - local mod = "`mod'"+"(1.item`i'<-THETA@1 tt)" - } - else { - local mod = "`mod'"+"(1.item`i'<-THETA@1)" - } - } - local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent" - qui `mod' - mat V=r(table) - mat W=V[1..2,1...] - forvalues j=1/`nbitems' { - if (`j'<`difitemsmin') { - mat outmat[`k',`j'] = W[1,3*`j'] // items avant le premier dif - } - else if (`j'<`difitemsmax') { - mat outmat[`k',`j'] = W[1,1+3*`j'] // items après le premier dif - } - else { - mat outmat[`k',`j'] = W[1,2+3*`j'] // items après le deuxieme dif - } - } - mat outmat[`k',`nbitems'+1] = W[1,3*`difitemsmin'-1] // coef de dif - mat outmat[`k',`nbitems'+2] = W[1,3*`difitemsmax'] // coef de dif - mat outmat[`k',`nbitems'+3] = W[1,3*`nbitems'+3] // beta - mat outmat[`k',`nbitems'+4] = W[2,3*`nbitems'+3] // se beta - mat outmat[`k',`nbitems'+5] = `difitemsmin' // numéro item de dif - mat outmat[`k',`nbitems'+6] = `difitemsmax' // numéro item de dif - restore - } - putexcel set "`path_res'/13`scen'_`Nn'.xls", sheet("outmat") replace - putexcel A1=matrix(outmat), colnames -} -} - - - -** Scenario 14: J = 7 items / M = 4 modalities / DIF size 0.3 x2 -local N = "100 200 300" -foreach Nnn in `N' { -local Nn = `Nnn' -local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N`Nn'" -local path_res = "/home/corentin/Documents/These/Recherche/Simulations/Analysis/DIF/N`Nn'" -local scenarios = "A B C D E F G" -foreach scen in `scenarios' { -clear -import delim "`path_data'/scenario_14`scen'_`Nn'.csv", encoding(ISO-8859-2) case(preserve) clear -rename TT tt - -* Matrice de taille 1000 * 4 items + 1 DIF + beta + std beta + 1 dif -local nbitems = 7 -local nbdif = 2 -local taillemat = 3*`nbitems'+6+2+`nbdif' -mat outmat = J(1000,`taillemat',.) -mat colnames outmat = "item1_1" "item1_2" "item1_3" "item2_1" "item2_2" "item2_3" "item3_1" "item3_2" "item3_3" "item4_1" "item4_2" "item4_3" "item5_1" "item5_2" "item5_3" "item6_1" "item6_2" "item6_3" "item7_1" "item7_2" "item7_3" "dif1_1" "dif1_2" "dif1_3" "dif2_1" "dif2_2" "dif2_3" "beta" "se_beta" "dif_item_1" "dif_item_2" -di "Scenario 14`scen' / N=`Nnn'" -forvalues k=1/1000 { - if (mod(`k',100)==0) { - di "`k'/1000" - } - preserve - qui keep if replication==`k' - local difitems1=dif1 - local difitems2=dif2 - if (`difitems1'<`difitems2') { - local difitemsmin `difitems1' - local difitemsmax `difitems2' - } - else { - local difitemsmin `difitems2' - local difitemsmax `difitems1' - } - forvalues i=1/`nbitems' { - if (`i'==`difitemsmin') { - local constrnt = "constraint 1 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))" - local constrnt2 = "constraint 2 3*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([3.item`i']_cons-([3.item`i']_cons+[3.item`i'] tt))" - } - } - forvalues i=1/`nbitems' { - if (`i'==`difitemsmax') { - local constrn3 = "constraint 3 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))" - local constrnt4 = "constraint 4 3*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([3.item`i']_cons-([3.item`i']_cons+[3.item`i'] tt))" - } - } - local mod "gsem " - forvalues i=1/`nbitems' { - if (`i'==`difitemsmin' | `i'==`difitemsmax') { - local mod = "`mod'"+"(1.item`i'<-THETA@1 tt)(2.item`i'<-THETA@2 tt)(3.item`i'<-THETA@3 tt)" - } - else { - local mod = "`mod'"+"(1.item`i'<-THETA@1)(2.item`i'<-THETA@2)(3.item`i'<-THETA@3)" - } - } - local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent constraint(1 2 3 4)" - qui `constrnt' - qui `constrnt2' - qui `constrnt3' - qui `constrnt4' - qui `mod' - mat V=r(table) - mat W=V[1..2,1...] - forvalues j=1/`nbitems' { - if (`j'<`difitemsmin') { - mat outmat[`k',3*`j'-2] = W[1,7*(`j'-1)+3] // items avant le premier dif - mat outmat[`k',3*`j'-1] = W[1,7*(`j'-1)+5] // items avant le premier dif - mat outmat[`k',3*`j'] = W[1,7*(`j'-1)+7] // items avant le premier dif - } - else if (`j'==`difitemsmin') { - mat outmat[`k',3*`j'-2] = W[1,7*(`j'-1)+4] // items du le premier dif - mat outmat[`k',3*`j'-1] = W[1,7*(`j'-1)+7] // items du le premier dif - mat outmat[`k',3*`j'] = W[1,7*(`j'-1)+10] // items du le premier dif } - } - else if (`j'<`difitemsmax') { - mat outmat[`k',3*`j'-2] = W[1,7*(`j'-1)+6] // items avant le premier dif - mat outmat[`k',3*`j'-1] = W[1,7*(`j'-1)+8] // items avant le premier dif - mat outmat[`k',3*`j'] = W[1,7*(`j'-1)+10] // items avant le premier dif - } - else if (`j'==`difitemsmax') { - mat outmat[`k',3*`j'-2] = W[1,7*(`j'-1)+7] // items avant le premier dif - mat outmat[`k',3*`j'-1] = W[1,7*(`j'-1)+10] // items avant le premier dif - mat outmat[`k',3*`j'] = W[1,7*(`j'-1)+13] // items avant le premier dif - } - else { - mat outmat[`k',3*`j'-2] = W[1,7*(`j'-1)+9] // items avant le premier dif - mat outmat[`k',3*`j'-1] = W[1,7*(`j'-1)+11] // items avant le premier dif - mat outmat[`k',3*`j'] = W[1,7*(`j'-1)+13] // items avant le premier dif - } - } - mat outmat[`k',3*`nbitems'+1] = W[1,7*(`difitemsmin'-1)+2] // coef de dif - mat outmat[`k',3*`nbitems'+2] = W[1,7*(`difitemsmin'-1)+5] // coef de dif - mat outmat[`k',3*`nbitems'+3] = W[1,7*(`difitemsmin'-1)+8] // coef de dif - mat outmat[`k',3*`nbitems'+4] = W[1,7*(`difitemsmax'-1)+5] // coef de dif - mat outmat[`k',3*`nbitems'+5] = W[1,7*(`difitemsmax'-1)+8] // coef de dif - mat outmat[`k',3*`nbitems'+6] = W[1,7*(`difitemsmax'-1)+11] // coef de dif - mat outmat[`k',3*`nbitems'+7] = W[1,7*`nbitems'+7] // beta - mat outmat[`k',3*`nbitems'+8] = W[2,7*`nbitems'+7] // se beta - mat outmat[`k',3*`nbitems'+9] = `difitemsmin' // numéro item de dif - mat outmat[`k',3*`nbitems'+10] = `difitemsmax' // numéro item de dif - restore -} -putexcel set "`path_res'/14`scen'_`Nn'.xls", sheet("outmat") replace -putexcel A1=matrix(outmat), colnames -} -} - - - -** Scenario 15: J = 7 items / M = 2 modalities / DIF size 0.5 x2 - local N = "100 200 300" - foreach Nnn in `N' { - local Nn = `Nnn' - local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N`Nn'" - local path_res = "/home/corentin/Documents/These/Recherche/Simulations/Analysis/DIF/N`Nn'" - local scenarios = "A B C D E F G" - foreach scen in `scenarios' { - clear - import delim "`path_data'/scenario_15`scen'_`Nn'.csv", encoding(ISO-8859-2) case(preserve) clear - rename TT tt - - * Matrice de taille 1000 * 4 items + 1 DIF + beta + std beta + 1 dif - local nbitems = 7 - local nbdif = 2 - local taillemat = `nbitems'+`nbdif'+4 - mat outmat = J(1000,`taillemat',.) - mat colnames outmat = "item1" "item2" "item3" "item4" "item5" "item6" "item7" "dif1" "dif2" "beta" "se_beta" "dif_item_1" "dif_item_2" - di "Scenario 15`scen' / N=`Nnn'" - forvalues k=1/1000 { - if (mod(`k',100)==0) { - di "`k'/1000" - } - preserve - qui keep if replication==`k' - local difitems1=dif1 - local difitems2=dif2 - if (`difitems1'<`difitems2') { - local difitemsmin `difitems1' - local difitemsmax `difitems2' - } - else { - local difitemsmin `difitems2' - local difitemsmax `difitems1' - } - local mod "gsem " - forvalues i=1/`nbitems' { - if (`i'==`difitemsmin' | `i'==`difitemsmax') { - local mod = "`mod'"+"(1.item`i'<-THETA@1 tt)" - } - else { - local mod = "`mod'"+"(1.item`i'<-THETA@1)" - } - } - local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent" - qui `mod' - mat V=r(table) - mat W=V[1..2,1...] - forvalues j=1/`nbitems' { - if (`j'<`difitemsmin') { - mat outmat[`k',`j'] = W[1,3*`j'] // items avant le premier dif - } - else if (`j'<`difitemsmax') { - mat outmat[`k',`j'] = W[1,1+3*`j'] // items après le premier dif - } - else { - mat outmat[`k',`j'] = W[1,2+3*`j'] // items après le deuxieme dif - } - } - mat outmat[`k',`nbitems'+1] = W[1,3*`difitemsmin'-1] // coef de dif - mat outmat[`k',`nbitems'+2] = W[1,3*`difitemsmax'] // coef de dif - mat outmat[`k',`nbitems'+3] = W[1,3*`nbitems'+3] // beta - mat outmat[`k',`nbitems'+4] = W[2,3*`nbitems'+3] // se beta - mat outmat[`k',`nbitems'+5] = `difitemsmin' // numéro item de dif - mat outmat[`k',`nbitems'+6] = `difitemsmax' // numéro item de dif - restore - } - putexcel set "`path_res'/15`scen'_`Nn'.xls", sheet("outmat") replace - putexcel A1=matrix(outmat), colnames -} -} - - - -** Scenario 16: J = 7 items / M = 4 modalities / DIF size 0.5 x2 -local N = "100 200 300" -foreach Nnn in `N' { -local Nn = `Nnn' -local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N`Nn'" -local path_res = "/home/corentin/Documents/These/Recherche/Simulations/Analysis/DIF/N`Nn'" -local scenarios = "A B C D E F G" -foreach scen in `scenarios' { -clear -import delim "`path_data'/scenario_16`scen'_`Nn'.csv", encoding(ISO-8859-2) case(preserve) clear -rename TT tt - -* Matrice de taille 1000 * 4 items + 1 DIF + beta + std beta + 1 dif -local nbitems = 7 -local nbdif = 2 -local taillemat = 3*`nbitems'+6+2+`nbdif' -mat outmat = J(1000,`taillemat',.) -mat colnames outmat = "item1_1" "item1_2" "item1_3" "item2_1" "item2_2" "item2_3" "item3_1" "item3_2" "item3_3" "item4_1" "item4_2" "item4_3" "item5_1" "item5_2" "item5_3" "item6_1" "item6_2" "item6_3" "item7_1" "item7_2" "item7_3" "dif1_1" "dif1_2" "dif1_3" "dif2_1" "dif2_2" "dif2_3" "beta" "se_beta" "dif_item_1" "dif_item_2" -di "Scenario 16`scen' / N=`Nnn'" -forvalues k=1/1000 { - if (mod(`k',100)==0) { - di "`k'/1000" - } - preserve - qui keep if replication==`k' - local difitems1=dif1 - local difitems2=dif2 - if (`difitems1'<`difitems2') { - local difitemsmin `difitems1' - local difitemsmax `difitems2' - } - else { - local difitemsmin `difitems2' - local difitemsmax `difitems1' - } - forvalues i=1/`nbitems' { - if (`i'==`difitemsmin') { - local constrnt = "constraint 1 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))" - local constrnt2 = "constraint 2 3*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([3.item`i']_cons-([3.item`i']_cons+[3.item`i'] tt))" - } - } - forvalues i=1/`nbitems' { - if (`i'==`difitemsmax') { - local constrn3 = "constraint 3 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))" - local constrnt4 = "constraint 4 3*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([3.item`i']_cons-([3.item`i']_cons+[3.item`i'] tt))" - } - } - local mod "gsem " - forvalues i=1/`nbitems' { - if (`i'==`difitemsmin' | `i'==`difitemsmax') { - local mod = "`mod'"+"(1.item`i'<-THETA@1 tt)(2.item`i'<-THETA@2 tt)(3.item`i'<-THETA@3 tt)" - } - else { - local mod = "`mod'"+"(1.item`i'<-THETA@1)(2.item`i'<-THETA@2)(3.item`i'<-THETA@3)" - } - } - local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent constraint(1 2 3 4)" - qui `constrnt' - qui `constrnt2' - qui `constrnt3' - qui `constrnt4' - qui `mod' - mat V=r(table) - mat W=V[1..2,1...] - forvalues j=1/`nbitems' { - if (`j'<`difitemsmin') { - mat outmat[`k',3*`j'-2] = W[1,7*(`j'-1)+3] // items avant le premier dif - mat outmat[`k',3*`j'-1] = W[1,7*(`j'-1)+5] // items avant le premier dif - mat outmat[`k',3*`j'] = W[1,7*(`j'-1)+7] // items avant le premier dif - } - else if (`j'==`difitemsmin') { - mat outmat[`k',3*`j'-2] = W[1,7*(`j'-1)+4] // items du le premier dif - mat outmat[`k',3*`j'-1] = W[1,7*(`j'-1)+7] // items du le premier dif - mat outmat[`k',3*`j'] = W[1,7*(`j'-1)+10] // items du le premier dif } - } - else if (`j'<`difitemsmax') { - mat outmat[`k',3*`j'-2] = W[1,7*(`j'-1)+6] // items avant le premier dif - mat outmat[`k',3*`j'-1] = W[1,7*(`j'-1)+8] // items avant le premier dif - mat outmat[`k',3*`j'] = W[1,7*(`j'-1)+10] // items avant le premier dif - } - else if (`j'==`difitemsmax') { - mat outmat[`k',3*`j'-2] = W[1,7*(`j'-1)+7] // items avant le premier dif - mat outmat[`k',3*`j'-1] = W[1,7*(`j'-1)+10] // items avant le premier dif - mat outmat[`k',3*`j'] = W[1,7*(`j'-1)+13] // items avant le premier dif - } - else { - mat outmat[`k',3*`j'-2] = W[1,7*(`j'-1)+9] // items avant le premier dif - mat outmat[`k',3*`j'-1] = W[1,7*(`j'-1)+11] // items avant le premier dif - mat outmat[`k',3*`j'] = W[1,7*(`j'-1)+13] // items avant le premier dif - } - } - mat outmat[`k',3*`nbitems'+1] = W[1,7*(`difitemsmin'-1)+2] // coef de dif - mat outmat[`k',3*`nbitems'+2] = W[1,7*(`difitemsmin'-1)+5] // coef de dif - mat outmat[`k',3*`nbitems'+3] = W[1,7*(`difitemsmin'-1)+8] // coef de dif - mat outmat[`k',3*`nbitems'+4] = W[1,7*(`difitemsmax'-1)+5] // coef de dif - mat outmat[`k',3*`nbitems'+5] = W[1,7*(`difitemsmax'-1)+8] // coef de dif - mat outmat[`k',3*`nbitems'+6] = W[1,7*(`difitemsmax'-1)+11] // coef de dif - mat outmat[`k',3*`nbitems'+7] = W[1,7*`nbitems'+7] // beta - mat outmat[`k',3*`nbitems'+8] = W[2,7*`nbitems'+7] // se beta - mat outmat[`k',3*`nbitems'+9] = `difitemsmin' // numéro item de dif - mat outmat[`k',3*`nbitems'+10] = `difitemsmax' // numéro item de dif - restore -} -putexcel set "`path_res'/16`scen'_`Nn'.xls", sheet("outmat") replace -putexcel A1=matrix(outmat), colnames -} -} - -***** Scenarios with DIF on 3 items - -* Load pcm.ado -adopath+"/home/corentin/Documents/These/Recherche/Simulations/Modules/" - -** Scenario 17: J = 7 items / M = 2 modalities / DIF size 0.3 x3 - local N = "100 200 300" - foreach Nnn in `N' { - local Nn = `Nnn' - local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N`Nn'" - local path_res = "/home/corentin/Documents/These/Recherche/Simulations/Analysis/DIF/N`Nn'" - local scenarios = "A B C D E F G" - foreach scen in `scenarios' { - clear - import delim "`path_data'/scenario_17`scen'_`Nn'.csv", encoding(ISO-8859-2) case(preserve) clear - rename TT tt - - * Matrice de taille 1000 * 4 items + 1 DIF + beta + std beta + 1 dif - local nbitems = 7 - local nbdif = 3 - local taillemat = `nbitems'+`nbdif'+5 - mat outmat = J(1000,`taillemat',.) - mat colnames outmat = "item1" "item2" "item3" "item4" "item5" "item6" "item7" "dif1" "dif2" "dif3" "beta" "se_beta" "dif_item_1" "dif_item_2" "dif_item_3" - di "Scenario 17`scen' / N=`Nnn'" - forvalues k=1/1000 { - if (mod(`k',100)==0) { - di "`k'/1000" - } - preserve - qui keep if replication==`k' - local difitems1=dif1 - local difitems2=dif2 - local difitems3=dif3 - if (`difitems1' < `difitems2') { - local difitemsmin= `difitems1' - local difitemsmax= `difitems2' - } - else { - local difitemsmin= `difitems2' - local difitemsmax= `difitems1' - } - if (`difitems3' < `difitemsmin') { - local difitemsmid = `difitemsmin' - local difitemsmin= `difitems3' - } - else if (`difitems3' > `difitemsmax') { - local difitemsmid = `difitemsmax' - local difitemsmax= `difitems3' - } - else { - local difitemsmid = `difitems3' - } - local mod "gsem " - forvalues i=1/`nbitems' { - if (`i'==`difitemsmin' | `i'==`difitemsmax' | `i'==`difitemsmid') { - local mod = "`mod'"+"(1.item`i'<-THETA@1 tt)" - } - else { - local mod = "`mod'"+"(1.item`i'<-THETA@1)" - } - } - local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent" - qui `mod' - mat V=r(table) - mat W=V[1..2,1...] - forvalues j=1/`nbitems' { - if (`j'<`difitemsmin') { - mat outmat[`k',`j'] = W[1,3*`j'] // items avant le premier dif - } - else if (`j'<`difitemsmid') { - mat outmat[`k',`j'] = W[1,1+3*`j'] // items après le premier dif - } - else if (`j'<`difitemsmax') { - mat outmat[`k',`j'] = W[1,2+3*`j'] // items après le deuxieme dif - } - else { - mat outmat[`k',`j'] = W[1,3+3*`j'] // items après le deuxieme dif - } - } - mat outmat[`k',`nbitems'+1] = W[1,3*`difitemsmin'-1] // coef de dif - mat outmat[`k',`nbitems'+2] = W[1,3*`difitemsmid'] // coef de dif - mat outmat[`k',`nbitems'+3] = W[1,3*`difitemsmax'+1] // coef de dif - mat outmat[`k',`nbitems'+4] = W[1,3*`nbitems'+4] // beta - mat outmat[`k',`nbitems'+5] = W[2,3*`nbitems'+4] // se beta - mat outmat[`k',`nbitems'+6] = `difitemsmin' // numéro item de dif - mat outmat[`k',`nbitems'+7] = `difitemsmid' // numéro item de dif - mat outmat[`k',`nbitems'+8] = `difitemsmax' // numéro item de dif - restore - } - putexcel set "`path_res'/17`scen'_`Nn'.xls", sheet("outmat") replace - putexcel A1=matrix(outmat), colnames -} -} - - - -** Scenario 18: J = 7 items / M = 4 modalities / DIF size 0.3 x3 -local N = "100 200 300" -foreach Nnn in `N' { -local Nn = `Nnn' -local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N`Nn'" -local path_res = "/home/corentin/Documents/These/Recherche/Simulations/Analysis/DIF/N`Nn'" -local scenarios = "A B C D E F G" -foreach scen in `scenarios' { -clear -import delim "`path_data'/scenario_18`scen'_`Nn'.csv", encoding(ISO-8859-2) case(preserve) clear -rename TT tt - -* Matrice de taille 1000 * 4 items + 1 DIF + beta + std beta + 1 dif -local nbitems = 7 -local nbdif = 3 -local taillemat = 3*`nbitems'+9+2+`nbdif' -mat outmat = J(1000,`taillemat',.) -mat colnames outmat = "item1_1" "item1_2" "item1_3" "item2_1" "item2_2" "item2_3" "item3_1" "item3_2" "item3_3" "item4_1" "item4_2" "item4_3" "item5_1" "item5_2" "item5_3" "item6_1" "item6_2" "item6_3" "item7_1" "item7_2" "item7_3" "dif1_1" "dif1_2" "dif1_3" "dif2_1" "dif2_2" "dif2_3" "dif3_1" "dif3_2" "dif3_3" "beta" "se_beta" "dif_item_1" "dif_item_2" "dif_item_3" -di "Scenario 18`scen' / N=`Nnn'" -forvalues k=1/1000 { - if (mod(`k',100)==0) { - di "`k'/1000" - } - preserve - qui keep if replication==`k' - local difitems1=dif1 - local difitems2=dif2 - local difitems3=dif3 - if (`difitems1' < `difitems2') { - local difitemsmin= `difitems1' - local difitemsmax= `difitems2' - } - else { - local difitemsmin= `difitems2' - local difitemsmax= `difitems1' - } - if (`difitems3' < `difitemsmin') { - local difitemsmid = `difitemsmin' - local difitemsmin= `difitems3' - } - else if (`difitems3' > `difitemsmax') { - local difitemsmid = `difitemsmax' - local difitemsmax= `difitems3' - } - else { - local difitemsmid = `difitems3' - } - forvalues i=1/`nbitems' { - if (`i'==`difitemsmin') { - local constrnt = "constraint 1 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))" - local constrnt2 = "constraint 2 3*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([3.item`i']_cons-([3.item`i']_cons+[3.item`i'] tt))" - } - } - forvalues i=1/`nbitems' { - if (`i'==`difitemsmax') { - local constrn3 = "constraint 3 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))" - local constrnt4 = "constraint 4 3*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([3.item`i']_cons-([3.item`i']_cons+[3.item`i'] tt))" - } - } - forvalues i=1/`nbitems' { - if (`i'==`difitemsmid') { - local constrn5 = "constraint 5 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))" - local constrnt6 = "constraint 6 3*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([3.item`i']_cons-([3.item`i']_cons+[3.item`i'] tt))" - } - } - local mod "gsem " - forvalues i=1/`nbitems' { - if (`i'==`difitemsmin' | `i'==`difitemsmax' | `i'==`difitemsmid') { - local mod = "`mod'"+"(1.item`i'<-THETA@1 tt)(2.item`i'<-THETA@2 tt)(3.item`i'<-THETA@3 tt)" - } - else { - local mod = "`mod'"+"(1.item`i'<-THETA@1)(2.item`i'<-THETA@2)(3.item`i'<-THETA@3)" - } - } - local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent constraint(1 2 3 4 5 6)" - qui `constrnt' - qui `constrnt2' - qui `constrnt3' - qui `constrnt4' - qui `constrnt6' - qui `constrnt6' - qui `mod' - mat V=r(table) - mat W=V[1..2,1...] - forvalues j=1/`nbitems' { - if (`j'<`difitemsmin') { - mat outmat[`k',3*`j'-2] = W[1,7*(`j'-1)+3] // items avant le premier dif - mat outmat[`k',3*`j'-1] = W[1,7*(`j'-1)+5] // items avant le premier dif - mat outmat[`k',3*`j'] = W[1,7*(`j'-1)+7] // items avant le premier dif - } - else if (`j'==`difitemsmin') { - mat outmat[`k',3*`j'-2] = W[1,7*(`j'-1)+4] // items du le premier dif - mat outmat[`k',3*`j'-1] = W[1,7*(`j'-1)+7] // items du le premier dif - mat outmat[`k',3*`j'] = W[1,7*(`j'-1)+10] // items du le premier dif } - } - else if (`j'<`difitemsmid') { - mat outmat[`k',3*`j'-2] = W[1,7*(`j'-1)+6] // items avant le premier dif - mat outmat[`k',3*`j'-1] = W[1,7*(`j'-1)+8] // items avant le premier dif - mat outmat[`k',3*`j'] = W[1,7*(`j'-1)+10] // items avant le premier dif - } - else if (`j'==`difitemsmid') { - mat outmat[`k',3*`j'-2] = W[1,7*(`j'-1)+7] // items avant le premier dif - mat outmat[`k',3*`j'-1] = W[1,7*(`j'-1)+10] // items avant le premier dif - mat outmat[`k',3*`j'] = W[1,7*(`j'-1)+13] // items avant le premier dif - } - else if (`j'<`difitemsmax') { - mat outmat[`k',3*`j'-2] = W[1,7*(`j'-1)+9] // items avant le premier dif - mat outmat[`k',3*`j'-1] = W[1,7*(`j'-1)+11] // items avant le premier dif - mat outmat[`k',3*`j'] = W[1,7*(`j'-1)+13] // items avant le premier dif - } - else if (`j'==`difitemsmax') { - mat outmat[`k',3*`j'-2] = W[1,7*(`j'-1)+10] // items avant le premier dif - mat outmat[`k',3*`j'-1] = W[1,7*(`j'-1)+13] // items avant le premier dif - mat outmat[`k',3*`j'] = W[1,7*(`j'-1)+16] // items avant le premier dif - } - else { - mat outmat[`k',3*`j'-2] = W[1,7*(`j'-1)+12] // items avant le premier dif - mat outmat[`k',3*`j'-1] = W[1,7*(`j'-1)+14] // items avant le premier dif - mat outmat[`k',3*`j'] = W[1,7*(`j'-1)+16] // items avant le premier dif - } - } - mat outmat[`k',3*`nbitems'+1] = W[1,7*(`difitemsmin'-1)+2] // coef de dif - mat outmat[`k',3*`nbitems'+2] = W[1,7*(`difitemsmin'-1)+5] // coef de dif - mat outmat[`k',3*`nbitems'+3] = W[1,7*(`difitemsmin'-1)+8] // coef de dif - mat outmat[`k',3*`nbitems'+4] = W[1,7*(`difitemsmid'-1)+5] // coef de dif - mat outmat[`k',3*`nbitems'+5] = W[1,7*(`difitemsmid'-1)+8] // coef de dif - mat outmat[`k',3*`nbitems'+6] = W[1,7*(`difitemsmid'-1)+11] // coef de dif - mat outmat[`k',3*`nbitems'+7] = W[1,7*(`difitemsmax'-1)+8] // coef de dif - mat outmat[`k',3*`nbitems'+8] = W[1,7*(`difitemsmax'-1)+11] // coef de dif - mat outmat[`k',3*`nbitems'+9] = W[1,7*(`difitemsmax'-1)+14] // coef de dif - mat outmat[`k',3*`nbitems'+10] = W[1,7*`nbitems'+10] // beta - mat outmat[`k',3*`nbitems'+11] = W[2,7*`nbitems'+10] // se beta - mat outmat[`k',3*`nbitems'+12] = `difitemsmin' // numéro item de dif - mat outmat[`k',3*`nbitems'+13] = `difitemsmid' // numéro item de dif - mat outmat[`k',3*`nbitems'+14] = `difitemsmax' // numéro item de dif - restore -} -putexcel set "`path_res'/18`scen'_`Nn'.xls", sheet("outmat") replace -putexcel A1=matrix(outmat), colnames -} -} - -** Scenario 19: J = 7 items / M = 2 modalities / DIF size 0.5 x3 - local N = "100 200 300" - foreach Nnn in `N' { - local Nn = `Nnn' - local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N`Nn'" - local path_res = "/home/corentin/Documents/These/Recherche/Simulations/Analysis/DIF/N`Nn'" - local scenarios = "A B C D E F G" - foreach scen in `scenarios' { - clear - import delim "`path_data'/scenario_19`scen'_`Nn'.csv", encoding(ISO-8859-2) case(preserve) clear - rename TT tt - - * Matrice de taille 1000 * 4 items + 1 DIF + beta + std beta + 1 dif - local nbitems = 7 - local nbdif = 3 - local taillemat = `nbitems'+`nbdif'+5 - mat outmat = J(1000,`taillemat',.) - mat colnames outmat = "item1" "item2" "item3" "item4" "item5" "item6" "item7" "dif1" "dif2" "dif3" "beta" "se_beta" "dif_item_1" "dif_item_2" "dif_item_3" - di "Scenario 19`scen' / N=`Nnn'" - forvalues k=1/1000 { - if (mod(`k',100)==0) { - di "`k'/1000" - } - preserve - qui keep if replication==`k' - local difitems1=dif1 - local difitems2=dif2 - local difitems3=dif3 - if (`difitems1' < `difitems2') { - local difitemsmin= `difitems1' - local difitemsmax= `difitems2' - } - else { - local difitemsmin= `difitems2' - local difitemsmax= `difitems1' - } - if (`difitems3' < `difitemsmin') { - local difitemsmid = `difitemsmin' - local difitemsmin= `difitems3' - } - else if (`difitems3' > `difitemsmax') { - local difitemsmid = `difitemsmax' - local difitemsmax= `difitems3' - } - else { - local difitemsmid = `difitems3' - } - local mod "gsem " - forvalues i=1/`nbitems' { - if (`i'==`difitemsmin' | `i'==`difitemsmax' | `i'==`difitemsmid') { - local mod = "`mod'"+"(1.item`i'<-THETA@1 tt)" - } - else { - local mod = "`mod'"+"(1.item`i'<-THETA@1)" - } - } - local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent" - qui `mod' - mat V=r(table) - mat W=V[1..2,1...] - forvalues j=1/`nbitems' { - if (`j'<`difitemsmin') { - mat outmat[`k',`j'] = W[1,3*`j'] // items avant le premier dif - } - else if (`j'<`difitemsmid') { - mat outmat[`k',`j'] = W[1,1+3*`j'] // items après le premier dif - } - else if (`j'<`difitemsmax') { - mat outmat[`k',`j'] = W[1,2+3*`j'] // items après le deuxieme dif - } - else { - mat outmat[`k',`j'] = W[1,3+3*`j'] // items après le deuxieme dif - } - } - mat outmat[`k',`nbitems'+1] = W[1,3*`difitemsmin'-1] // coef de dif - mat outmat[`k',`nbitems'+2] = W[1,3*`difitemsmid'] // coef de dif - mat outmat[`k',`nbitems'+3] = W[1,3*`difitemsmax'+1] // coef de dif - mat outmat[`k',`nbitems'+4] = W[1,3*`nbitems'+4] // beta - mat outmat[`k',`nbitems'+5] = W[2,3*`nbitems'+4] // se beta - mat outmat[`k',`nbitems'+6] = `difitemsmin' // numéro item de dif - mat outmat[`k',`nbitems'+7] = `difitemsmid' // numéro item de dif - mat outmat[`k',`nbitems'+8] = `difitemsmax' // numéro item de dif - restore - } - putexcel set "`path_res'/19`scen'_`Nn'.xls", sheet("outmat") replace - putexcel A1=matrix(outmat), colnames -} -} - - - -** Scenario 20: J = 7 items / M = 4 modalities / DIF size 0.5 x3 -local N = "100 200 300" -foreach Nnn in `N' { -local Nn = `Nnn' -local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N`Nn'" -local path_res = "/home/corentin/Documents/These/Recherche/Simulations/Analysis/DIF/N`Nn'" -local scenarios = "A B C D E F G" -foreach scen in `scenarios' { -clear -import delim "`path_data'/scenario_20`scen'_`Nn'.csv", encoding(ISO-8859-2) case(preserve) clear -rename TT tt - -* Matrice de taille 1000 * 4 items + 1 DIF + beta + std beta + 1 dif -local nbitems = 7 -local nbdif = 3 -local taillemat = 3*`nbitems'+9+2+`nbdif' -mat outmat = J(1000,`taillemat',.) -mat colnames outmat = "item1_1" "item1_2" "item1_3" "item2_1" "item2_2" "item2_3" "item3_1" "item3_2" "item3_3" "item4_1" "item4_2" "item4_3" "item5_1" "item5_2" "item5_3" "item6_1" "item6_2" "item6_3" "item7_1" "item7_2" "item7_3" "dif1_1" "dif1_2" "dif1_3" "dif2_1" "dif2_2" "dif2_3" "dif3_1" "dif3_2" "dif3_3" "beta" "se_beta" "dif_item_1" "dif_item_2" "dif_item_3" -di "Scenario 20`scen' / N=`Nnn'" -forvalues k=1/1000 { - if (mod(`k',100)==0) { - di "`k'/1000" - } - preserve - qui keep if replication==`k' - local difitems1=dif1 - local difitems2=dif2 - local difitems3=dif3 - if (`difitems1' < `difitems2') { - local difitemsmin= `difitems1' - local difitemsmax= `difitems2' - } - else { - local difitemsmin= `difitems2' - local difitemsmax= `difitems1' - } - if (`difitems3' < `difitemsmin') { - local difitemsmid = `difitemsmin' - local difitemsmin= `difitems3' - } - else if (`difitems3' > `difitemsmax') { - local difitemsmid = `difitemsmax' - local difitemsmax= `difitems3' - } - else { - local difitemsmid = `difitems3' - } - forvalues i=1/`nbitems' { - if (`i'==`difitemsmin') { - local constrnt = "constraint 1 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))" - local constrnt2 = "constraint 2 3*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([3.item`i']_cons-([3.item`i']_cons+[3.item`i'] tt))" - } - } - forvalues i=1/`nbitems' { - if (`i'==`difitemsmax') { - local constrn3 = "constraint 3 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))" - local constrnt4 = "constraint 4 3*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([3.item`i']_cons-([3.item`i']_cons+[3.item`i'] tt))" - } - } - forvalues i=1/`nbitems' { - if (`i'==`difitemsmid') { - local constrn5 = "constraint 5 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))" - local constrnt6 = "constraint 6 3*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([3.item`i']_cons-([3.item`i']_cons+[3.item`i'] tt))" - } - } - local mod "gsem " - forvalues i=1/`nbitems' { - if (`i'==`difitemsmin' | `i'==`difitemsmax' | `i'==`difitemsmid') { - local mod = "`mod'"+"(1.item`i'<-THETA@1 tt)(2.item`i'<-THETA@2 tt)(3.item`i'<-THETA@3 tt)" - } - else { - local mod = "`mod'"+"(1.item`i'<-THETA@1)(2.item`i'<-THETA@2)(3.item`i'<-THETA@3)" - } - } - local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent constraint(1 2 3 4 5 6)" - qui `constrnt' - qui `constrnt2' - qui `constrnt3' - qui `constrnt4' - qui `constrnt6' - qui `constrnt6' - qui `mod' - mat V=r(table) - mat W=V[1..2,1...] - forvalues j=1/`nbitems' { - if (`j'<`difitemsmin') { - mat outmat[`k',3*`j'-2] = W[1,7*(`j'-1)+3] // items avant le premier dif - mat outmat[`k',3*`j'-1] = W[1,7*(`j'-1)+5] // items avant le premier dif - mat outmat[`k',3*`j'] = W[1,7*(`j'-1)+7] // items avant le premier dif - } - else if (`j'==`difitemsmin') { - mat outmat[`k',3*`j'-2] = W[1,7*(`j'-1)+4] // items du le premier dif - mat outmat[`k',3*`j'-1] = W[1,7*(`j'-1)+7] // items du le premier dif - mat outmat[`k',3*`j'] = W[1,7*(`j'-1)+10] // items du le premier dif } - } - else if (`j'<`difitemsmid') { - mat outmat[`k',3*`j'-2] = W[1,7*(`j'-1)+6] // items avant le premier dif - mat outmat[`k',3*`j'-1] = W[1,7*(`j'-1)+8] // items avant le premier dif - mat outmat[`k',3*`j'] = W[1,7*(`j'-1)+10] // items avant le premier dif - } - else if (`j'==`difitemsmid') { - mat outmat[`k',3*`j'-2] = W[1,7*(`j'-1)+7] // items avant le premier dif - mat outmat[`k',3*`j'-1] = W[1,7*(`j'-1)+10] // items avant le premier dif - mat outmat[`k',3*`j'] = W[1,7*(`j'-1)+13] // items avant le premier dif - } - else if (`j'<`difitemsmax') { - mat outmat[`k',3*`j'-2] = W[1,7*(`j'-1)+9] // items avant le premier dif - mat outmat[`k',3*`j'-1] = W[1,7*(`j'-1)+11] // items avant le premier dif - mat outmat[`k',3*`j'] = W[1,7*(`j'-1)+13] // items avant le premier dif - } - else if (`j'==`difitemsmax') { - mat outmat[`k',3*`j'-2] = W[1,7*(`j'-1)+10] // items avant le premier dif - mat outmat[`k',3*`j'-1] = W[1,7*(`j'-1)+13] // items avant le premier dif - mat outmat[`k',3*`j'] = W[1,7*(`j'-1)+16] // items avant le premier dif - } - else { - mat outmat[`k',3*`j'-2] = W[1,7*(`j'-1)+12] // items avant le premier dif - mat outmat[`k',3*`j'-1] = W[1,7*(`j'-1)+14] // items avant le premier dif - mat outmat[`k',3*`j'] = W[1,7*(`j'-1)+16] // items avant le premier dif - } - } - mat outmat[`k',3*`nbitems'+1] = W[1,7*(`difitemsmin'-1)+2] // coef de dif - mat outmat[`k',3*`nbitems'+2] = W[1,7*(`difitemsmin'-1)+5] // coef de dif - mat outmat[`k',3*`nbitems'+3] = W[1,7*(`difitemsmin'-1)+8] // coef de dif - mat outmat[`k',3*`nbitems'+4] = W[1,7*(`difitemsmid'-1)+5] // coef de dif - mat outmat[`k',3*`nbitems'+5] = W[1,7*(`difitemsmid'-1)+8] // coef de dif - mat outmat[`k',3*`nbitems'+6] = W[1,7*(`difitemsmid'-1)+11] // coef de dif - mat outmat[`k',3*`nbitems'+7] = W[1,7*(`difitemsmax'-1)+8] // coef de dif - mat outmat[`k',3*`nbitems'+8] = W[1,7*(`difitemsmax'-1)+11] // coef de dif - mat outmat[`k',3*`nbitems'+9] = W[1,7*(`difitemsmax'-1)+14] // coef de dif - mat outmat[`k',3*`nbitems'+10] = W[1,7*`nbitems'+10] // beta - mat outmat[`k',3*`nbitems'+11] = W[2,7*`nbitems'+10] // se beta - mat outmat[`k',3*`nbitems'+12] = `difitemsmin' // numéro item de dif - mat outmat[`k',3*`nbitems'+13] = `difitemsmid' // numéro item de dif - mat outmat[`k',3*`nbitems'+14] = `difitemsmax' // numéro item de dif - restore +*================================================================================================================================================= +* Date : 2024-01-23 +* Stata version : Stata 18 SE +* +* This program analyses simulated data accounting for DIF through a partial credit model +* +* ado-files needed : - pcm, rosali (version 5.5 October 25, 2023, available on gitea) +* +* +*================================================================================================================================================ +adopath+"/home/corentin/Documents/These/Recherche/ROSALI-SIM/Modules/rosali_custom" + + +local N = "50 100 200 300" + local ss = "1 2 3 4 5 6 7 8 9 10 11 1 13 14 15 16 17 18 19 20" + foreach s in `ss' { + foreach Nnn in `N' { + local Nn = `Nnn' + local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N`Nn'" + if (`s'<=4) { + local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N`Nn'" + } + local path_res = "/home/corentin/Documents/These/Recherche/Simulations/Analysis/ROSALI-DIF/N`Nn'" + local scenarios = "A B C D E F G" + foreach scen in `scenarios' { + clear + import delim "`path_data'/scenario_`s'`scen'_`Nn'.csv", encoding(ISO-8859-2) case(preserve) clear + rename TT tt + + if (`s'<=2) { + local nbitems=4 + } + else if (`s'<=4) { + local nbitems=7 + } + else if (`s'<=12) { + local nbitems=4 + } + else { + local nbitems=7 + } + +if (mod(`s',2)==0) { + local nbmoda=3 +} +else { + local nbmoda=1 +} + + if (`s'<=4) { + local nbdif=0 + } + else if (`s'<=8) { + local nbdif=1 + } + else if (`s'<=16) { + local nbdif=2 + } + else { + local nbdif=3 + } + * taillemat = Maximum J*M cases pour les items par et J*M cases pour les dif par + J cases pour les DIF detect + nbdif cases pour dif réel + local taillemat=2*`nbitems'*`nbmoda'+`nbitems'+`nbdif'+2 + local colna="" + forvalues i=1/`nbitems' { + forvalues z=1/`nbmoda' { + local colna = "`colna'"+"item`i'_`z' " + local colna = "`colna'"+"dif_`i'_`z' " + } + } + forvalues i=1/`nbitems' { + local colna = "`colna'"+"dif_detect_`i' " + } + + forvalues i=1/`nbdif' { + local colna = "`colna'"+"real_dif_`i' " + } +local colna = "`colna'" + "beta " + "se_beta" + + + mat outmat = J(1000,`taillemat',.) + mat colnames outmat= `colna' + di "Scenario `s'`scen' / N=`Nnn'" + forvalues k=1/1000 { + if (mod(`k',100)==0) { + di "`k'/1000" + } + preserve + qui keep if replication==`k' + + + * MERGE des modalités si non représentées + + if (`nbmoda'>1 & `Nn'==50) { + local com_z = 0 + qui gen comz = 0 + forvalues j = 1 / `nbitems' { + local recoda_`j' = 0 + qui tab item`j' if tt == 0, matrow(rect1_g0_`j') matcell(nbrt1_g0_`j') + local maxm`j'_t1_g0 = rect1_g0_`j'[r(r),1] + local minm`j'_t1_g0 = rect1_g0_`j'[1,1] + + qui tab item`j' if tt == 1, matrow(rect1_g1_`j') matcell(nbrt1_g1_`j') + local minm`j'_t1_g1 = rect1_g1_`j'[1,1] + local maxm`j'_t1_g1 = rect1_g1_`j'[r(r),1] + + local minm_`j' = min(`minm`j'_t1_g0',`minm`j'_t1_g1') + local maxm_`j' = max(`maxm`j'_t1_g0',`maxm`j'_t1_g1') + local nbm_`j' = `=`maxm_`j''-`minm_`j''' + + if `minm_`j'' != 0 & `com_z' == 0 { + local com_z = 1 + } + + qui count if item`j' == 3 & tt == 0 + local mod3plac = r(N) + qui count if item`j' == 3 & tt == 1 + local mod3tt = r(N) + local nb_rn3 = min(`mod3plac',`mod3tt') + if `nb_rn3'==0 { + qui replace comz = 1 + } + + forvalues m = 0/`=`nbm_`j''-1' { + qui count if item`j' == `m' & tt == 0 + local nb_rn1_g0 = r(N) + qui count if item`j' == `m' & tt == 1 + local nb_rn1_g1 = r(N) + local nb_rn = min(`nb_rn1_g0',`nb_rn1_g1') + if `nb_rn' == 0 { + qui replace comz = 1 + local recoda_`j' = 1 + if `m' == 0 | `m' < `minm`j'_t1_g0' | `m' < `minm`j'_t1_g1' { + local stop = 1 + forvalues kk = 1/`=`nbm_`j''-`m'' { + qui count if item`j' == `=`m' + `kk'' & tt == 0 + local v`kk'1_0 = r(N) + qui count if item`j' == `=`m' + `kk'' & tt == 1 + local v`kk'1_1 = r(N) + if (`v`kk'1_0' != 0 | `v`kk'1_1' != 0) & `stop' != 0 { + qui replace item`j'= `=`m'+`kk'' if item`j'==`m' + local zzz=`j'+`nbitems' + *qui replace item`zzz'=`=`m'+`kk'' if item``=`j'+`nbitems'''==`m' + *di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged" + local stop = 0 + } + } + } + else if `m' == `=`nbm_`j''-1' | `m' >= `maxm`j'_t1_g1' { + local stop = 1 + forvalues kk = 1/`=`m'' { + qui count if item`j' == `=`m' - `kk'' & tt == 0 + local v`kk'1_0 = r(N) + qui count if item`j' == `=`m' - `kk'' & tt == 1 + local v`kk'1_1 = r(N) + if (`v`kk'1_0' != 0 | `v`kk'1_1' != 0) & `stop' != 0 { + qui replace item`j'= `=`m' - `kk'' if item`j'==`m' + local zzz=`j'+`nbitems' + *qui replace item`zzz'= `=`m' - `kk'' if item`zzz'==`m' + *di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged" + local stop = 0 + } + } + } + else { + if runiform()>0.5{ + local stop = 1 + forvalues kk = 1/`m' { + qui count if item`j' == `=`m' - `kk'' & tt == 0 + local v`kk'1_0 = r(N) + qui count if item`j' == `=`m' - `kk'' & tt == 1 + local v`kk'1_1 = r(N) + if (`v`kk'1_0' != 0 | `v`kk'1_1' != 0) & `stop' != 0 { + qui replace item`j'= `=`m'-`kk'' if item`j'==`m' + local zzz=`j'+`nbitems' + *qui replace item`zzz'=`=`m'-`kk'' if item``=`j'+`nbitems'''==`m' + *di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged" + local stop = 0 + } + } + } + else { + local stop = 1 + forvalues kk = 1/`=`nbm_`j''-`m'' { + qui count if item`j' == `=`m' + `kk'' & tt == 0 + local v`kk'1_0 = r(N) + qui count if item`j' == `=`m' + `kk'' & tt == 1 + local v`kk'1_1 = r(N) + if (`v`kk'1_0' != 0 | `v`kk'1_1' != 0) & `stop' != 0{ + qui replace item`j'=`=`m' + `kk'' if item`j'==`m' + local zzz=`j'+`nbitems' + *qui replace item`zzz'=`=`m' + `kk'' if item``=`j'+`nbitems'''==`m' + *di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged" + local stop = 0 + } + else { + if `stop' != 0 { + qui replace item`j'= `nbm_`j'' if item`j'==`m' + local zzz=`j'+`nbitems' + *qui replace item`zzz'= `nbm_`j'' if item``=`j'+`nbitems'''==`m' + *di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged" + local stop = 0 + } + } + } + } + } + } + } + qui levelsof item`j' + local val = r(levels) + local checker: word 1 of `val' + local checker2: word 2 of `val' + local checker3: word 3 of `val' + local nummoda=r(r) + local nbmoda_`j'=`nummoda' + if (`nummoda'==2) { + qui recode item`j' (`checker'=0) (`checker2'=1) + } + if (`nummoda'==3) { + if (`checker'!=0) { + qui recode item`j' (`checker'=0) (`checker2'=1) (`checker3'=2) + } + else if (`checker2'!=1) { + qui recode item`j' (`checker2'=1) (`checker3'=2) + } + else if (`checker3'!=2) { + qui recode item`j' (`checker3'=2) + } + } + } + + qui valuesof comz + local val = r(values) + local checker: word 1 of `val' + } + else { + forvalues jj=1/`nbitems' { + local nbmoda_`jj'=`nbmoda' + } + } + + + * ROSALI + qui rosali_original item1-item`nbitems' item1-item`nbitems', group(tt) + qui mat resmat=r(difitems) + local nbitems2 = 2*`nbitems' + + * Calculer le nbre d'items détectés + local nbdetect = 0 + local stop = 0 + forvalues jj=1/`nbitems' { + if (`stop'==0) { + mat testm=J(1,1,.) + if (resmat[1,`jj']==testm[1,1]) { + local stop = 1 + local nbdetect = `jj'-1 + } + } + } + + * Stocker les items détectés + + * Définition des contraintes + local csrt=0 + mat testm=J(1,1,0) + forvalues u=1/`nbdetect' { + local difitems`u'=resmat[1,`u'] + local i=`difitems`u'' + if (`nbmoda_`i''==3 & resmat[1,`nbitems'+`i']!=testm[1,1]){ + local constrnt`u' = "constraint `u' 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))" + qui `constrnt`u'' + local v=`u'+100 + local constrnt`u'_2 = "constraint `v' 3*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([3.item`i']_cons-([3.item`i']_cons+[3.item`i'] tt))" + qui `constrnt`u'_2' + } + if (`nbmoda_`i''==2 & resmat[1,`nbitems'+`i']!=testm[1,1]){ + local constrnt`u' = "constraint `u' 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))" + qui `constrnt`u'' + } + } + + * Définition du modèle + local mod "gsem " + local conformula = "" + forvalues i=1/`nbitems' { + local mod = "`mod'"+"(1.item`i'<-THETA@1)" + if (`nbmoda_`i''==3) { + local mod = "`mod'"+"(2.item`i'<-THETA@2)(3.item`i'<-THETA@3)" + } + else if (`nbmoda_`i''==2) { + local mod = "`mod'"+"(2.item`i'<-THETA@2)" + } + } + forvalues u=1/`nbdetect' { + local v=`difitems`u'' + local mod = "`mod'"+"(1.item`v'<-THETA@1 tt)" + if (`nbmoda_`v''==3) { + local mod = "`mod'"+"(2.item`v'<-THETA@2 tt)(3.item`v'<-THETA@3 tt)" + } + else if (`nbmoda_`v''==2) { + local mod = "`mod'"+"(2.item`v'<-THETA@2 tt)" + } + local w= 100+`u' + if (resmat[1,`nbitems'+`v']!=testm[1,1] & `nbmoda_`v''==3) { + local conformula = "`conformula'" + "`u' " + "`w' " + } + else if (resmat[1,`nbitems'+`v']!=testm[1,1] & `nbmoda_`v''==2) { + local conformula = "`conformula'" + "`u' " + } + } + if ("`conformula'" != "") { + local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent constraint(`conformula')" + } + else { + local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent" + } + *calcul du modèle + qui `mod' + mat V=r(table) + mat W=V[1..2,1...] + + * compilation + forvalues j=1/`nbitems' { + forvalues z=1/`nbmoda_`j'' { + mat outmat[`k',colnumb(outmat,"item`j'_`z'")] = W[1,colnumb(W,"`z'.item`j':_cons")] + } + } + * compilation DIF + forvalues u=1/`nbdetect' { + local j=`difitems`u'' + forvalues z=1/`nbmoda_`j'' { + mat outmat[`k',colnumb(outmat,"dif_`u'_`z'")] = W[1,colnumb(W,"`z'.item`j':tt")] + mat outmat[`k',colnumb(outmat,"dif_detect_`u'")] = `j' + } + } + + * Stocker les items de DIF originaux + if (`nbdif' > 0) { + qui levelsof dif1 + local ldif1 = r(levels) + local diff1: word 1 of `ldif1' + qui mat outmat[`k',colnumb(outmat,"real_dif_1")]=`diff1' + if (`nbdif' > 1) { + qui levelsof dif2 + local ldif2 = r(levels) + local diff2: word 1 of `ldif2' + qui mat outmat[`k',colnumb(outmat,"real_dif_2")]=`diff2' + if (`nbdif' > 2) { + qui levelsof dif3 + local ldif3 = r(levels) + local diff3: word 1 of `ldif3' + qui mat outmat[`k',colnumb(outmat,"real_dif_3")]=`diff3' + } + } + } + qui mat outmat[`k',colnumb(outmat,"beta")]=W[1,colnumb(W,"THETA:tt")] + qui mat outmat[`k',colnumb(outmat,"se_beta")]=W[2,colnumb(W,"THETA:tt")] + restore + } + putexcel set "`path_res'/`s'`scen'_`Nn'_original.xls", sheet("outmat") replace + putexcel A1=matrix(outmat), colnames } -putexcel set "`path_res'/20`scen'_`Nn'.xls", sheet("outmat") replace -putexcel A1=matrix(outmat), colnames } } diff --git a/Scripts/Analysis/DIF/temp/item_merger.do b/Scripts/Analysis/DIF/merger/item_merger.do similarity index 100% rename from Scripts/Analysis/DIF/temp/item_merger.do rename to Scripts/Analysis/DIF/merger/item_merger.do