diff --git a/RProject/.RData b/RProject/.RData index fca6731..32c9193 100644 Binary files a/RProject/.RData and b/RProject/.RData differ diff --git a/RProject/.Rhistory b/RProject/.Rhistory index 8493b04..871b7c1 100644 --- a/RProject/.Rhistory +++ b/RProject/.Rhistory @@ -1,512 +1,512 @@ -## create penalization matrix -acoefs <- get_acoefs(RSM, DSF, m, I, q, n_sigma) -## update number of parameters to be optimized -px <- px + ncol(designX) -}else{ -## dummy matrix in case no covariates are specified -designX <- matrix(0,0,0) -acoefs <- matrix(0,nrow=px,ncol=1) -} -if(main.effects){ -design.main <- matrix(rep(X, each = sum(q)),ncol = ncol(X)) -designX <- cbind(design.main, designX) -acoefs <- rbind(matrix(0, ncol = ncol(acoefs), nrow = ncol(design.main)), acoefs) -px <- px + ncol(X) -} -ret.list <- list(q = q, I = I, m = m, px = px, n = n, response = response, -design = design, designX = designX, sd.vec = sd.vec, -acoefs = acoefs, n_sigma = n_sigma, x.names = x.names, -RSM = RSM, GPCM = GPCM, Y = Y, DSF = DSF) -return(ret.list) -} -create.sd.vec <- function(sd.vec, DSF, px, n_sigma, I, q, main.effects){ -if(DSF){ -new_vec <- rep(sd.vec, sum(q)) -}else{ -new_vec <- rep(sd.vec, I) -} -if(main.effects){ -new_vec <- c(sd.vec, new_vec) -} -new_vec <- c(rep(1,px-n_sigma),new_vec,rep(1,n_sigma)) -new_vec -} -GPCMlasso2(formula = cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control=ctrl_GPCMlasso(lambda=0.0000000000001),acoefs2 = u) -get_designX <- function(X, DSF, m, I, q, n){ -if(!DSF){ -designX <- matrix(0, ncol = m * I, nrow = n * sum(q)) -pos_u <- 1 -for (u in 1:n) { -for(uu in 1:I){ -designX[pos_u:(pos_u+q[uu]-1), ((uu - 1) * m + 1):(uu * m)] <- -matrix(rep(X[u,], q[uu]), byrow = TRUE, ncol = m, nrow = q[uu]) -pos_u <- pos_u+q[uu] -} -} -}else{ -designX <- matrix(0, ncol = m * sum(q), nrow = n * sum(q)) -pos_u <- 1 -for (u in 1:n) { -pos_uu <- 1 -for(uu in 1:I){ -for(uuu in 1:q[uu]){ -designX[pos_u, pos_uu:(pos_uu+m-1)] <- -X[u,] -pos_u <- pos_u+1 -pos_uu <- pos_uu+m -} -} -} -} -return(designX) -} -get_acoefs_old <- function(RSM, DSF, m, I, q, n_sigma){ -if(!DSF){ -pen1 <- diag(m*I) -}else{ -pen1 <- matrix(0,nrow=m*sum(q),ncol=m*sum(choose(q,2))) -pos1 <-1 -pos_pos <- 1 -for(u in 1:I){ -n_comb <- choose(q[u],2) -if(n_comb>0){ -combis <- combn(q[u],2)-1 -for(uuu in 1:m){ -for(uu in 1:n_comb){ -pen1[combis[1,uu]*m+pos_pos,pos1] <- 1 -pen1[combis[2,uu]*m+pos_pos,pos1] <- -1 -pos1 <- pos1+1 -} -pos_pos <- pos_pos+1 -} -pos_pos <- pos_pos+(q[u]-1)*m -} -} -pen1 <- cbind(diag(m*sum(q)),pen1) -} -if(RSM){ -acoefs <- rbind(matrix(0,nrow=q[1]+I-1,ncol=ncol(pen1)),pen1, -matrix(0, ncol = ncol(pen1), nrow = n_sigma)) -}else{ -acoefs <- rbind(matrix(0,nrow=sum(q),ncol=ncol(pen1)),pen1, -matrix(0, ncol = ncol(pen1), nrow = n_sigma)) -} -} -get_acoefs <- function(RSM, DSF, m, I, q, n_sigma){ -if(!DSF){ -pen1 <- diag(m*I) -}else{ -pen1 <- matrix(0,nrow=m*sum(q),ncol=m*sum(q-1)) -pos1 <-1 -pos_pos <- 1 -for(u in 1:I){ -n_comb <- q[u] - 1 -if(n_comb>0){ -combis <- rep(1:q[u], each = 2) -combis <- matrix(combis[-c(1,length(combis))]-1, nrow = 2) -for(uuu in 1:m){ -for(uu in 1:n_comb){ -pen1[combis[1,uu]*m+pos_pos,pos1] <- 1 -pen1[combis[2,uu]*m+pos_pos,pos1] <- -1 -pos1 <- pos1+1 -} -pos_pos <- pos_pos+1 -} -pos_pos <- pos_pos+(q[u]-1)*m -} -} -pen1 <- cbind(diag(m*sum(q)),pen1) -} -if(RSM){ -acoefs <- rbind(matrix(0,nrow=q[1]+I-1,ncol=ncol(pen1)),pen1, -matrix(0, ncol = ncol(pen1), nrow = n_sigma)) -}else{ -acoefs <- rbind(matrix(0,nrow=sum(q),ncol=ncol(pen1)),pen1, -matrix(0, ncol = ncol(pen1), nrow = n_sigma)) -} -} -GPCMlasso2(formula = cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control=ctrl_GPCMlasso(lambda=0.0000000000001),acoefs2 = u) -# Generated by using Rcpp::compileAttributes() -> do not edit by hand -# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 -loglikPCMlasso <- function(alpha, Y, X, Z, Q, q, n, I, px, GHweights, GHnodes, acoefs, lambda, lambda2, cvalue, cores, weight, n_sigma, scale_fac) { -.Call(`_GPCMlasso_loglikPCMlasso`, alpha, Y, X, Z, Q, q, n, I, px, GHweights, GHnodes, acoefs, lambda, lambda2, cvalue, cores, weight, n_sigma, scale_fac) -} -scorePCMlasso <- function(alpha, Y, X, Z, Q, q, n, I, px, GHweights, GHnodes, acoefs, lambda, lambda2, cvalue, cores, weight, n_sigma, scale_fac) { -.Call(`_GPCMlasso_scorePCMlasso`, alpha, Y, X, Z, Q, q, n, I, px, GHweights, GHnodes, acoefs, lambda, lambda2, cvalue, cores, weight, n_sigma, scale_fac) -} -loglikDIFlasso <- function(alpha, Y, X, Z, Q, q, n, I, px, GHweights, GHnodes, acoefs, lambda, lambda2, cvalue, cores, weight, n_sigma, scale_fac) { -.Call(`_GPCMlasso_loglikDIFlasso`, alpha, Y, X, Z, Q, q, n, I, px, GHweights, GHnodes, acoefs, lambda, lambda2, cvalue, cores, weight, n_sigma, scale_fac) -} -scoreDIFlasso <- function(alpha, Y, X, Z, Q, q, n, I, px, GHweights, GHnodes, acoefs, lambda, lambda2, cvalue, cores, weight, n_sigma, scale_fac) { -.Call(`_GPCMlasso_scoreDIFlasso`, alpha, Y, X, Z, Q, q, n, I, px, GHweights, GHnodes, acoefs, lambda, lambda2, cvalue, cores, weight, n_sigma, scale_fac) -} -loglikscorePCMlasso <- function(alpha, Y, X, Z, Q, q, n, I, px, GHweights, GHnodes, acoefs, lambda, lambda2, cvalue, cores, weight, n_sigma, scale_fac) { -.Call(`_GPCMlasso_loglikscorePCMlasso`, alpha, Y, X, Z, Q, q, n, I, px, GHweights, GHnodes, acoefs, lambda, lambda2, cvalue, cores, weight, n_sigma, scale_fac) -} -loglikscoreDIFlasso <- function(alpha, Y, X, Z, Q, q, n, I, px, GHweights, GHnodes, acoefs, lambda, lambda2, cvalue, cores, weight, n_sigma, scale_fac) { -.Call(`_GPCMlasso_loglikscoreDIFlasso`, alpha, Y, X, Z, Q, q, n, I, px, GHweights, GHnodes, acoefs, lambda, lambda2, cvalue, cores, weight, n_sigma, scale_fac) -} -GPCMlasso2(formula = cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control=ctrl_GPCMlasso(lambda=0.0000000000001),acoefs2 = u) -library(GPCMlasso) -trace(GPCMlasso,edit=T) -library(GPCMlasso) -View(GPCMlasso) -u -aaa -aaa <- read.csv(paste0('/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N',100,'/scenario_',"5A_100",'.csv')) -aaa <- read.csv(paste0('/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N',100,'/scenario_',"5A_100",'.csv')) -aaaa <- aaa[aaa$replication==1,] -GPCMlasso(formula=cbind('item1','item2',"item3","item4")~TT,data=aaaa,model="PCM") -GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM") -GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0.00001)) -acc <- matrix(nrow = 10,ncol=4,0) -acc -GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0.00001),acoefs2 = acc) -acc[6,1]1 -acc[6,1]<-1 -acc -acc[7,2]<-1 -acc[8,3]<-1 -acc[9,4]<-1 -acc -GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0.00001),acoefs2 = acc) -library(TAM) -tam.mml(resp=aaaa[,c('item1',"item2","item3","item4")],group=aaaa[,'TT']) -zzz <- tam.mml(resp=aaaa[,c('item1',"item2","item3","item4")],group=aaaa[,'TT']) -summary(zzz) -GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0.00001),acoefs2 = acc) -acc <- matrix(nrow = 10,ncol=4,0) -GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0.00001),acoefs2 = acc) -summary(zzz) -remove.packages(GPCMlasso) -remove.packages("GPCMlasso") -install.packages("GPCMlasso") -install.packages("GPCMlasso") -library(GPCMlasso) -View(GPCMlasso) -GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0.00001)) -tam.mml(resp=aaaa[,c('item1',"item2","item3","item4")],group=aaaa[,'TT']) -library(tam.mml) -library(TAM) -tam.mml(resp=aaaa[,c('item1',"item2","item3","item4")],group=aaaa[,'TT']) -tam.mml(resp=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.00001)) -GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0.000000000000000000001)) -remove.packages("GPCMlasso") -install.packages('/home/corentin/Documents/These/Recherche/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.000000000000000000001)) -GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0.0000000000000000000000000000000001)) -GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0.0000000000000000000000000000000001),acoefs=acc) -GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0.0000000000000000000000000000000001),acoefs2=acc) -View(GPCMlasso) -library(GPCMlasso) -View(GPCMlasso) -aaa <- read.csv(paste0('/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N',100,'/scenario_',"5A_100",'.csv')) -aaa <- read.csv(paste0('/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N',100,'/scenario_',"5A_100",'.csv')) -aaaa <- aaa[aaa$replication==1,] -acc <- matrix(nrow = 10,ncol=4,0) -GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0.0000000000000000000000000000000001),acoefs2=acc) -acc[6,1] <- 1;acc[7,2] <- 1;acc[8,3] <- 1;acc[9,4] <- 1 -acc -GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0.0000000000000000000000000000000001),acoefs2=acc) -remove.packages("GPCMlasso") -install.packages('/home/corentin/Documents/These/Recherche/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.0000000000000000000000000000000001)) -GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 100)) -GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 1000)) -GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0.0000000000000000000000000000000001)) -GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0.0000000000000000000000000000000001))$coefficients -install.packages("geoR") -library(geoR) -nlmP -nlmP() -.nlmP() -geoR::.nlmP -remove.packages("GPCMlasso") -install.packages('/home/corentin/Documents/These/Recherche/GPCMlasso_0.1-7.tar.gz') -install.packages('/home/corentin/Documents/These/Recherche/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.0000000000000000000000000000000001)) -remove.packages("GPCMlasso") -install.packages('/home/corentin/Documents/These/Recherche/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.0000000000000000000000000000000001)) -GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0.0000000000000000000000000000000001))$design_list -GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0.0000000000000000000000000000000001),DSF = T) -summary(GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0.0000000000000000000000000000000001),DSF = T)) -GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0.0000000000000000000000000000000001),DSF = T) -GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0.0000000000000000000000000000000001),DSF = F) -library(TAM) -tam.mml(resp = aaaa[,c("item1","item2","item3","item4")],group=aaaa[,"TT"],irtmodel="PCM2") -summary(tam.mml(resp = aaaa[,c("item1","item2","item3","item4")],group=aaaa[,"TT"],irtmodel="PCM2")) -GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0.0000000000000000000000000000000001),DSF = F) -summary(tam.mml(resp = aaaa[,c("item1","item2","item3","item4")],group=aaaa[,"TT"],irtmodel="PCM2")) -GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0.0000000000000000000000000000000001),DSF = F) -summary(tam.mml(resp = aaaa[,c("item1","item2","item3","item4")],group=aaaa[,"TT"],irtmodel="PCM2")) -summary(tam.jml(resp = aaaa[,c("item1","item2","item3","item4")],group=aaaa[,"TT"],irtmodel="PCM2")) -summary(tam.jml(resp = aaaa[,c("item1","item2","item3","item4")],group=aaaa[,"TT"])) -summary(tam(resp = 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.0000000000000000000000000000000001),DSF = F) -GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0.0000000000000000000000000000000001),DSF = F,cv=F) -GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0.0000000000000000000001),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) -GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 1),DSF = F,cv=F) -summary(tam(resp = 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 = 1),DSF = F,cv=F) -GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0.5),DSF = F,cv=F) -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.01),DSF = F,cv=F) -GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0.001),DSF = F,cv=F) -GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0.0001),DSF = F,cv=F) -GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0.00000001),DSF = F,cv=F) -GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0.0000001),DSF = F,cv=F) -GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0.01),DSF = F,cv=F) -GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0.00001),DSF = F,cv=F) -GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0.00000001),DSF = F,cv=F) -GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0.0000001),DSF = F,cv=F) -GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0.0000005),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)$design_list -install.packages('/home/corentin/Documents/These/Recherche/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) -remove.packages('GPCMlasso') -install.packages('/home/corentin/Documents/These/Recherche/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 = 0),DSF = F,cv=F)$design_list -remove.packages("PCMlasso") -remove.packages("GPCMlasso") -install.packages('/home/corentin/Documents/These/Recherche/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)$design_list -library(GPCMlasso) -GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0),DSF = F,cv=F)$design_list -GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0),DSF = F,cv=F) -remove.packages("GPCMlasso") -install.packages('/home/corentin/Documents/These/Recherche/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 = 0),DSF = F,cv=F)$design_list -remove.packages("GPCMlasso") -install.packages('/home/corentin/Documents/These/Recherche/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:item1,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0),DSF = F,cv=F) -GPCMlasso(formula=cbind(item1,item2,item3,item4)~I(TT:item1*0),data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0),DSF = F,cv=F) -GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT:item1*0,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0),DSF = F,cv=F) -aaaa$item1tt <- 1-aaaa$item1 -GPCMlasso(formula=cbind(item1,item2,item3,item4)~TT:item1tt,data=aaaa,model="PCM",control = ctrl_GPCMlasso(lambda = 0),DSF = F,cv=F) -aaaa$item2tt <- 1-aaaa$item2 -aaaa$item3tt <- 1-aaaa$item3 -aaaa$item1 -aaaa$item4tt <- 1-aaaa$item4 -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+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) wwwwww <- read.csv('/home/corentin/Documents/These/Recherche/Simulations/Analysis/RESALI/Detection_data/3A_200.csv') table(wwwwww$dif.detect.1) table(wwwwww$dif.detect.1)/400 sum(table(wwwwww$dif.detect.1)/400) +results <- c(sapply(1:4,function(x) paste0(x,c('A','B','C','D','E'))),sapply(5:9,function(x) paste0(x,c('A','B','C','D','E','F','G')))) +results2 <- c(sapply(10:20,function(x) paste0(x,c('A','B','C','D','E','F','G')))) +results <- c(sapply(c(50,100,200,300),function(x) paste0(results,'_',x))) +results2 <- c(sapply(c(50,100,200,300),function(x) paste0(results2,'_',x))) +results <- sort(results) +results2 <- sort(results2) +results <- c(results,results2) +## Importer l'analyse resali pour chaque scenario +for (r in results[473:length(results)]) { +cat('--------------------------------------------------------------------------\n') +cat(paste0(r,"\n")) +cat('--------------------------------------------------------------------------\n') +#### Importer les datas +scen <- as.numeric(gsub("[A,B,C,D,E,F,G,_]","",substr(r,0,3))) +if (substr(r,start=nchar(r)-1,stop=nchar(r))=="50") { +N <- 50 +} +if (substr(r,start=nchar(r)-2,stop=nchar(r))=="100") { +N <- 100 +} +if (substr(r,start=nchar(r)-2,stop=nchar(r))=="200") { +N <- 200 +} +if (substr(r,start=nchar(r)-2,stop=nchar(r))=="300") { +N <- 300 +} +if (scen<5) { +datt <- read.csv(paste0('/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N',N,'/scenario_',r,'.csv')) +} +if (scen>=5) { +datt <- read.csv(paste0('/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N',N,'/scenario_',r,'.csv')) +} +#### Importer l'analyse +analyse <- read.csv(paste0('/home/corentin/Documents/These/Recherche/Simulations/Analysis/RESALI/Detection/',r,".csv")) +#### Pour chaque replication +for (k in 1:1000) { +if (k%%100==0) { +cat(paste0("N = ",k," / 1000\n")) +} +datt[datt$replication==k,"dif.detect.1"] <- analyse[analyse$X==k,"dif.detect.1"] +datt[datt$replication==k,"dif.detect.2"] <- analyse[analyse$X==k,"dif.detect.2"] +datt[datt$replication==k,"dif.detect.3"] <- analyse[analyse$X==k,"dif.detect.3"] +datt[datt$replication==k,"dif.detect.4"] <- analyse[analyse$X==k,"dif.detect.4"] +datt[datt$replication==k,"dif.detect.unif.1"] <- analyse[analyse$X==k,"dif.detect.unif.1"] +datt[datt$replication==k,"dif.detect.unif.2"] <- analyse[analyse$X==k,"dif.detect.unif.2"] +datt[datt$replication==k,"dif.detect.unif.3"] <- analyse[analyse$X==k,"dif.detect.unif.3"] +datt[datt$replication==k,"dif.detect.unif.4"] <- analyse[analyse$X==k,"dif.detect.unif.4"] +if (scen==3 | scen==4 | scen>=13) { +datt[datt$replication==k,"dif.detect.5"] <- analyse[analyse$X==k,"dif.detect.5"] +datt[datt$replication==k,"dif.detect.6"] <- analyse[analyse$X==k,"dif.detect.6"] +datt[datt$replication==k,"dif.detect.7"] <- analyse[analyse$X==k,"dif.detect.7"] +datt[datt$replication==k,"dif.detect.unif.5"] <- analyse[analyse$X==k,"dif.detect.unif.5"] +datt[datt$replication==k,"dif.detect.unif.6"] <- analyse[analyse$X==k,"dif.detect.unif.6"] +datt[datt$replication==k,"dif.detect.unif.7"] <- analyse[analyse$X==k,"dif.detect.unif.7"] +} +} +datt[is.na(datt$dif.detect.1),"dif.detect.1"] <- "" +datt[is.na(datt$dif.detect.2),"dif.detect.2"] <- "" +datt[is.na(datt$dif.detect.3),"dif.detect.3"] <- "" +datt[is.na(datt$dif.detect.4),"dif.detect.4"] <- "" +datt[is.na(datt$dif.detect.unif.1),"dif.detect.unif.1"] <- "" +datt[is.na(datt$dif.detect.unif.2),"dif.detect.unif.2"] <- "" +datt[is.na(datt$dif.detect.unif.3),"dif.detect.unif.3"] <- "" +datt[is.na(datt$dif.detect.unif.4),"dif.detect.unif.4"] <- "" +if (scen==3 | scen==4 | scen>=13) { +datt[is.na(datt$dif.detect.5),"dif.detect.5"] <- "" +datt[is.na(datt$dif.detect.6),"dif.detect.6"] <- "" +datt[is.na(datt$dif.detect.7),"dif.detect.7"] <- "" +datt[is.na(datt$dif.detect.unif.5),"dif.detect.unif.5"] <- "" +datt[is.na(datt$dif.detect.unif.6),"dif.detect.unif.6"] <- "" +datt[is.na(datt$dif.detect.unif.7),"dif.detect.unif.7"] <- "" +} +write.csv(datt,paste0("/home/corentin/Documents/These/Recherche/Simulations/Analysis/RESALI/Detection_data/",r,".csv")) +} +results <- c(sapply(1:4,function(x) paste0(x,c('A','B','C','D','E'))),sapply(5:9,function(x) paste0(x,c('A','B','C','D','E','F','G')))) +results2 <- c(sapply(10:20,function(x) paste0(x,c('A','B','C','D','E','F','G')))) +results <- c(sapply(c(50,100,200,300),function(x) paste0(results,'_',x))) +results2 <- c(sapply(c(50,100,200,300),function(x) paste0(results2,'_',x))) +results <- sort(results) +results2 <- sort(results2) +results <- c(results,results2) +## Importer l'analyse resali pour chaque scenario +for (r in results) { +cat('--------------------------------------------------------------------------\n') +cat(paste0(r,"\n")) +cat('--------------------------------------------------------------------------\n') +#### Importer les datas +scen <- as.numeric(gsub("[A,B,C,D,E,F,G,_]","",substr(r,0,3))) +if (substr(r,start=nchar(r)-1,stop=nchar(r))=="50") { +N <- 50 +} +if (substr(r,start=nchar(r)-2,stop=nchar(r))=="100") { +N <- 100 +} +if (substr(r,start=nchar(r)-2,stop=nchar(r))=="200") { +N <- 200 +} +if (substr(r,start=nchar(r)-2,stop=nchar(r))=="300") { +N <- 300 +} +if (scen<5) { +datt <- read.csv(paste0('/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N',N,'/scenario_',r,'.csv')) +} +if (scen>=5) { +datt <- read.csv(paste0('/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N',N,'/scenario_',r,'.csv')) +} +#### Importer l'analyse +analyse <- read.csv(paste0('/home/corentin/Documents/These/Recherche/Simulations/Analysis/RESALI/Detection/',r,".csv")) +#### Pour chaque replication +for (k in 1:1000) { +if (k%%100==0) { +cat(paste0("N = ",k," / 1000\n")) +} +datt[datt$replication==k,"dif.detect.1"] <- analyse[analyse$X==k,"dif.detect.1"] +datt[datt$replication==k,"dif.detect.2"] <- analyse[analyse$X==k,"dif.detect.2"] +datt[datt$replication==k,"dif.detect.3"] <- analyse[analyse$X==k,"dif.detect.3"] +datt[datt$replication==k,"dif.detect.4"] <- analyse[analyse$X==k,"dif.detect.4"] +datt[datt$replication==k,"dif.detect.unif.1"] <- analyse[analyse$X==k,"dif.detect.unif.1"] +datt[datt$replication==k,"dif.detect.unif.2"] <- analyse[analyse$X==k,"dif.detect.unif.2"] +datt[datt$replication==k,"dif.detect.unif.3"] <- analyse[analyse$X==k,"dif.detect.unif.3"] +datt[datt$replication==k,"dif.detect.unif.4"] <- analyse[analyse$X==k,"dif.detect.unif.4"] +if (scen==3 | scen==4 | scen>=13) { +datt[datt$replication==k,"dif.detect.5"] <- analyse[analyse$X==k,"dif.detect.5"] +datt[datt$replication==k,"dif.detect.6"] <- analyse[analyse$X==k,"dif.detect.6"] +datt[datt$replication==k,"dif.detect.7"] <- analyse[analyse$X==k,"dif.detect.7"] +datt[datt$replication==k,"dif.detect.unif.5"] <- analyse[analyse$X==k,"dif.detect.unif.5"] +datt[datt$replication==k,"dif.detect.unif.6"] <- analyse[analyse$X==k,"dif.detect.unif.6"] +datt[datt$replication==k,"dif.detect.unif.7"] <- analyse[analyse$X==k,"dif.detect.unif.7"] +} +} +datt[is.na(datt$dif.detect.1),"dif.detect.1"] <- "" +datt[is.na(datt$dif.detect.2),"dif.detect.2"] <- "" +datt[is.na(datt$dif.detect.3),"dif.detect.3"] <- "" +datt[is.na(datt$dif.detect.4),"dif.detect.4"] <- "" +datt[is.na(datt$dif.detect.unif.1),"dif.detect.unif.1"] <- "" +datt[is.na(datt$dif.detect.unif.2),"dif.detect.unif.2"] <- "" +datt[is.na(datt$dif.detect.unif.3),"dif.detect.unif.3"] <- "" +datt[is.na(datt$dif.detect.unif.4),"dif.detect.unif.4"] <- "" +if (scen==3 | scen==4 | scen>=13) { +datt[is.na(datt$dif.detect.5),"dif.detect.5"] <- "" +datt[is.na(datt$dif.detect.6),"dif.detect.6"] <- "" +datt[is.na(datt$dif.detect.7),"dif.detect.7"] <- "" +datt[is.na(datt$dif.detect.unif.5),"dif.detect.unif.5"] <- "" +datt[is.na(datt$dif.detect.unif.6),"dif.detect.unif.6"] <- "" +datt[is.na(datt$dif.detect.unif.7),"dif.detect.unif.7"] <- "" +} +write.csv(datt,paste0("/home/corentin/Documents/These/Recherche/Simulations/Analysis/RESALI/Detection_data/",r,".csv")) +} +for (r in results) { +cat('--------------------------------------------------------------------------\n') +cat(paste0(r,"\n")) +cat('--------------------------------------------------------------------------\n') +#### Importer les datas +scen <- as.numeric(gsub("[A,B,C,D,E,F,G,_]","",substr(r,0,3))) +if (substr(r,start=nchar(r)-1,stop=nchar(r))=="50") { +N <- 50 +} +if (substr(r,start=nchar(r)-2,stop=nchar(r))=="100") { +N <- 100 +} +if (substr(r,start=nchar(r)-2,stop=nchar(r))=="200") { +N <- 200 +} +if (substr(r,start=nchar(r)-2,stop=nchar(r))=="300") { +N <- 300 +} +#### Importer l'analyse +analyse <- read.csv(paste0("/home/corentin/Documents/These/Recherche/Simulations/Analysis/RESALI/Detection_data/",r,".csv")) +names(analyse)[names(analyse)=="dif.detect.1"] <- "dif_detect_1" +names(analyse)[names(analyse)=="dif.detect.2"] <- "dif_detect_2" +names(analyse)[names(analyse)=="dif.detect.3"] <- "dif_detect_3" +names(analyse)[names(analyse)=="dif.detect.4"] <- "dif_detect_4" +names(analyse)[names(analyse)=="dif.detect.unif.1"] <- "dif_detect_unif_1" +names(analyse)[names(analyse)=="dif.detect.unif.2"] <- "dif_detect_unif_2" +names(analyse)[names(analyse)=="dif.detect.unif.3"] <- "dif_detect_unif_3" +names(analyse)[names(analyse)=="dif.detect.unif.4"] <- "dif_detect_unif_4" +analyse[analyse$dif_detect_1==999,"dif_detect_1"] <- "" +analyse[analyse$dif_detect_2==999,"dif_detect_2"] <- "" +analyse[analyse$dif_detect_3==999,"dif_detect_3"] <- "" +analyse[analyse$dif_detect_4==999,"dif_detect_4"] <- "" +analyse[analyse$dif_detect_unif_1==999,"dif_detect_unif_1"] <- "" +analyse[analyse$dif_detect_unif_2==999,"dif_detect_unif_2"] <- "" +analyse[analyse$dif_detect_unif_3==999,"dif_detect_unif_3"] <- "" +analyse[analyse$dif_detect_unif_4==999,"dif_detect_unif_4"] <- "" +if (scen==3 | scen==4 | scen>=13) { +names(analyse)[names(analyse)=="dif.detect.5"] <- "dif_detect_5" +names(analyse)[names(analyse)=="dif.detect.6"] <- "dif_detect_6" +names(analyse)[names(analyse)=="dif.detect.7"] <- "dif_detect_7" +names(analyse)[names(analyse)=="dif.detect.unif.5"] <- "dif_detect_unif_5" +names(analyse)[names(analyse)=="dif.detect.unif.6"] <- "dif_detect_unif_6" +names(analyse)[names(analyse)=="dif.detect.unif.7"] <- "dif_detect_unif_7" +analyse[analyse$dif_detect_5==999,"dif_detect_5"] <- "" +analyse[analyse$dif_detect_6==999,"dif_detect_6"] <- "" +analyse[analyse$dif_detect_7==999,"dif_detect_7"] <- "" +analyse[analyse$dif_detect_unif_5==999,"dif_detect_unif_5"] <- "" +analyse[analyse$dif_detect_unif_6==999,"dif_detect_unif_6"] <- "" +analyse[analyse$dif_detect_unif_7==999,"dif_detect_unif_7"] <- "" +} +analyse <- analyse[,!names(analyse) %in% c("X","X.1","X.2")] +write.csv(analyse,paste0("/home/corentin/Documents/These/Recherche/Simulations/Analysis/RESALI/Detection_data/",r,".csv")) +} +for (r in results[-c(1:4)]) { +cat('--------------------------------------------------------------------------\n') +cat(paste0(r,"\n")) +cat('--------------------------------------------------------------------------\n') +#### Importer les datas +scen <- as.numeric(gsub("[A,B,C,D,E,F,G,_]","",substr(r,0,3))) +if (substr(r,start=nchar(r)-1,stop=nchar(r))=="50") { +N <- 50 +} +if (substr(r,start=nchar(r)-2,stop=nchar(r))=="100") { +N <- 100 +} +if (substr(r,start=nchar(r)-2,stop=nchar(r))=="200") { +N <- 200 +} +if (substr(r,start=nchar(r)-2,stop=nchar(r))=="300") { +N <- 300 +} +#### Importer l'analyse +analyse <- read.csv(paste0("/home/corentin/Documents/These/Recherche/Simulations/Analysis/RESALI/Detection_data/",r,".csv")) +names(analyse)[names(analyse)=="dif.detect.1"] <- "dif_detect_1" +names(analyse)[names(analyse)=="dif.detect.2"] <- "dif_detect_2" +names(analyse)[names(analyse)=="dif.detect.3"] <- "dif_detect_3" +names(analyse)[names(analyse)=="dif.detect.4"] <- "dif_detect_4" +names(analyse)[names(analyse)=="dif.detect.unif.1"] <- "dif_detect_unif_1" +names(analyse)[names(analyse)=="dif.detect.unif.2"] <- "dif_detect_unif_2" +names(analyse)[names(analyse)=="dif.detect.unif.3"] <- "dif_detect_unif_3" +names(analyse)[names(analyse)=="dif.detect.unif.4"] <- "dif_detect_unif_4" +analyse[analyse$dif_detect_1==999,"dif_detect_1"] <- "" +analyse[analyse$dif_detect_2==999,"dif_detect_2"] <- "" +analyse[analyse$dif_detect_3==999,"dif_detect_3"] <- "" +analyse[analyse$dif_detect_4==999,"dif_detect_4"] <- "" +analyse[analyse$dif_detect_unif_1==999,"dif_detect_unif_1"] <- "" +analyse[analyse$dif_detect_unif_2==999,"dif_detect_unif_2"] <- "" +analyse[analyse$dif_detect_unif_3==999,"dif_detect_unif_3"] <- "" +analyse[analyse$dif_detect_unif_4==999,"dif_detect_unif_4"] <- "" +if (scen==3 | scen==4 | scen>=13) { +names(analyse)[names(analyse)=="dif.detect.5"] <- "dif_detect_5" +names(analyse)[names(analyse)=="dif.detect.6"] <- "dif_detect_6" +names(analyse)[names(analyse)=="dif.detect.7"] <- "dif_detect_7" +names(analyse)[names(analyse)=="dif.detect.unif.5"] <- "dif_detect_unif_5" +names(analyse)[names(analyse)=="dif.detect.unif.6"] <- "dif_detect_unif_6" +names(analyse)[names(analyse)=="dif.detect.unif.7"] <- "dif_detect_unif_7" +analyse[analyse$dif_detect_5==999,"dif_detect_5"] <- "" +analyse[analyse$dif_detect_6==999,"dif_detect_6"] <- "" +analyse[analyse$dif_detect_7==999,"dif_detect_7"] <- "" +analyse[analyse$dif_detect_unif_5==999,"dif_detect_unif_5"] <- "" +analyse[analyse$dif_detect_unif_6==999,"dif_detect_unif_6"] <- "" +analyse[analyse$dif_detect_unif_7==999,"dif_detect_unif_7"] <- "" +} +analyse <- analyse[,!names(analyse) %in% c("X","X.1","X.2")] +write.csv(analyse,paste0("/home/corentin/Documents/These/Recherche/Simulations/Analysis/RESALI/Detection_data/",r,".csv")) +} +for (r in results) { +cat('--------------------------------------------------------------------------\n') +cat(paste0(r,"\n")) +cat('--------------------------------------------------------------------------\n') +#### Importer les datas +scen <- as.numeric(gsub("[A,B,C,D,E,F,G,_]","",substr(r,0,3))) +if (substr(r,start=nchar(r)-1,stop=nchar(r))=="50") { +N <- 50 +} +if (substr(r,start=nchar(r)-2,stop=nchar(r))=="100") { +N <- 100 +} +if (substr(r,start=nchar(r)-2,stop=nchar(r))=="200") { +N <- 200 +} +if (substr(r,start=nchar(r)-2,stop=nchar(r))=="300") { +N <- 300 +} +#### Importer l'analyse +analyse <- read.csv(paste0("/home/corentin/Documents/These/Recherche/Simulations/Analysis/RESALI/Detection_data/",r,".csv")) +names(analyse)[names(analyse)=="dif.detect.1"] <- "dif_detect_1" +names(analyse)[names(analyse)=="dif.detect.2"] <- "dif_detect_2" +names(analyse)[names(analyse)=="dif.detect.3"] <- "dif_detect_3" +names(analyse)[names(analyse)=="dif.detect.4"] <- "dif_detect_4" +names(analyse)[names(analyse)=="dif.detect.unif.1"] <- "dif_detect_unif_1" +names(analyse)[names(analyse)=="dif.detect.unif.2"] <- "dif_detect_unif_2" +names(analyse)[names(analyse)=="dif.detect.unif.3"] <- "dif_detect_unif_3" +names(analyse)[names(analyse)=="dif.detect.unif.4"] <- "dif_detect_unif_4" +if (scen==3 | scen==4 | scen>=13) { +names(analyse)[names(analyse)=="dif.detect.5"] <- "dif_detect_5" +names(analyse)[names(analyse)=="dif.detect.6"] <- "dif_detect_6" +names(analyse)[names(analyse)=="dif.detect.7"] <- "dif_detect_7" +names(analyse)[names(analyse)=="dif.detect.unif.5"] <- "dif_detect_unif_5" +names(analyse)[names(analyse)=="dif.detect.unif.6"] <- "dif_detect_unif_6" +names(analyse)[names(analyse)=="dif.detect.unif.7"] <- "dif_detect_unif_7" +#analyse[analyse$dif_detect_5==999,"dif_detect_5"] <- "" +#analyse[analyse$dif_detect_6==999,"dif_detect_6"] <- "" +#analyse[analyse$dif_detect_7==999,"dif_detect_7"] <- "" +#analyse[analyse$dif_detect_unif_5==999,"dif_detect_unif_5"] <- "" +#analyse[analyse$dif_detect_unif_6==999,"dif_detect_unif_6"] <- "" +#analyse[analyse$dif_detect_unif_7==999,"dif_detect_unif_7"] <- "" +} +analyse <- analyse[,!names(analyse) %in% c("X","X.1","X.2")] +write.csv(analyse,paste0("/home/corentin/Documents/These/Recherche/Simulations/Analysis/RESALI/Detection_data/",r,".csv")) +} +for (r in results[-c(1:4)]) { +cat('--------------------------------------------------------------------------\n') +cat(paste0(r,"\n")) +cat('--------------------------------------------------------------------------\n') +#### Importer les datas +scen <- as.numeric(gsub("[A,B,C,D,E,F,G,_]","",substr(r,0,3))) +if (substr(r,start=nchar(r)-1,stop=nchar(r))=="50") { +N <- 50 +} +if (substr(r,start=nchar(r)-2,stop=nchar(r))=="100") { +N <- 100 +} +if (substr(r,start=nchar(r)-2,stop=nchar(r))=="200") { +N <- 200 +} +if (substr(r,start=nchar(r)-2,stop=nchar(r))=="300") { +N <- 300 +} +#### Importer l'analyse +analyse <- read.csv(paste0("/home/corentin/Documents/These/Recherche/Simulations/Analysis/RESALI/Detection_data/",r,".csv")) +names(analyse)[names(analyse)=="dif.detect.1"] <- "dif_detect_1" +names(analyse)[names(analyse)=="dif.detect.2"] <- "dif_detect_2" +names(analyse)[names(analyse)=="dif.detect.3"] <- "dif_detect_3" +names(analyse)[names(analyse)=="dif.detect.4"] <- "dif_detect_4" +names(analyse)[names(analyse)=="dif.detect.unif.1"] <- "dif_detect_unif_1" +names(analyse)[names(analyse)=="dif.detect.unif.2"] <- "dif_detect_unif_2" +names(analyse)[names(analyse)=="dif.detect.unif.3"] <- "dif_detect_unif_3" +names(analyse)[names(analyse)=="dif.detect.unif.4"] <- "dif_detect_unif_4" +analyse[analyse$dif_detect_1==999,"dif_detect_1"] <- "" +analyse[analyse$dif_detect_2==999,"dif_detect_2"] <- "" +analyse[analyse$dif_detect_3==999,"dif_detect_3"] <- "" +analyse[analyse$dif_detect_4==999,"dif_detect_4"] <- "" +analyse[analyse$dif_detect_unif_1==999,"dif_detect_unif_1"] <- "" +analyse[analyse$dif_detect_unif_2==999,"dif_detect_unif_2"] <- "" +analyse[analyse$dif_detect_unif_3==999,"dif_detect_unif_3"] <- "" +analyse[analyse$dif_detect_unif_4==999,"dif_detect_unif_4"] <- "" +if (scen==3 | scen==4 | scen>=13) { +names(analyse)[names(analyse)=="dif.detect.5"] <- "dif_detect_5" +names(analyse)[names(analyse)=="dif.detect.6"] <- "dif_detect_6" +names(analyse)[names(analyse)=="dif.detect.7"] <- "dif_detect_7" +names(analyse)[names(analyse)=="dif.detect.unif.5"] <- "dif_detect_unif_5" +names(analyse)[names(analyse)=="dif.detect.unif.6"] <- "dif_detect_unif_6" +names(analyse)[names(analyse)=="dif.detect.unif.7"] <- "dif_detect_unif_7" +analyse[analyse$dif_detect_5==999,"dif_detect_5"] <- "" +analyse[analyse$dif_detect_6==999,"dif_detect_6"] <- "" +analyse[analyse$dif_detect_7==999,"dif_detect_7"] <- "" +analyse[analyse$dif_detect_unif_5==999,"dif_detect_unif_5"] <- "" +analyse[analyse$dif_detect_unif_6==999,"dif_detect_unif_6"] <- "" +analyse[analyse$dif_detect_unif_7==999,"dif_detect_unif_7"] <- "" +} +analyse <- analyse[,!names(analyse) %in% c("X","X.1","X.2")] +write.csv(analyse,paste0("/home/corentin/Documents/These/Recherche/Simulations/Analysis/RESALI/Detection_data/",r,".csv")) +} +for (r in results) { +cat('--------------------------------------------------------------------------\n') +cat(paste0(r,"\n")) +cat('--------------------------------------------------------------------------\n') +#### Importer les datas +scen <- as.numeric(gsub("[A,B,C,D,E,F,G,_]","",substr(r,0,3))) +if (substr(r,start=nchar(r)-1,stop=nchar(r))=="50") { +N <- 50 +} +if (substr(r,start=nchar(r)-2,stop=nchar(r))=="100") { +N <- 100 +} +if (substr(r,start=nchar(r)-2,stop=nchar(r))=="200") { +N <- 200 +} +if (substr(r,start=nchar(r)-2,stop=nchar(r))=="300") { +N <- 300 +} +#### Importer l'analyse +analyse <- read.csv(paste0("/home/corentin/Documents/These/Recherche/Simulations/Analysis/RESALI/Detection_data/",r,".csv")) +names(analyse)[names(analyse)=="dif.detect.1"] <- "dif_detect_1" +names(analyse)[names(analyse)=="dif.detect.2"] <- "dif_detect_2" +names(analyse)[names(analyse)=="dif.detect.3"] <- "dif_detect_3" +names(analyse)[names(analyse)=="dif.detect.4"] <- "dif_detect_4" +names(analyse)[names(analyse)=="dif.detect.unif.1"] <- "dif_detect_unif_1" +names(analyse)[names(analyse)=="dif.detect.unif.2"] <- "dif_detect_unif_2" +names(analyse)[names(analyse)=="dif.detect.unif.3"] <- "dif_detect_unif_3" +names(analyse)[names(analyse)=="dif.detect.unif.4"] <- "dif_detect_unif_4" +analyse[analyse$dif_detect_1==999,"dif_detect_1"] <- "" +analyse[analyse$dif_detect_2==999,"dif_detect_2"] <- "" +analyse[analyse$dif_detect_3==999,"dif_detect_3"] <- "" +analyse[analyse$dif_detect_4==999,"dif_detect_4"] <- "" +analyse[analyse$dif_detect_unif_1==999,"dif_detect_unif_1"] <- "" +analyse[analyse$dif_detect_unif_2==999,"dif_detect_unif_2"] <- "" +analyse[analyse$dif_detect_unif_3==999,"dif_detect_unif_3"] <- "" +analyse[analyse$dif_detect_unif_4==999,"dif_detect_unif_4"] <- "" +if (scen==3 | scen==4 | scen>=13) { +names(analyse)[names(analyse)=="dif.detect.5"] <- "dif_detect_5" +names(analyse)[names(analyse)=="dif.detect.6"] <- "dif_detect_6" +names(analyse)[names(analyse)=="dif.detect.7"] <- "dif_detect_7" +names(analyse)[names(analyse)=="dif.detect.unif.5"] <- "dif_detect_unif_5" +names(analyse)[names(analyse)=="dif.detect.unif.6"] <- "dif_detect_unif_6" +names(analyse)[names(analyse)=="dif.detect.unif.7"] <- "dif_detect_unif_7" +analyse[analyse$dif_detect_5==999,"dif_detect_5"] <- "" +analyse[analyse$dif_detect_6==999,"dif_detect_6"] <- "" +analyse[analyse$dif_detect_7==999,"dif_detect_7"] <- "" +analyse[analyse$dif_detect_unif_5==999,"dif_detect_unif_5"] <- "" +analyse[analyse$dif_detect_unif_6==999,"dif_detect_unif_6"] <- "" +analyse[analyse$dif_detect_unif_7==999,"dif_detect_unif_7"] <- "" +} +analyse[is.na(analyse)] <- "" +analyse <- analyse[,!names(analyse) %in% c("X","X.1","X.2")] +write.csv(analyse,paste0("/home/corentin/Documents/These/Recherche/Simulations/Analysis/RESALI/Detection_data/",r,".csv")) +} +for (r in results) { +cat('--------------------------------------------------------------------------\n') +cat(paste0(r,"\n")) +cat('--------------------------------------------------------------------------\n') +#### Importer les datas +scen <- as.numeric(gsub("[A,B,C,D,E,F,G,_]","",substr(r,0,3))) +if (substr(r,start=nchar(r)-1,stop=nchar(r))=="50") { +N <- 50 +} +if (substr(r,start=nchar(r)-2,stop=nchar(r))=="100") { +N <- 100 +} +if (substr(r,start=nchar(r)-2,stop=nchar(r))=="200") { +N <- 200 +} +if (substr(r,start=nchar(r)-2,stop=nchar(r))=="300") { +N <- 300 +} +#### Importer l'analyse +analyse <- read.csv(paste0("/home/corentin/Documents/These/Recherche/Simulations/Analysis/RESALI/Detection_data/",r,".csv")) +analyse[is.na(analyse)] <- "" +names(analyse)[names(analyse)=="dif.detect.1"] <- "dif_detect_1" +names(analyse)[names(analyse)=="dif.detect.2"] <- "dif_detect_2" +names(analyse)[names(analyse)=="dif.detect.3"] <- "dif_detect_3" +names(analyse)[names(analyse)=="dif.detect.4"] <- "dif_detect_4" +names(analyse)[names(analyse)=="dif.detect.unif.1"] <- "dif_detect_unif_1" +names(analyse)[names(analyse)=="dif.detect.unif.2"] <- "dif_detect_unif_2" +names(analyse)[names(analyse)=="dif.detect.unif.3"] <- "dif_detect_unif_3" +names(analyse)[names(analyse)=="dif.detect.unif.4"] <- "dif_detect_unif_4" +analyse[analyse$dif_detect_1==999,"dif_detect_1"] <- "" +analyse[analyse$dif_detect_2==999,"dif_detect_2"] <- "" +analyse[analyse$dif_detect_3==999,"dif_detect_3"] <- "" +analyse[analyse$dif_detect_4==999,"dif_detect_4"] <- "" +analyse[analyse$dif_detect_unif_1==999,"dif_detect_unif_1"] <- "" +analyse[analyse$dif_detect_unif_2==999,"dif_detect_unif_2"] <- "" +analyse[analyse$dif_detect_unif_3==999,"dif_detect_unif_3"] <- "" +analyse[analyse$dif_detect_unif_4==999,"dif_detect_unif_4"] <- "" +if (scen==3 | scen==4 | scen>=13) { +names(analyse)[names(analyse)=="dif.detect.5"] <- "dif_detect_5" +names(analyse)[names(analyse)=="dif.detect.6"] <- "dif_detect_6" +names(analyse)[names(analyse)=="dif.detect.7"] <- "dif_detect_7" +names(analyse)[names(analyse)=="dif.detect.unif.5"] <- "dif_detect_unif_5" +names(analyse)[names(analyse)=="dif.detect.unif.6"] <- "dif_detect_unif_6" +names(analyse)[names(analyse)=="dif.detect.unif.7"] <- "dif_detect_unif_7" +} +analyse <- analyse[,!names(analyse) %in% c("X","X.1","X.2")] +write.csv(analyse,paste0("/home/corentin/Documents/These/Recherche/Simulations/Analysis/RESALI/Detection_data/",r,".csv")) +} +for (r in results) { +cat('--------------------------------------------------------------------------\n') +cat(paste0(r,"\n")) +cat('--------------------------------------------------------------------------\n') +#### Importer les datas +scen <- as.numeric(gsub("[A,B,C,D,E,F,G,_]","",substr(r,0,3))) +if (substr(r,start=nchar(r)-1,stop=nchar(r))=="50") { +N <- 50 +} +if (substr(r,start=nchar(r)-2,stop=nchar(r))=="100") { +N <- 100 +} +if (substr(r,start=nchar(r)-2,stop=nchar(r))=="200") { +N <- 200 +} +if (substr(r,start=nchar(r)-2,stop=nchar(r))=="300") { +N <- 300 +} +#### Importer l'analyse +analyse <- read.csv(paste0("/home/corentin/Documents/These/Recherche/Simulations/Analysis/RESALI/Detection_data/",r,".csv")) +analyse[is.na(analyse)] <- "" +names(analyse)[names(analyse)=="dif.detect.1"] <- "dif_detect_1" +names(analyse)[names(analyse)=="dif.detect.2"] <- "dif_detect_2" +names(analyse)[names(analyse)=="dif.detect.3"] <- "dif_detect_3" +names(analyse)[names(analyse)=="dif.detect.4"] <- "dif_detect_4" +names(analyse)[names(analyse)=="dif.detect.unif.1"] <- "dif_detect_unif_1" +names(analyse)[names(analyse)=="dif.detect.unif.2"] <- "dif_detect_unif_2" +names(analyse)[names(analyse)=="dif.detect.unif.3"] <- "dif_detect_unif_3" +names(analyse)[names(analyse)=="dif.detect.unif.4"] <- "dif_detect_unif_4" +analyse[analyse$dif_detect_1==999,"dif_detect_1"] <- "" +analyse[analyse$dif_detect_2==999,"dif_detect_2"] <- "" +analyse[analyse$dif_detect_3==999,"dif_detect_3"] <- "" +analyse[analyse$dif_detect_4==999,"dif_detect_4"] <- "" +analyse[analyse$dif_detect_unif_1==999,"dif_detect_unif_1"] <- "" +analyse[analyse$dif_detect_unif_2==999,"dif_detect_unif_2"] <- "" +analyse[analyse$dif_detect_unif_3==999,"dif_detect_unif_3"] <- "" +analyse[analyse$dif_detect_unif_4==999,"dif_detect_unif_4"] <- "" +if (scen==3 | scen==4 | scen>=13) { +names(analyse)[names(analyse)=="dif.detect.5"] <- "dif_detect_5" +names(analyse)[names(analyse)=="dif.detect.6"] <- "dif_detect_6" +names(analyse)[names(analyse)=="dif.detect.7"] <- "dif_detect_7" +names(analyse)[names(analyse)=="dif.detect.unif.5"] <- "dif_detect_unif_5" +names(analyse)[names(analyse)=="dif.detect.unif.6"] <- "dif_detect_unif_6" +names(analyse)[names(analyse)=="dif.detect.unif.7"] <- "dif_detect_unif_7" +analyse[analyse$dif_detect_5==999,"dif_detect_5"] <- "" +analyse[analyse$dif_detect_6==999,"dif_detect_6"] <- "" +analyse[analyse$dif_detect_7==999,"dif_detect_7"] <- "" +analyse[analyse$dif_detect_unif_5==999,"dif_detect_unif_5"] <- "" +analyse[analyse$dif_detect_unif_6==999,"dif_detect_unif_6"] <- "" +analyse[analyse$dif_detect_unif_7==999,"dif_detect_unif_7"] <- "" +} +analyse <- analyse[,!names(analyse) %in% c("X","X.1","X.2")] +write.csv(analyse,paste0("/home/corentin/Documents/These/Recherche/Simulations/Analysis/RESALI/Detection_data/",r,".csv")) +} diff --git a/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S10.do b/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S10.do index 71ececc..17deac6 100644 --- a/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S10.do +++ b/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S10.do @@ -27,338 +27,352 @@ local N = "50 100 200 300" 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 + 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 nbitems=7 + local nbmoda=1 } -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 + if (mod(`s',2)==0) { + local taillemat=2*`nbitems'*`nbmoda'+`nbitems'+`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' { + if (mod(`s',2)==1) { + local colna = "`colna'"+"dif_detect_`i' " + } + if (mod(`s',2)==0) { + local colna = "`colna'"+"dif_detect_`i' "+"dif_detect_unif_`i' " + } + } - 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" - 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' - 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 - * 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] - 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] - 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''' - 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 + } - 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 + } - 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'-1 + 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) + } + } + } - 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' + } + } - 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' - * 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 + } + } + } - * 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'' + } + } - * 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' + * 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)" } - 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'' + else if (`nbmoda_`i''==2) { + local mod = "`mod'"+"(2.item`i'<-THETA@2)" } - } - - * 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...] + } + 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' + local unif_`u'=0 + if (resmat[1,`nbitems'+`v']!=testm[1,1] & `nbmoda_`v''==3) { + local conformula = "`conformula'" + "`u' " + "`w' " + local unif_`u'=1 + } + else if (resmat[1,`nbitems'+`v']!=testm[1,1] & `nbmoda_`v''==2) { + local conformula = "`conformula'" + "`u' " + local unif_`u'=1 + } + } + 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' - } - } + * 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' + if (mod(`s',2)==0) { + mat outmat[`k',colnumb(outmat,"dif_detect_unif_`u'")] = `unif_`u'' + } + } - * 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 + * 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'/`s'`scen'_`Nn'_original.xls", sheet("outmat") replace - putexcel A1=matrix(outmat), colnames -} -} -} diff --git a/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S12.do b/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S12.do index c6a392d..8e7e251 100644 --- a/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S12.do +++ b/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S12.do @@ -27,338 +27,352 @@ local N = "50 100 200 300" 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 + 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 nbitems=7 + local nbmoda=1 } -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 + if (mod(`s',2)==0) { + local taillemat=2*`nbitems'*`nbmoda'+`nbitems'+`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' { + if (mod(`s',2)==1) { + local colna = "`colna'"+"dif_detect_`i' " + } + if (mod(`s',2)==0) { + local colna = "`colna'"+"dif_detect_`i' "+"dif_detect_unif_`i' " + } + } - 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" - 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' - 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 - * 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] - 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] - 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''' - 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 + } - 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 + } - 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'-1 + 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) + } + } + } - 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' + } + } - 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' - * 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 + } + } + } - * 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'' + } + } - * 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' + * 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)" } - 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'' + else if (`nbmoda_`i''==2) { + local mod = "`mod'"+"(2.item`i'<-THETA@2)" } - } - - * 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...] + } + 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' + local unif_`u'=0 + if (resmat[1,`nbitems'+`v']!=testm[1,1] & `nbmoda_`v''==3) { + local conformula = "`conformula'" + "`u' " + "`w' " + local unif_`u'=1 + } + else if (resmat[1,`nbitems'+`v']!=testm[1,1] & `nbmoda_`v''==2) { + local conformula = "`conformula'" + "`u' " + local unif_`u'=1 + } + } + 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' - } - } + * 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' + if (mod(`s',2)==0) { + mat outmat[`k',colnumb(outmat,"dif_detect_unif_`u'")] = `unif_`u'' + } + } - * 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 + * 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'/`s'`scen'_`Nn'_original.xls", sheet("outmat") replace - putexcel A1=matrix(outmat), colnames -} -} -} diff --git a/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S14.do b/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S14.do index 1a584e4..9c67cfa 100644 --- a/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S14.do +++ b/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S14.do @@ -27,338 +27,352 @@ local N = "50 100 200 300" 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 + 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 nbitems=7 + local nbmoda=1 } -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 + if (mod(`s',2)==0) { + local taillemat=2*`nbitems'*`nbmoda'+`nbitems'+`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' { + if (mod(`s',2)==1) { + local colna = "`colna'"+"dif_detect_`i' " + } + if (mod(`s',2)==0) { + local colna = "`colna'"+"dif_detect_`i' "+"dif_detect_unif_`i' " + } + } - 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" - 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' - 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 - * 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] - 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] - 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''' - 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 + } - 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 + } - 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'-1 + 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) + } + } + } - 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' + } + } - 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' - * 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 + } + } + } - * 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'' + } + } - * 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' + * 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)" } - 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'' + else if (`nbmoda_`i''==2) { + local mod = "`mod'"+"(2.item`i'<-THETA@2)" } - } - - * 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...] + } + 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' + local unif_`u'=0 + if (resmat[1,`nbitems'+`v']!=testm[1,1] & `nbmoda_`v''==3) { + local conformula = "`conformula'" + "`u' " + "`w' " + local unif_`u'=1 + } + else if (resmat[1,`nbitems'+`v']!=testm[1,1] & `nbmoda_`v''==2) { + local conformula = "`conformula'" + "`u' " + local unif_`u'=1 + } + } + 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' - } - } + * 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' + if (mod(`s',2)==0) { + mat outmat[`k',colnumb(outmat,"dif_detect_unif_`u'")] = `unif_`u'' + } + } - * 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 + * 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'/`s'`scen'_`Nn'_original.xls", sheet("outmat") replace - putexcel A1=matrix(outmat), colnames -} -} -} diff --git a/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S16.do b/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S16.do index 74fdc63..e58031b 100644 --- a/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S16.do +++ b/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S16.do @@ -27,338 +27,352 @@ local N = "50 100 200 300" 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 + 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 nbitems=7 + local nbmoda=1 } -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 + if (mod(`s',2)==0) { + local taillemat=2*`nbitems'*`nbmoda'+`nbitems'+`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' { + if (mod(`s',2)==1) { + local colna = "`colna'"+"dif_detect_`i' " + } + if (mod(`s',2)==0) { + local colna = "`colna'"+"dif_detect_`i' "+"dif_detect_unif_`i' " + } + } - 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" - 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' - 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 - * 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] - 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] - 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''' - 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 + } - 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 + } - 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'-1 + 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) + } + } + } - 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' + } + } - 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' - * 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 + } + } + } - * 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'' + } + } - * 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' + * 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)" } - 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'' + else if (`nbmoda_`i''==2) { + local mod = "`mod'"+"(2.item`i'<-THETA@2)" } - } - - * 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...] + } + 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' + local unif_`u'=0 + if (resmat[1,`nbitems'+`v']!=testm[1,1] & `nbmoda_`v''==3) { + local conformula = "`conformula'" + "`u' " + "`w' " + local unif_`u'=1 + } + else if (resmat[1,`nbitems'+`v']!=testm[1,1] & `nbmoda_`v''==2) { + local conformula = "`conformula'" + "`u' " + local unif_`u'=1 + } + } + 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' - } - } + * 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' + if (mod(`s',2)==0) { + mat outmat[`k',colnumb(outmat,"dif_detect_unif_`u'")] = `unif_`u'' + } + } - * 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 + * 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'/`s'`scen'_`Nn'_original.xls", sheet("outmat") replace - putexcel A1=matrix(outmat), colnames -} -} -} diff --git a/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S18.do b/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S18.do index eb63617..203ad44 100644 --- a/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S18.do +++ b/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S18.do @@ -27,338 +27,352 @@ local N = "50 100 200 300" 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 + 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 nbitems=7 + local nbmoda=1 } -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 + if (mod(`s',2)==0) { + local taillemat=2*`nbitems'*`nbmoda'+`nbitems'+`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' { + if (mod(`s',2)==1) { + local colna = "`colna'"+"dif_detect_`i' " + } + if (mod(`s',2)==0) { + local colna = "`colna'"+"dif_detect_`i' "+"dif_detect_unif_`i' " + } + } - 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" - 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' - 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 - * 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] - 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] - 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''' - 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 + } - 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 + } - 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'-1 + 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) + } + } + } - 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' + } + } - 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' - * 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 + } + } + } - * 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'' + } + } - * 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' + * 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)" } - 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'' + else if (`nbmoda_`i''==2) { + local mod = "`mod'"+"(2.item`i'<-THETA@2)" } - } - - * 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...] + } + 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' + local unif_`u'=0 + if (resmat[1,`nbitems'+`v']!=testm[1,1] & `nbmoda_`v''==3) { + local conformula = "`conformula'" + "`u' " + "`w' " + local unif_`u'=1 + } + else if (resmat[1,`nbitems'+`v']!=testm[1,1] & `nbmoda_`v''==2) { + local conformula = "`conformula'" + "`u' " + local unif_`u'=1 + } + } + 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' - } - } + * 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' + if (mod(`s',2)==0) { + mat outmat[`k',colnumb(outmat,"dif_detect_unif_`u'")] = `unif_`u'' + } + } - * 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 + * 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'/`s'`scen'_`Nn'_original.xls", sheet("outmat") replace - putexcel A1=matrix(outmat), colnames -} -} -} diff --git a/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S2.do b/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S2.do index 5d96e1c..af802d4 100644 --- a/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S2.do +++ b/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S2.do @@ -27,338 +27,352 @@ local N = "50 100 200 300" 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 + 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 nbitems=7 + local nbmoda=1 } -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 + if (mod(`s',2)==0) { + local taillemat=2*`nbitems'*`nbmoda'+`nbitems'+`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' { + if (mod(`s',2)==1) { + local colna = "`colna'"+"dif_detect_`i' " + } + if (mod(`s',2)==0) { + local colna = "`colna'"+"dif_detect_`i' "+"dif_detect_unif_`i' " + } + } - 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" - 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' - 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 - * 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] - 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] - 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''' - 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 + } - 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 + } - 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'-1 + 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) + } + } + } - 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' + } + } - 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' - * 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 + } + } + } - * 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'' + } + } - * 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' + * 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)" } - 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'' + else if (`nbmoda_`i''==2) { + local mod = "`mod'"+"(2.item`i'<-THETA@2)" } - } - - * 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...] + } + 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' + local unif_`u'=0 + if (resmat[1,`nbitems'+`v']!=testm[1,1] & `nbmoda_`v''==3) { + local conformula = "`conformula'" + "`u' " + "`w' " + local unif_`u'=1 + } + else if (resmat[1,`nbitems'+`v']!=testm[1,1] & `nbmoda_`v''==2) { + local conformula = "`conformula'" + "`u' " + local unif_`u'=1 + } + } + 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' - } - } + * 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' + if (mod(`s',2)==0) { + mat outmat[`k',colnumb(outmat,"dif_detect_unif_`u'")] = `unif_`u'' + } + } - * 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 + * 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'/`s'`scen'_`Nn'_original.xls", sheet("outmat") replace - putexcel A1=matrix(outmat), colnames -} -} -} diff --git a/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S20.do b/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S20.do index 82cdd40..a32c0c6 100644 --- a/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S20.do +++ b/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S20.do @@ -27,338 +27,352 @@ local N = "50 100 200 300" 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 + 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 nbitems=7 + local nbmoda=1 } -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 + if (mod(`s',2)==0) { + local taillemat=2*`nbitems'*`nbmoda'+`nbitems'+`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' { + if (mod(`s',2)==1) { + local colna = "`colna'"+"dif_detect_`i' " + } + if (mod(`s',2)==0) { + local colna = "`colna'"+"dif_detect_`i' "+"dif_detect_unif_`i' " + } + } - 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" - 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' - 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 - * 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] - 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] - 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''' - 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 + } - 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 + } - 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'-1 + 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) + } + } + } - 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' + } + } - 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' - * 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 + } + } + } - * 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'' + } + } - * 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' + * 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)" } - 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'' + else if (`nbmoda_`i''==2) { + local mod = "`mod'"+"(2.item`i'<-THETA@2)" } - } - - * 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...] + } + 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' + local unif_`u'=0 + if (resmat[1,`nbitems'+`v']!=testm[1,1] & `nbmoda_`v''==3) { + local conformula = "`conformula'" + "`u' " + "`w' " + local unif_`u'=1 + } + else if (resmat[1,`nbitems'+`v']!=testm[1,1] & `nbmoda_`v''==2) { + local conformula = "`conformula'" + "`u' " + local unif_`u'=1 + } + } + 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' - } - } + * 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' + if (mod(`s',2)==0) { + mat outmat[`k',colnumb(outmat,"dif_detect_unif_`u'")] = `unif_`u'' + } + } - * 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 + * 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'/`s'`scen'_`Nn'_original.xls", sheet("outmat") replace - putexcel A1=matrix(outmat), colnames -} -} -} diff --git a/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S4.do b/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S4.do index f00f747..76f75cd 100644 --- a/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S4.do +++ b/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S4.do @@ -27,338 +27,352 @@ local N = "50 100 200 300" 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 + 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 nbitems=7 + local nbmoda=1 } -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 + if (mod(`s',2)==0) { + local taillemat=2*`nbitems'*`nbmoda'+`nbitems'+`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' { + if (mod(`s',2)==1) { + local colna = "`colna'"+"dif_detect_`i' " + } + if (mod(`s',2)==0) { + local colna = "`colna'"+"dif_detect_`i' "+"dif_detect_unif_`i' " + } + } - 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" - 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' - 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 - * 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] - 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] - 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''' - 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 + } - 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 + } - 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'-1 + 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) + } + } + } - 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' + } + } - 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' - * 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 + } + } + } - * 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'' + } + } - * 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' + * 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)" } - 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'' + else if (`nbmoda_`i''==2) { + local mod = "`mod'"+"(2.item`i'<-THETA@2)" } - } - - * 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...] + } + 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' + local unif_`u'=0 + if (resmat[1,`nbitems'+`v']!=testm[1,1] & `nbmoda_`v''==3) { + local conformula = "`conformula'" + "`u' " + "`w' " + local unif_`u'=1 + } + else if (resmat[1,`nbitems'+`v']!=testm[1,1] & `nbmoda_`v''==2) { + local conformula = "`conformula'" + "`u' " + local unif_`u'=1 + } + } + 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' - } - } + * 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' + if (mod(`s',2)==0) { + mat outmat[`k',colnumb(outmat,"dif_detect_unif_`u'")] = `unif_`u'' + } + } - * 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 + * 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'/`s'`scen'_`Nn'_original.xls", sheet("outmat") replace - putexcel A1=matrix(outmat), colnames -} -} -} diff --git a/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S6.do b/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S6.do index ba0d7f1..e3dea9f 100644 --- a/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S6.do +++ b/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S6.do @@ -27,338 +27,352 @@ local N = "50 100 200 300" 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 + 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 nbitems=7 + local nbmoda=1 } -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 + if (mod(`s',2)==0) { + local taillemat=2*`nbitems'*`nbmoda'+`nbitems'+`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' { + if (mod(`s',2)==1) { + local colna = "`colna'"+"dif_detect_`i' " + } + if (mod(`s',2)==0) { + local colna = "`colna'"+"dif_detect_`i' "+"dif_detect_unif_`i' " + } + } - 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" - 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' - 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 - * 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] - 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] - 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''' - 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 + } - 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 + } - 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'-1 + 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) + } + } + } - 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' + } + } - 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' - * 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 + } + } + } - * 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'' + } + } - * 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' + * 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)" } - 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'' + else if (`nbmoda_`i''==2) { + local mod = "`mod'"+"(2.item`i'<-THETA@2)" } - } - - * 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...] + } + 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' + local unif_`u'=0 + if (resmat[1,`nbitems'+`v']!=testm[1,1] & `nbmoda_`v''==3) { + local conformula = "`conformula'" + "`u' " + "`w' " + local unif_`u'=1 + } + else if (resmat[1,`nbitems'+`v']!=testm[1,1] & `nbmoda_`v''==2) { + local conformula = "`conformula'" + "`u' " + local unif_`u'=1 + } + } + 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' - } - } + * 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' + if (mod(`s',2)==0) { + mat outmat[`k',colnumb(outmat,"dif_detect_unif_`u'")] = `unif_`u'' + } + } - * 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 + * 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'/`s'`scen'_`Nn'_original.xls", sheet("outmat") replace - putexcel A1=matrix(outmat), colnames -} -} -} diff --git a/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S8.do b/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S8.do index 52a3e1a..737d60a 100644 --- a/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S8.do +++ b/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S8.do @@ -27,338 +27,352 @@ local N = "50 100 200 300" 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 + 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 nbitems=7 + local nbmoda=1 } -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 + if (mod(`s',2)==0) { + local taillemat=2*`nbitems'*`nbmoda'+`nbitems'+`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' { + if (mod(`s',2)==1) { + local colna = "`colna'"+"dif_detect_`i' " + } + if (mod(`s',2)==0) { + local colna = "`colna'"+"dif_detect_`i' "+"dif_detect_unif_`i' " + } + } - 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" - 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' - 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 - * 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] - 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] - 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''' - 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 + } - 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 + } - 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'-1 + 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) + } + } + } - 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' + } + } - 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' - * 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 + } + } + } - * 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'' + } + } - * 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' + * 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)" } - 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'' + else if (`nbmoda_`i''==2) { + local mod = "`mod'"+"(2.item`i'<-THETA@2)" } - } - - * 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...] + } + 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' + local unif_`u'=0 + if (resmat[1,`nbitems'+`v']!=testm[1,1] & `nbmoda_`v''==3) { + local conformula = "`conformula'" + "`u' " + "`w' " + local unif_`u'=1 + } + else if (resmat[1,`nbitems'+`v']!=testm[1,1] & `nbmoda_`v''==2) { + local conformula = "`conformula'" + "`u' " + local unif_`u'=1 + } + } + 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' - } - } + * 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' + if (mod(`s',2)==0) { + mat outmat[`k',colnumb(outmat,"dif_detect_unif_`u'")] = `unif_`u'' + } + } - * 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 + * 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'/`s'`scen'_`Nn'_original.xls", sheet("outmat") replace - putexcel A1=matrix(outmat), colnames -} -} -}