Created ROSALI screening version
This commit is contained in:
1366
Modules/rosali_custom/rosali_nolrt_anchor.ado
Normal file
1366
Modules/rosali_custom/rosali_nolrt_anchor.ado
Normal file
File diff suppressed because it is too large
Load Diff
1354
Modules/rosali_custom/rosali_nolrt_screening.ado
Normal file
1354
Modules/rosali_custom/rosali_nolrt_screening.ado
Normal file
File diff suppressed because it is too large
Load Diff
@ -147,19 +147,35 @@ replicate_pcm_analysis<- function(df=NULL,treatment='TT',irtmodel='PCM2',method=
|
||||
|
||||
#### Create data.frame
|
||||
|
||||
#results <- c(sapply(c(2,4),function(x) paste0(x,c('A','B','C'))),sapply(c(6,8),function(x) paste0(x,c('A','B','C','D','E'))))
|
||||
|
||||
#results2 <- c(sapply(seq(10,20,2),function(x) paste0(x,c('A','B','C','D','E'))))
|
||||
|
||||
#results <- c(sapply(c(50,100,300),function(x) paste0(results,'_',x)))
|
||||
|
||||
#results2 <- c(sapply(c(50,100,300),function(x) paste0(results2,'_',x)))
|
||||
|
||||
#results <- c(results,results2)
|
||||
|
||||
results <- c(sapply(c(2,4),function(x) paste0(x,c('A','B','C'))),sapply(c(6,8),function(x) paste0(x,c('A','B','C','D','E'))))
|
||||
|
||||
results2 <- c(sapply(seq(10,20,2),function(x) paste0(x,c('A','B','C','D','E'))))
|
||||
|
||||
results <- c(sapply(c(50,100,300),function(x) paste0(results,'_',x)))
|
||||
results <- c(sapply(c("050",100,300),function(x) paste0(results,'_',x)))
|
||||
|
||||
results2 <- c(sapply(c(50,100,300),function(x) paste0(results2,'_',x)))
|
||||
results2 <- c(sapply(c("050",100,300),function(x) paste0(results2,'_',x)))
|
||||
|
||||
results <- sort(results)
|
||||
|
||||
results2 <- sort(results2)
|
||||
|
||||
results <- c(results,results2)
|
||||
|
||||
results <- c(sapply(1:16,function(x) c(results[x],results[x+16],results[x+32])),
|
||||
sapply(1:30,function(x) c(results[x+48],results[x+30+48],results[x+60+48]))
|
||||
)
|
||||
results <- gsub('050',"50",results)
|
||||
|
||||
# results <- c(sapply(1:16,function(x) c(results[x],results[x+16],results[x+32])),
|
||||
# sapply(1:30,function(x) c(results[x+48],results[x+30+48],results[x+60+48]))
|
||||
# )
|
||||
#### Compiler function
|
||||
|
||||
compile_simulation <- function(scenario) {
|
||||
@ -302,21 +318,21 @@ res.dat[is.nan(res.dat)] <- NA
|
||||
|
||||
#### Create data.frame
|
||||
|
||||
results <- c(sapply(c(2,4),function(x) paste0(x,c('A','B','C'))),sapply(c(6,8),function(x) paste0(x,c('A','B','C','D','E'))))
|
||||
results <- c(sapply(c(6,8),function(x) paste0(x,c('A','B','C','D','E'))))
|
||||
|
||||
results2 <- c(sapply(seq(10,20,2),function(x) paste0(x,c('A','B','C','D','E'))))
|
||||
|
||||
results <- c(sapply(c(50,100,300),function(x) paste0(results,'_',x)))
|
||||
results <- c(sapply(c("050",100,300),function(x) paste0(results,'_',x)))
|
||||
|
||||
results2 <- c(sapply(c(50,100,300),function(x) paste0(results2,'_',x)))
|
||||
results2 <- c(sapply(c("050",100,300),function(x) paste0(results2,'_',x)))
|
||||
|
||||
results <- sort(results)
|
||||
|
||||
results2 <- sort(results2)
|
||||
|
||||
results <- c(results,results2)
|
||||
|
||||
results <- c(sapply(1:16,function(x) c(results[x],results[x+16],results[x+32])),
|
||||
sapply(1:30,function(x) c(results[x+48],results[x+30+48],results[x+60+48]))
|
||||
)
|
||||
|
||||
results <- results[19:length(results)]
|
||||
results <- gsub('050',"50",results)
|
||||
|
||||
|
||||
#### Compiler function
|
||||
@ -425,19 +441,23 @@ res.dat.dif$bias <- res.dat.dif$eff.size-res.dat.dif$m.beta
|
||||
|
||||
#### Create data.frame
|
||||
|
||||
|
||||
results <- c(sapply(c(2,4),function(x) paste0(x,c('A','B','C'))),sapply(c(6,8),function(x) paste0(x,c('A','B','C','D','E'))))
|
||||
|
||||
results2 <- c(sapply(seq(10,20,2),function(x) paste0(x,c('A','B','C','D','E'))))
|
||||
|
||||
results <- c(sapply(c(50,100,300),function(x) paste0(results,'_',x)))
|
||||
results <- c(sapply(c("050",100,300),function(x) paste0(results,'_',x)))
|
||||
|
||||
results2 <- c(sapply(c(50,100,300),function(x) paste0(results2,'_',x)))
|
||||
results2 <- c(sapply(c("050",100,300),function(x) paste0(results2,'_',x)))
|
||||
|
||||
results <- sort(results)
|
||||
|
||||
results2 <- sort(results2)
|
||||
|
||||
results <- c(results,results2)
|
||||
|
||||
results <- c(sapply(1:16,function(x) c(results[x],results[x+16],results[x+32])),
|
||||
sapply(1:30,function(x) c(results[x+48],results[x+30+48],results[x+60+48]))
|
||||
)
|
||||
results <- gsub('050',"50",results)
|
||||
|
||||
|
||||
#### Compiler function
|
||||
|
||||
@ -719,19 +739,36 @@ res.dat.dif.rosali$bias <- res.dat.dif.rosali$eff.size-res.dat.dif.rosali$m.beta
|
||||
#### Create data.frame
|
||||
|
||||
|
||||
#results <- c(sapply(c(2,4),function(x) paste0(x,c('A','B','C'))),sapply(c(6,8),function(x) paste0(x,c('A','B','C','D','E'))))
|
||||
|
||||
#results2 <- c(sapply(seq(10,20,2),function(x) paste0(x,c('A','B','C','D','E'))))
|
||||
|
||||
#results <- c(sapply(c(50,100,300),function(x) paste0(results,'_',x)))
|
||||
|
||||
#results2 <- c(sapply(c(50,100,300),function(x) paste0(results2,'_',x)))
|
||||
|
||||
#results <- c(results,results2)
|
||||
|
||||
#results <- c(sapply(1:16,function(x) c(results[x],results[x+16],results[x+32])),
|
||||
# sapply(1:30,function(x) c(results[x+48],results[x+30+48],results[x+60+48]))
|
||||
#)
|
||||
|
||||
|
||||
results <- c(sapply(c(2,4),function(x) paste0(x,c('A','B','C'))),sapply(c(6,8),function(x) paste0(x,c('A','B','C','D','E'))))
|
||||
|
||||
results2 <- c(sapply(seq(10,20,2),function(x) paste0(x,c('A','B','C','D','E'))))
|
||||
|
||||
results <- c(sapply(c(50,100,300),function(x) paste0(results,'_',x)))
|
||||
results <- c(sapply(c("050",100,300),function(x) paste0(results,'_',x)))
|
||||
|
||||
results2 <- c(sapply(c(50,100,300),function(x) paste0(results2,'_',x)))
|
||||
results2 <- c(sapply(c("050",100,300),function(x) paste0(results2,'_',x)))
|
||||
|
||||
results <- sort(results)
|
||||
|
||||
results2 <- sort(results2)
|
||||
|
||||
results <- c(results,results2)
|
||||
|
||||
results <- c(sapply(1:16,function(x) c(results[x],results[x+16],results[x+32])),
|
||||
sapply(1:30,function(x) c(results[x+48],results[x+30+48],results[x+60+48]))
|
||||
)
|
||||
results <- gsub('050',"50",results)
|
||||
|
||||
|
||||
#### Compiler function
|
||||
@ -985,6 +1022,7 @@ res.dat.dif.resali[substr(res.dat.dif.resali$scenario,1,2)%in%seq(10,16,2),'nb.d
|
||||
res.dat.dif.resali[substr(res.dat.dif.resali$scenario,1,2)%in%seq(18,20,2),'nb.dif'] <- 3
|
||||
res.dat.dif.resali[res.dat.dif.resali$N==50,"dif.size"] <- res.dat.dif.resali[which(res.dat.dif.resali$N==50)+1,"dif.size"]
|
||||
res.dat.dif.resali[res.dat.dif.resali$scenario.type=="B",]$eff.size <- 0.2
|
||||
res.dat.dif.resali[res.dat.dif.resali$scenario=="20E" & res.dat.dif.resali$N==50,]$dif.size <- -0.5
|
||||
res.dat.dif.resali[res.dat.dif.resali$scenario.type=="C" & res.dat.dif.resali$dif.size==0,]$eff.size <- 0.4
|
||||
res.dat.dif.resali[res.dat.dif.resali$scenario.type=="C" & res.dat.dif.resali$dif.size!=0,]$eff.size <- 0.2
|
||||
res.dat.dif.resali[res.dat.dif.resali$scenario.type=="D" & res.dat.dif.resali$dif.size!=0,]$eff.size <- 0.4
|
||||
@ -1203,7 +1241,8 @@ res.dat.article.rosali.2$bias <- -1*res.dat.article.rosali.2$bias
|
||||
res.dat.article.rosali.2.nodif <- res.dat.article.rosali.2[res.dat.article.rosali.2$nb.dif==0,]
|
||||
|
||||
# STRATEGY 3 - RESIDIF
|
||||
|
||||
res.dat.dif.resali[1,"N"] <- 50
|
||||
res.dat.dif.resali$dif.size <- res.dat.dif.rosali$dif.size
|
||||
res.dat.article.residif <- res.dat.dif.resali[,c("N","J","eff.size","nb.dif","dif.size",
|
||||
"m.beta","bias","true.value.in.ci.p","h0.rejected.p",
|
||||
"theoretical.power")]
|
||||
@ -1219,7 +1258,7 @@ res.dat.article.residif[res.dat.article.residif$nb.dif==0,"true.gamma"] <- NA
|
||||
res.dat.article.residif[is.na(res.dat.article.residif)] <- " "
|
||||
res.dat.article.residif$bias <- -1*res.dat.article.residif$bias
|
||||
res.dat.article.residif <- reshape(res.dat.article.residif,
|
||||
direction = "wide", idvar = c("J","true.beta","nb.dif",'true.gamma'),timevar = "N" )
|
||||
direction = "wide", idvar = c("J","true.beta","nb.dif",'true.gamma'),timevar = "N")
|
||||
res.dat.article.residif.dif <- res.dat.article.residif[res.dat.article.residif$nb.dif>0,]
|
||||
write.csv(res.dat.article.residif.dif,"/home/corentin/Documents/These/Valorisation/Articles/Simulations 1/Tables/res_RESIDIF_DIF.csv")
|
||||
res.dat.article.residif.nodif <- res.dat.article.residif[res.dat.article.residif$nb.dif==0,]
|
||||
@ -1240,6 +1279,7 @@ res.dat.article.residif.2[res.dat.article.residif.2$nb.dif==0,"true.gamma"] <- N
|
||||
res.dat.article.residif.2[is.na(res.dat.article.residif.2)] <- " "
|
||||
res.dat.article.residif.2$bias <- -1*res.dat.article.residif.2$bias
|
||||
res.dat.article.residif.2.nodif <- res.dat.article.residif.2[res.dat.article.residif.2$nb.dif==0,]
|
||||
res.dat.article.residif.dif
|
||||
|
||||
# STRATEGY 4 - PERFECT-DIF
|
||||
|
||||
|
@ -27,10 +27,9 @@ resali <- function(df=NULL,items=NULL,group=NULL,verbose=T) {
|
||||
for (i in items) {
|
||||
dat[,paste0('res_',i)] <- IRT.residuals(pcm_initial)$stand_residuals[,i]
|
||||
res.anova[i] <- summary(aov(dat[,paste0('res_',i)]~TT*score_q5,data=dat))
|
||||
pval[i] <- res.anova[[i]][1,"Pr(>F)"]
|
||||
fval[i] <- res.anova[[i]][1,'F value']
|
||||
pval[c(i,i+nbitems)] <- c(res.anova[[i]][1,"Pr(>F)"],res.anova[[i]][3,"Pr(>F)"])
|
||||
fval[c(i,i+nbitems)] <- c(res.anova[[i]][1,'F value'],res.anova[[i]][3,"F value"])
|
||||
}
|
||||
print(res.anova)
|
||||
if (verbose) {
|
||||
cat('DONE\n')
|
||||
cat('-----------------------------------------------------------\n')
|
||||
@ -44,9 +43,10 @@ resali <- function(df=NULL,items=NULL,group=NULL,verbose=T) {
|
||||
cat(paste('COMPUTING STEP',k,'\n'))
|
||||
cat('-----------------------------------------------------------\n')
|
||||
}
|
||||
res.item <- gsub("[a-z]", "",colnames(resp)[which.max(fval)])
|
||||
numitem <- ifelse(which.max(fval)%%(length(fval)/2)!=0,which.max(fval)%%(length(fval)/2),length(fval)/2)
|
||||
res.item <- gsub("[a-z]", "",colnames(resp)[numitem])
|
||||
res.items <- c(res.items,res.item)
|
||||
res.uni <- res.anova[[which.max(fval)]][3,"Pr(>F)"]>0.05
|
||||
res.uni <- res.anova[[numitem]][3,"Pr(>F)"]>0.05
|
||||
res.uniform <- c(res.uniform,res.uni)
|
||||
items_n <- c(items_n[items_n!=paste0('item',res.item)],paste0("item",res.item,c("noTT","TT")))
|
||||
dat[dat$TT==1,paste0("item",res.item,'TT')] <- dat[dat$TT==1,paste0('item',res.item)]
|
||||
@ -54,24 +54,19 @@ resali <- function(df=NULL,items=NULL,group=NULL,verbose=T) {
|
||||
resp <- dat[,items_n]
|
||||
grp <- dat[,group]
|
||||
pcm_while <- TAM::tam.mml(resp=resp,Y=grp,irtmodel = "PCM",est.variance = T,verbose=F)
|
||||
nbitems <- length(items_n)
|
||||
nbitems <- length(items_n)-2*length(res.items)
|
||||
res.anova <- rep(NA,nbitems)
|
||||
pval <- rep(NA,nbitems)
|
||||
fval <- rep(NA,nbitems)
|
||||
pval <- rep(NA,2*nbitems)
|
||||
fval <- rep(NA,2*nbitems)
|
||||
for (i in 1:nbitems) {
|
||||
dat[,paste0('res_',i)] <- IRT.residuals(pcm_while)$stand_residuals[,i]
|
||||
res.anova[i] <- summary(aov(dat[,paste0('res_',i)]~TT*score_q5,data=dat))
|
||||
pval[i] <- res.anova[[i]][1,"Pr(>F)"]
|
||||
pval[i+nbitems] <- res.anova[[i]][3,"Pr(>F)"]
|
||||
fval[i] <- res.anova[[i]][1,'F value']
|
||||
fval[i+nbitems] <- res.anova[[i]][3,"F value"]
|
||||
}
|
||||
zz <- 0
|
||||
for (name_i in items_n) {
|
||||
zz <- zz+1
|
||||
if (grepl("TT",name_i)) {
|
||||
pval[zz] <- 1
|
||||
fval[zz] <- 0
|
||||
}
|
||||
}
|
||||
if (verbose) {
|
||||
cat('DONE\n')
|
||||
cat('-----------------------------------------------------------\n')
|
||||
|
167
RProject/Scripts/Analysis/functions/resali_v2.R
Normal file
167
RProject/Scripts/Analysis/functions/resali_v2.R
Normal file
@ -0,0 +1,167 @@
|
||||
library(TAM)
|
||||
|
||||
resali <- function(df=NULL,items=NULL,group=NULL,verbose=T) {
|
||||
if (verbose) {
|
||||
cat('-----------------------------------------------------------\n')
|
||||
cat('COMPUTING INITIAL PCM\n')
|
||||
cat('-----------------------------------------------------------\n')
|
||||
}
|
||||
nbitems <- length(items)
|
||||
nbitems_o <- nbitems
|
||||
items_n <- paste0('item',items)
|
||||
resp <- df[,items_n]
|
||||
grp <- df[,group]
|
||||
pcm_initial <- TAM::tam.mml(resp=resp,Y=grp,irtmodel = "PCM",est.variance = T,verbose=F)
|
||||
dat <- df
|
||||
dat$score <- rowSums(dat[,items_n])
|
||||
nqt <- ifelse(length(unique(quantile(dat$score,seq(0,1,0.2))))==6,5,length(unique(quantile(dat$score,seq(0,1,0.2))))-1)
|
||||
while (length(unique(quantile(dat$score,seq(0,1,1/nqt))))!=nqt+1) {
|
||||
nqt <- nqt-1
|
||||
}
|
||||
# ITEM POLYTOMIQUE
|
||||
if (max(resp)>1) {
|
||||
dat$score_q5 <- cut(dat$score,unique(quantile(dat$score,seq(0,1,1/nqt))),labels=1:nqt,include.lowest=T)
|
||||
res.anova <- rep(NA,nbitems)
|
||||
pval <- rep(NA,nbitems)
|
||||
fval <- rep(NA,nbitems)
|
||||
for (i in items) {
|
||||
dat[,paste0('res_',i)] <- IRT.residuals(pcm_initial)$stand_residuals[,i]
|
||||
res.anova[i] <- summary(aov(dat[,paste0('res_',i)]~TT*score_q5,data=dat))
|
||||
pval[i] <- res.anova[[i]][1,"Pr(>F)"]
|
||||
fval[i] <- res.anova[[i]][1,'F value']
|
||||
}
|
||||
print(res.anova)
|
||||
if (verbose) {
|
||||
cat('DONE\n')
|
||||
cat('-----------------------------------------------------------\n')
|
||||
}
|
||||
res.items <- c()
|
||||
res.uniform <- c()
|
||||
k <- 1
|
||||
while(any(pval<0.05/(nbitems_o*3))) {
|
||||
k <- k+1
|
||||
if (verbose) {
|
||||
cat(paste('COMPUTING STEP',k,'\n'))
|
||||
cat('-----------------------------------------------------------\n')
|
||||
}
|
||||
res.item <- gsub("[a-z]", "",colnames(resp)[which.max(fval)])
|
||||
res.items <- c(res.items,res.item)
|
||||
res.uni <- res.anova[[which.max(fval)]][3,"Pr(>F)"]>0.05
|
||||
res.uniform <- c(res.uniform,res.uni)
|
||||
items_n <- c(items_n[items_n!=paste0('item',res.item)],paste0("item",res.item,c("noTT","TT")))
|
||||
dat[dat$TT==1,paste0("item",res.item,'TT')] <- dat[dat$TT==1,paste0('item',res.item)]
|
||||
dat[dat$TT==0,paste0("item",res.item,'noTT')] <- dat[dat$TT==0,paste0('item',res.item)]
|
||||
resp <- dat[,items_n]
|
||||
grp <- dat[,group]
|
||||
pcm_while <- TAM::tam.mml(resp=resp,Y=grp,irtmodel = "PCM",est.variance = T,verbose=F)
|
||||
nbitems <- length(items_n)
|
||||
res.anova <- rep(NA,nbitems)
|
||||
pval <- rep(NA,nbitems)
|
||||
fval <- rep(NA,nbitems)
|
||||
for (i in 1:nbitems) {
|
||||
dat[,paste0('res_',i)] <- IRT.residuals(pcm_while)$stand_residuals[,i]
|
||||
res.anova[i] <- summary(aov(dat[,paste0('res_',i)]~TT*score_q5,data=dat))
|
||||
pval[i] <- res.anova[[i]][1,"Pr(>F)"]
|
||||
fval[i] <- res.anova[[i]][1,'F value']
|
||||
}
|
||||
zz <- 0
|
||||
for (name_i in items_n) {
|
||||
zz <- zz+1
|
||||
if (grepl("TT",name_i)) {
|
||||
pval[zz] <- 1
|
||||
fval[zz] <- 0
|
||||
}
|
||||
}
|
||||
if (verbose) {
|
||||
cat('DONE\n')
|
||||
cat('-----------------------------------------------------------\n')
|
||||
}
|
||||
}
|
||||
if (verbose) {
|
||||
cat("DETECTED DIF ITEMS\n")
|
||||
cat('-----------------------------------------------------------\n')
|
||||
}
|
||||
if (length(res.items>0)) {
|
||||
results <- data.frame(dif.items=res.items,
|
||||
uniform=1*res.uniform)
|
||||
return(results)
|
||||
}
|
||||
else {
|
||||
if (verbose) {
|
||||
cat("No DIF was detected\n")
|
||||
}
|
||||
return(NULL)
|
||||
}
|
||||
# ITEM DICHOTOMIQUE
|
||||
} else {
|
||||
|
||||
res.anova <- rep(NA,nbitems)
|
||||
pval <- rep(NA,nbitems)
|
||||
fval <- rep(NA,nbitems)
|
||||
for (i in items) {
|
||||
dat[,paste0('res_',i)] <- IRT.residuals(pcm_initial)$stand_residuals[,i]
|
||||
res.anova[i] <- summary(aov(dat[,paste0('res_',i)]~TT,data=dat))
|
||||
pval[i] <- res.anova[[i]][1,"Pr(>F)"]
|
||||
fval[i] <- res.anova[[i]][1,'F value']
|
||||
}
|
||||
if (verbose) {
|
||||
cat('DONE\n')
|
||||
cat('-----------------------------------------------------------\n')
|
||||
}
|
||||
res.items <- c()
|
||||
k <- 1
|
||||
while(any(pval<0.05/(nbitems_o))) {
|
||||
k <- k+1
|
||||
if (verbose) {
|
||||
cat(paste('COMPUTING STEP',k,'\n'))
|
||||
cat('-----------------------------------------------------------\n')
|
||||
}
|
||||
res.item <- gsub("[a-z]", "",colnames(resp)[which.max(fval)])
|
||||
res.items <- c(res.items,res.item)
|
||||
items_n <- c(items_n[items_n!=paste0('item',res.item)],paste0("item",res.item,c("noTT","TT")))
|
||||
dat[dat$TT==1,paste0("item",res.item,'TT')] <- dat[dat$TT==1,paste0('item',res.item)]
|
||||
dat[dat$TT==0,paste0("item",res.item,'noTT')] <- dat[dat$TT==0,paste0('item',res.item)]
|
||||
resp <- dat[,items_n]
|
||||
grp <- dat[,group]
|
||||
pcm_while <- TAM::tam.mml(resp=resp,Y=grp,irtmodel = "PCM",est.variance = T,verbose=F)
|
||||
nbitems <- length(items_n)
|
||||
res.anova <- rep(NA,nbitems)
|
||||
pval <- rep(NA,nbitems)
|
||||
fval <- rep(NA,nbitems)
|
||||
for (i in 1:nbitems) {
|
||||
dat[,paste0('res_',i)] <- IRT.residuals(pcm_while)$stand_residuals[,i]
|
||||
res.anova[i] <- summary(aov(dat[,paste0('res_',i)]~TT,data=dat))
|
||||
pval[i] <- res.anova[[i]][1,"Pr(>F)"]
|
||||
fval[i] <- res.anova[[i]][1,'F value']
|
||||
}
|
||||
zz <- 0
|
||||
for (name_i in items_n) {
|
||||
zz <- zz+1
|
||||
if (grepl("TT",name_i)) {
|
||||
pval[zz] <- 1
|
||||
fval[zz] <- 0
|
||||
}
|
||||
}
|
||||
if (verbose) {
|
||||
cat('DONE\n')
|
||||
cat('-----------------------------------------------------------\n')
|
||||
}
|
||||
}
|
||||
if (verbose) {
|
||||
cat("DETECTED DIF ITEMS\n")
|
||||
cat('-----------------------------------------------------------\n')
|
||||
}
|
||||
if (length(res.items>0)) {
|
||||
results <- data.frame(dif.items=res.items,
|
||||
uniform=rep(1,length(res.items)))
|
||||
return(results)
|
||||
}
|
||||
else {
|
||||
if (verbose) {
|
||||
cat("No DIF was detected\n")
|
||||
}
|
||||
return(NULL)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -113,15 +113,18 @@ generate_resali <- function(scenario=NULL,grp=NULL) {
|
||||
return(df_res)
|
||||
}
|
||||
|
||||
#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 <- c(sapply(c(2:4),function(x) paste0(x,c('A','B','C'))),sapply(c(6,8),function(x) paste0(x,c('A','B','C','D','E'))))
|
||||
|
||||
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(seq(10,20,2),function(x) paste0(x,c('A','B','C','D','E'))))
|
||||
|
||||
results2 <- c(sapply(10:20,function(x) paste0(x,c('A','B','C','D','E','F','G'))))
|
||||
results <- c(sapply(c(50,100,300),function(x) paste0(results,'_',x)))
|
||||
|
||||
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)))
|
||||
results2 <- c(sapply(c(50,100,300),function(x) paste0(results2,'_',x)))
|
||||
|
||||
results <- sort(results)
|
||||
|
||||
@ -144,13 +147,27 @@ for (r in results) {
|
||||
|
||||
## Liste des scenarios
|
||||
|
||||
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'))))
|
||||
#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'))))
|
||||
#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)))
|
||||
#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)))
|
||||
#results2 <- c(sapply(c(50,100,200,300),function(x) paste0(results2,'_',x)))
|
||||
|
||||
#results <- sort(results)
|
||||
|
||||
#results2 <- sort(results2)
|
||||
|
||||
#results <- c(results,results2)
|
||||
|
||||
results <- c(sapply(c(2:4),function(x) paste0(x,c('A','B','C'))),sapply(c(6,8),function(x) paste0(x,c('A','B','C','D','E'))))
|
||||
|
||||
results2 <- c(sapply(seq(10,20,2),function(x) paste0(x,c('A','B','C','D','E'))))
|
||||
|
||||
results <- c(sapply(c(50,100,300),function(x) paste0(results,'_',x)))
|
||||
|
||||
results2 <- c(sapply(c(50,100,300),function(x) paste0(results2,'_',x)))
|
||||
|
||||
results <- sort(results)
|
||||
|
||||
|
375
Scripts/Analysis/DIF-RESIDUALS/pcm_dif_residus2.do
Normal file
375
Scripts/Analysis/DIF-RESIDUALS/pcm_dif_residus2.do
Normal file
@ -0,0 +1,375 @@
|
||||
*=================================================================================================================================================
|
||||
* Date : 2024-01-23
|
||||
* Stata version : Stata 18 SE
|
||||
*
|
||||
* This program analyses simulated data accounting for DIF through a partial credit model
|
||||
*
|
||||
* ado-files needed : - pcm, rosali (version 5.5 October 25, 2023, available on gitea)
|
||||
*
|
||||
*
|
||||
*================================================================================================================================================
|
||||
adopath+"/home/corentin/Documents/These/Recherche/ROSALI-SIM/Modules/rosali_custom"
|
||||
|
||||
|
||||
local N = "50 100 300"
|
||||
local ss = "18 20"
|
||||
foreach s in `ss' {
|
||||
foreach Nnn in `N' {
|
||||
local Nn = `Nnn'
|
||||
local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Analysis/RESALI/Detection_data"
|
||||
local path_res = "/home/corentin/Documents/These/Recherche/Simulations/Analysis/RESALI/Results/N`Nn'"
|
||||
local scenarios = "A B C D E"
|
||||
if (`s' <= 4) {
|
||||
local scenarios = "A B C"
|
||||
}
|
||||
foreach scen in `scenarios' {
|
||||
clear
|
||||
import delim "`path_data'/`s'`scen'_`Nn'.csv", encoding(ISO-8859-2) case(preserve) clear
|
||||
rename TT tt
|
||||
|
||||
if (`s'<=2) {
|
||||
local nbitems=4
|
||||
}
|
||||
else if (`s'<=4) {
|
||||
local nbitems=7
|
||||
}
|
||||
else if (`s'<=12) {
|
||||
local nbitems=4
|
||||
}
|
||||
else {
|
||||
local nbitems=7
|
||||
}
|
||||
|
||||
if (mod(`s',2)==0) {
|
||||
local nbmoda=3
|
||||
}
|
||||
else {
|
||||
local nbmoda=1
|
||||
}
|
||||
|
||||
if (`s'<=4) {
|
||||
local nbdif=0
|
||||
}
|
||||
else if (`s'<=8) {
|
||||
local nbdif=1
|
||||
}
|
||||
else if (`s'<=16) {
|
||||
local nbdif=2
|
||||
}
|
||||
else {
|
||||
local nbdif=3
|
||||
}
|
||||
* taillemat = Maximum J*M cases pour les items par et J*M cases pour les dif par + J cases pour les DIF detect + nbdif cases pour dif réel
|
||||
local taillemat=2*`nbitems'*`nbmoda'+`nbitems'+`nbdif'+2
|
||||
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' "
|
||||
}
|
||||
}
|
||||
|
||||
forvalues i=1/`nbdif' {
|
||||
local colna = "`colna'"+"real_dif_`i' "
|
||||
}
|
||||
local colna = "`colna'" + "beta " + "se_beta"
|
||||
mat outmat = J(1000,`taillemat',.)
|
||||
mat colnames outmat= `colna'
|
||||
di "Scenario `s'`scen' / N=`Nnn'"
|
||||
forvalues k=1/1000 {
|
||||
if (mod(`k',100)==0) {
|
||||
di "`k'/1000"
|
||||
}
|
||||
preserve
|
||||
qui keep if replication==`k'
|
||||
|
||||
|
||||
* MERGE des modalités si non représentées
|
||||
|
||||
if (`nbmoda'>1 & `Nn'==50) {
|
||||
local com_z = 0
|
||||
qui gen comz = 0
|
||||
forvalues j = 1 / `nbitems' {
|
||||
local recoda_`j' = 0
|
||||
qui tab item`j' if tt == 0, matrow(rect1_g0_`j') matcell(nbrt1_g0_`j')
|
||||
local maxm`j'_t1_g0 = rect1_g0_`j'[r(r),1]
|
||||
local minm`j'_t1_g0 = rect1_g0_`j'[1,1]
|
||||
|
||||
qui tab item`j' if tt == 1, matrow(rect1_g1_`j') matcell(nbrt1_g1_`j')
|
||||
local minm`j'_t1_g1 = rect1_g1_`j'[1,1]
|
||||
local maxm`j'_t1_g1 = rect1_g1_`j'[r(r),1]
|
||||
|
||||
local minm_`j' = min(`minm`j'_t1_g0',`minm`j'_t1_g1')
|
||||
local maxm_`j' = max(`maxm`j'_t1_g0',`maxm`j'_t1_g1')
|
||||
local nbm_`j' = `=`maxm_`j''-`minm_`j'''
|
||||
|
||||
if `minm_`j'' != 0 & `com_z' == 0 {
|
||||
local com_z = 1
|
||||
}
|
||||
|
||||
qui count if item`j' == 3 & tt == 0
|
||||
local mod3plac = r(N)
|
||||
qui count if item`j' == 3 & tt == 1
|
||||
local mod3tt = r(N)
|
||||
local nb_rn3 = min(`mod3plac',`mod3tt')
|
||||
if `nb_rn3'==0 {
|
||||
qui replace comz = 1
|
||||
}
|
||||
|
||||
forvalues m = 0/`=`nbm_`j''-1' {
|
||||
qui count if item`j' == `m' & tt == 0
|
||||
local nb_rn1_g0 = r(N)
|
||||
qui count if item`j' == `m' & tt == 1
|
||||
local nb_rn1_g1 = r(N)
|
||||
local nb_rn = min(`nb_rn1_g0',`nb_rn1_g1')
|
||||
if `nb_rn' == 0 {
|
||||
qui replace comz = 1
|
||||
local recoda_`j' = 1
|
||||
if `m' == 0 | `m' < `minm`j'_t1_g0' | `m' < `minm`j'_t1_g1' {
|
||||
local stop = 1
|
||||
forvalues kk = 1/`=`nbm_`j''-`m'' {
|
||||
qui count if item`j' == `=`m' + `kk'' & tt == 0
|
||||
local v`kk'1_0 = r(N)
|
||||
qui count if item`j' == `=`m' + `kk'' & tt == 1
|
||||
local v`kk'1_1 = r(N)
|
||||
if (`v`kk'1_0' != 0 | `v`kk'1_1' != 0) & `stop' != 0 {
|
||||
qui replace item`j'= `=`m'+`kk'' if item`j'==`m'
|
||||
local zzz=`j'+`nbitems'
|
||||
*qui replace item`zzz'=`=`m'+`kk'' if item``=`j'+`nbitems'''==`m'
|
||||
*di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
|
||||
local stop = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
else if `m' == `=`nbm_`j''-1' | `m' >= `maxm`j'_t1_g1' {
|
||||
local stop = 1
|
||||
forvalues kk = 1/`=`m'' {
|
||||
qui count if item`j' == `=`m' - `kk'' & tt == 0
|
||||
local v`kk'1_0 = r(N)
|
||||
qui count if item`j' == `=`m' - `kk'' & tt == 1
|
||||
local v`kk'1_1 = r(N)
|
||||
if (`v`kk'1_0' != 0 | `v`kk'1_1' != 0) & `stop' != 0 {
|
||||
qui replace item`j'= `=`m' - `kk'' if item`j'==`m'
|
||||
local zzz=`j'+`nbitems'
|
||||
*qui replace item`zzz'= `=`m' - `kk'' if item`zzz'==`m'
|
||||
*di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
|
||||
local stop = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if runiform()>0.5{
|
||||
local stop = 1
|
||||
forvalues kk = 1/`m' {
|
||||
qui count if item`j' == `=`m' - `kk'' & tt == 0
|
||||
local v`kk'1_0 = r(N)
|
||||
qui count if item`j' == `=`m' - `kk'' & tt == 1
|
||||
local v`kk'1_1 = r(N)
|
||||
if (`v`kk'1_0' != 0 | `v`kk'1_1' != 0) & `stop' != 0 {
|
||||
qui replace item`j'= `=`m'-`kk'' if item`j'==`m'
|
||||
local zzz=`j'+`nbitems'
|
||||
*qui replace item`zzz'=`=`m'-`kk'' if item``=`j'+`nbitems'''==`m'
|
||||
*di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
|
||||
local stop = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
local stop = 1
|
||||
forvalues kk = 1/`=`nbm_`j''-`m'' {
|
||||
qui count if item`j' == `=`m' + `kk'' & tt == 0
|
||||
local v`kk'1_0 = r(N)
|
||||
qui count if item`j' == `=`m' + `kk'' & tt == 1
|
||||
local v`kk'1_1 = r(N)
|
||||
if (`v`kk'1_0' != 0 | `v`kk'1_1' != 0) & `stop' != 0{
|
||||
qui replace item`j'=`=`m' + `kk'' if item`j'==`m'
|
||||
local zzz=`j'+`nbitems'
|
||||
*qui replace item`zzz'=`=`m' + `kk'' if item``=`j'+`nbitems'''==`m'
|
||||
*di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
|
||||
local stop = 0
|
||||
}
|
||||
else {
|
||||
if `stop' != 0 {
|
||||
qui replace item`j'= `nbm_`j'' if item`j'==`m'
|
||||
local zzz=`j'+`nbitems'
|
||||
*qui replace item`zzz'= `nbm_`j'' if item``=`j'+`nbitems'''==`m'
|
||||
*di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
|
||||
local stop = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
qui levelsof item`j'
|
||||
local val = r(levels)
|
||||
local checker: word 1 of `val'
|
||||
local checker2: word 2 of `val'
|
||||
local checker3: word 3 of `val'
|
||||
local nummoda=r(r)
|
||||
local nbmoda_`j'=`nummoda'-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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
qui valuesof comz
|
||||
local val = r(values)
|
||||
local checker: word 1 of `val'
|
||||
}
|
||||
else {
|
||||
forvalues jj=1/`nbitems' {
|
||||
local nbmoda_`jj'=`nbmoda'
|
||||
}
|
||||
}
|
||||
local nbitems2 = 2*`nbitems'
|
||||
|
||||
* Calculer le nbre d'items détectés
|
||||
local nbdetect = 0
|
||||
local stop = 0
|
||||
forvalues jj=1/`nbitems' {
|
||||
qui levelsof dif_detect_`jj'
|
||||
local detected=r(levels)
|
||||
if (`stop'==0) {
|
||||
mat testm=J(1,1,.)
|
||||
if (`detected'==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' {
|
||||
qui levelsof dif_detect_`u'
|
||||
local detected=r(levels)
|
||||
local difitems`u'=`detected'
|
||||
local i=`difitems`u''
|
||||
qui levelsof dif_detect_unif_`u'
|
||||
local detected_unif=r(levels)
|
||||
if (`nbmoda_`i''==3 & `detected_unif'!=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 & `detected_unif'!=testm[1,1]){
|
||||
local constrnt`u' = "constraint `u' 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))"
|
||||
qui `constrnt`u''
|
||||
}
|
||||
}
|
||||
* Définition du modèle
|
||||
local mod "gsem "
|
||||
local conformula = ""
|
||||
forvalues i=1/`nbitems' {
|
||||
local mod = "`mod'"+"(1.item`i'<-THETA@1)"
|
||||
if (`nbmoda_`i''==3) {
|
||||
local mod = "`mod'"+"(2.item`i'<-THETA@2)(3.item`i'<-THETA@3)"
|
||||
}
|
||||
else if (`nbmoda_`i''==2) {
|
||||
local mod = "`mod'"+"(2.item`i'<-THETA@2)"
|
||||
}
|
||||
}
|
||||
forvalues u=1/`nbdetect' {
|
||||
local v=`difitems`u''
|
||||
local mod = "`mod'"+"(1.item`v'<-THETA@1 tt)"
|
||||
if (`nbmoda_`v''==3) {
|
||||
local mod = "`mod'"+"(2.item`v'<-THETA@2 tt)(3.item`v'<-THETA@3 tt)"
|
||||
}
|
||||
else if (`nbmoda_`v''==2) {
|
||||
local mod = "`mod'"+"(2.item`v'<-THETA@2 tt)"
|
||||
}
|
||||
local w= 100+`u'
|
||||
qui levelsof dif_detect_unif_`u'
|
||||
local detected=r(levels)
|
||||
local unif_`u'=r(levels)
|
||||
if (`detected'!=testm[1,1] & `nbmoda_`v''==3) {
|
||||
local conformula = "`conformula'" + "`u' " + "`w' "
|
||||
}
|
||||
else if (`detected'!=testm[1,1] & `nbmoda_`v''==2) {
|
||||
local conformula = "`conformula'" + "`u' "
|
||||
}
|
||||
}
|
||||
if ("`conformula'" != "") {
|
||||
local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent constraint(`conformula')"
|
||||
}
|
||||
else {
|
||||
local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent"
|
||||
}
|
||||
*calcul du modèle
|
||||
qui `mod'
|
||||
mat V=r(table)
|
||||
mat W=V[1..2,1...]
|
||||
|
||||
* compilation
|
||||
forvalues j=1/`nbitems' {
|
||||
forvalues z=1/`nbmoda_`j'' {
|
||||
mat outmat[`k',colnumb(outmat,"item`j'_`z'")] = W[1,colnumb(W,"`z'.item`j':_cons")]
|
||||
}
|
||||
}
|
||||
|
||||
* compilation DIF
|
||||
forvalues u=1/`nbdetect' {
|
||||
local j=`difitems`u''
|
||||
forvalues z=1/`nbmoda_`j'' {
|
||||
mat outmat[`k',colnumb(outmat,"dif_`u'_`z'")] = W[1,colnumb(W,"`z'.item`j':tt")]
|
||||
}
|
||||
mat outmat[`k',colnumb(outmat,"dif_detect_`u'")] = `j'
|
||||
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
|
||||
}
|
||||
putexcel set "`path_res'/`s'`scen'_`Nn'_original.xls", sheet("outmat") replace
|
||||
putexcel A1=matrix(outmat), colnames
|
||||
}
|
||||
}
|
||||
}
|
388
Scripts/Analysis/DIF-ROSALI/pcm_dif_rosali_nolrt.do
Normal file
388
Scripts/Analysis/DIF-ROSALI/pcm_dif_rosali_nolrt.do
Normal file
@ -0,0 +1,388 @@
|
||||
*=================================================================================================================================================
|
||||
* Date : 2024-01-23
|
||||
* Stata version : Stata 18 SE
|
||||
*
|
||||
* This program analyses simulated data accounting for DIF through a partial credit model
|
||||
*
|
||||
* ado-files needed : - pcm, rosali (version 5.5 October 25, 2023, available on gitea)
|
||||
*
|
||||
*
|
||||
*================================================================================================================================================
|
||||
adopath+"/home/corentin/Documents/These/Recherche/Simulations/Modules/rosali_custom"
|
||||
|
||||
|
||||
local N = "50 100 200 300"
|
||||
local ss = "2 4 8 12 16 20"
|
||||
foreach s in `ss' {
|
||||
foreach Nnn in `N' {
|
||||
local Nn = `Nnn'
|
||||
local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N`Nn'"
|
||||
if (`s'<=4) {
|
||||
local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N`Nn'"
|
||||
}
|
||||
local path_res = "/home/corentin/Documents/These/Recherche/Simulations/Analysis/ROSALI-DIF-IMPROVED/MIMIC-NOLRT/N`Nn'"
|
||||
local path_log = "/home/corentin/Documents/These/Recherche/Simulations/Analysis/ROSALI-DIF/log/"
|
||||
local scenarios = "A B C D E"
|
||||
if (`s' <= 4) {
|
||||
local scenarios = "A B C"
|
||||
}
|
||||
foreach scen in `scenarios' {
|
||||
clear
|
||||
import delim "`path_data'/scenario_`s'`scen'_`Nn'.csv", encoding(ISO-8859-2) case(preserve) clear
|
||||
rename TT tt
|
||||
log using "`path_log'/log_`s'`scen'_`Nn'.log", replace
|
||||
if (`s'<=2) {
|
||||
local nbitems=4
|
||||
}
|
||||
else if (`s'<=4) {
|
||||
local nbitems=7
|
||||
}
|
||||
else if (`s'<=12) {
|
||||
local nbitems=4
|
||||
}
|
||||
else {
|
||||
local nbitems=7
|
||||
}
|
||||
|
||||
if (mod(`s',2)==0) {
|
||||
local nbmoda=3
|
||||
}
|
||||
else {
|
||||
local nbmoda=1
|
||||
}
|
||||
|
||||
if (`s'<=4) {
|
||||
local nbdif=0
|
||||
}
|
||||
else if (`s'<=8) {
|
||||
local nbdif=1
|
||||
}
|
||||
else if (`s'<=16) {
|
||||
local nbdif=2
|
||||
}
|
||||
else {
|
||||
local nbdif=3
|
||||
}
|
||||
* taillemat = Maximum J*M cases pour les items par et J*M cases pour les dif par + J cases pour les DIF detect + nbdif cases pour dif réel
|
||||
local taillemat=2*`nbitems'*`nbmoda'+`nbitems'+`nbdif'+2+1
|
||||
if (mod(`s',2)==0) {
|
||||
local taillemat=2*`nbitems'*`nbmoda'+`nbitems'+`nbitems'+`nbdif'+2+1
|
||||
}
|
||||
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' "
|
||||
}
|
||||
}
|
||||
|
||||
forvalues i=1/`nbdif' {
|
||||
local colna = "`colna'"+"real_dif_`i' "
|
||||
}
|
||||
local colna = "`colna'" + "beta " + "se_beta " + "lrt_passed"
|
||||
|
||||
mat outmat = J(1000,`taillemat',.)
|
||||
mat colnames outmat= `colna'
|
||||
di "Scenario `s'`scen' / N=`Nnn'"
|
||||
forvalues k=1/1000 {
|
||||
di "###################################################################################"
|
||||
di "###################################################################################"
|
||||
di "###################################################################################"
|
||||
di "Scenario `s'`scen' N=`Nn' ########## `k'/1000"
|
||||
di "###################################################################################"
|
||||
di "###################################################################################"
|
||||
di "###################################################################################"
|
||||
|
||||
preserve
|
||||
qui keep if replication==`k'
|
||||
|
||||
|
||||
* MERGE des modalités si non représentées
|
||||
|
||||
if (`nbmoda'>1 & `Nn'==50) {
|
||||
local com_z = 0
|
||||
qui gen comz = 0
|
||||
forvalues j = 1 / `nbitems' {
|
||||
local recoda_`j' = 0
|
||||
qui tab item`j' if tt == 0, matrow(rect1_g0_`j') matcell(nbrt1_g0_`j')
|
||||
local maxm`j'_t1_g0 = rect1_g0_`j'[r(r),1]
|
||||
local minm`j'_t1_g0 = rect1_g0_`j'[1,1]
|
||||
|
||||
qui tab item`j' if tt == 1, matrow(rect1_g1_`j') matcell(nbrt1_g1_`j')
|
||||
local minm`j'_t1_g1 = rect1_g1_`j'[1,1]
|
||||
local maxm`j'_t1_g1 = rect1_g1_`j'[r(r),1]
|
||||
|
||||
local minm_`j' = min(`minm`j'_t1_g0',`minm`j'_t1_g1')
|
||||
local maxm_`j' = max(`maxm`j'_t1_g0',`maxm`j'_t1_g1')
|
||||
local nbm_`j' = `=`maxm_`j''-`minm_`j'''
|
||||
|
||||
if `minm_`j'' != 0 & `com_z' == 0 {
|
||||
local com_z = 1
|
||||
}
|
||||
|
||||
qui count if item`j' == 3 & tt == 0
|
||||
local mod3plac = r(N)
|
||||
qui count if item`j' == 3 & tt == 1
|
||||
local mod3tt = r(N)
|
||||
local nb_rn3 = min(`mod3plac',`mod3tt')
|
||||
if `nb_rn3'==0 {
|
||||
qui replace comz = 1
|
||||
}
|
||||
|
||||
forvalues m = 0/`=`nbm_`j''-1' {
|
||||
qui count if item`j' == `m' & tt == 0
|
||||
local nb_rn1_g0 = r(N)
|
||||
qui count if item`j' == `m' & tt == 1
|
||||
local nb_rn1_g1 = r(N)
|
||||
local nb_rn = min(`nb_rn1_g0',`nb_rn1_g1')
|
||||
if `nb_rn' == 0 {
|
||||
qui replace comz = 1
|
||||
local recoda_`j' = 1
|
||||
if `m' == 0 | `m' < `minm`j'_t1_g0' | `m' < `minm`j'_t1_g1' {
|
||||
local stop = 1
|
||||
forvalues kk = 1/`=`nbm_`j''-`m'' {
|
||||
qui count if item`j' == `=`m' + `kk'' & tt == 0
|
||||
local v`kk'1_0 = r(N)
|
||||
qui count if item`j' == `=`m' + `kk'' & tt == 1
|
||||
local v`kk'1_1 = r(N)
|
||||
if (`v`kk'1_0' != 0 | `v`kk'1_1' != 0) & `stop' != 0 {
|
||||
qui replace item`j'= `=`m'+`kk'' if item`j'==`m'
|
||||
local zzz=`j'+`nbitems'
|
||||
*qui replace item`zzz'=`=`m'+`kk'' if item``=`j'+`nbitems'''==`m'
|
||||
*di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
|
||||
local stop = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
else if `m' == `=`nbm_`j''-1' | `m' >= `maxm`j'_t1_g1' {
|
||||
local stop = 1
|
||||
forvalues kk = 1/`=`m'' {
|
||||
qui count if item`j' == `=`m' - `kk'' & tt == 0
|
||||
local v`kk'1_0 = r(N)
|
||||
qui count if item`j' == `=`m' - `kk'' & tt == 1
|
||||
local v`kk'1_1 = r(N)
|
||||
if (`v`kk'1_0' != 0 | `v`kk'1_1' != 0) & `stop' != 0 {
|
||||
qui replace item`j'= `=`m' - `kk'' if item`j'==`m'
|
||||
local zzz=`j'+`nbitems'
|
||||
*qui replace item`zzz'= `=`m' - `kk'' if item`zzz'==`m'
|
||||
*di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
|
||||
local stop = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
if runiform()>0.5{
|
||||
local stop = 1
|
||||
forvalues kk = 1/`m' {
|
||||
qui count if item`j' == `=`m' - `kk'' & tt == 0
|
||||
local v`kk'1_0 = r(N)
|
||||
qui count if item`j' == `=`m' - `kk'' & tt == 1
|
||||
local v`kk'1_1 = r(N)
|
||||
if (`v`kk'1_0' != 0 | `v`kk'1_1' != 0) & `stop' != 0 {
|
||||
qui replace item`j'= `=`m'-`kk'' if item`j'==`m'
|
||||
local zzz=`j'+`nbitems'
|
||||
*qui replace item`zzz'=`=`m'-`kk'' if item``=`j'+`nbitems'''==`m'
|
||||
*di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
|
||||
local stop = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
local stop = 1
|
||||
forvalues kk = 1/`=`nbm_`j''-`m'' {
|
||||
qui count if item`j' == `=`m' + `kk'' & tt == 0
|
||||
local v`kk'1_0 = r(N)
|
||||
qui count if item`j' == `=`m' + `kk'' & tt == 1
|
||||
local v`kk'1_1 = r(N)
|
||||
if (`v`kk'1_0' != 0 | `v`kk'1_1' != 0) & `stop' != 0{
|
||||
qui replace item`j'=`=`m' + `kk'' if item`j'==`m'
|
||||
local zzz=`j'+`nbitems'
|
||||
*qui replace item`zzz'=`=`m' + `kk'' if item``=`j'+`nbitems'''==`m'
|
||||
*di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
|
||||
local stop = 0
|
||||
}
|
||||
else {
|
||||
if `stop' != 0 {
|
||||
qui replace item`j'= `nbm_`j'' if item`j'==`m'
|
||||
local zzz=`j'+`nbitems'
|
||||
*qui replace item`zzz'= `nbm_`j'' if item``=`j'+`nbitems'''==`m'
|
||||
*di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
|
||||
local stop = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
qui levelsof item`j'
|
||||
local val = r(levels)
|
||||
local checker: word 1 of `val'
|
||||
local checker2: word 2 of `val'
|
||||
local checker3: word 3 of `val'
|
||||
local nummoda=r(r)
|
||||
local nbmoda_`j'=`nummoda'-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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
qui valuesof comz
|
||||
local val = r(values)
|
||||
local checker: word 1 of `val'
|
||||
}
|
||||
else {
|
||||
forvalues jj=1/`nbitems' {
|
||||
local nbmoda_`jj'=`nbmoda'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
* ROSALI
|
||||
rosali_nolrt_screening item1-item`nbitems' item1-item`nbitems', group(tt)
|
||||
qui mat resmat=r(difitems)
|
||||
local nbitems2 = 2*`nbitems'
|
||||
mat lrt_passed = resmat[1,`nbitems2'+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''
|
||||
}
|
||||
}
|
||||
|
||||
* 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'
|
||||
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
|
||||
`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'
|
||||
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")]
|
||||
qui mat outmat[`k',colnumb(outmat,"lrt_passed")]=lrt_passed[1,1]
|
||||
restore
|
||||
}
|
||||
log close
|
||||
putexcel set "`path_res'/`s'`scen'_`Nn'_original.xls", sheet("outmat") replace
|
||||
putexcel A1=matrix(outmat), colnames
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user