diff --git a/Modules/simirt.R b/Modules/simirt.R
deleted file mode 100644
index babf68c..0000000
--- a/Modules/simirt.R
+++ /dev/null
@@ -1,274 +0,0 @@
-simIRT <- function(NBOBS=2000,DIM=NULL,MU=NULL,COV=NULL,COVM=NULL,DIS=NULL,DIF=NULL,PMIN=NULL,PMAX=NULL,ACC=NULL,CLEAR=NULL,STORE=NULL,REP=NULL,PREF=NULL,DRAW=NULL,
- TYPEDIF=NULL,DRAWALL=NULL,ICC,GR=0,RAND=NULL,DELTAGR=0,RSM1=NULL,RSM2=NULL,THR=NULL,TIT=NULL,PCM=NULL,ID=NULL,GENP=NULL,GENI=NULL) {
-
-if (GR < 0 | GR > 1) {
- stop('Error 198: The GR option defines a probability. The values defined by this option must be greater (or equal) to 0 and lesser (or equal) to 1.')
-}
-
-if ( is.null(CLEAR) & is.null(STORE) ) {
- stop('Error 198: You must use at least one of these two options: clear and/or store.')
-}
-
-if (!is.null(DIM)) {
- nbdim <- length(DIM)
- if (nbdim > 2 & is.null(COVM)) {
- stop('Error 198: You can simulate data with one or two dimensions, and you have indicated more dimensions in the DIM option. Please correct it.')
- }
-
- if (!is.null(COVM)) {
- nbrowcovm <- nrow(COVM)
- if (nbdim != nbrowcovm) {
- stop('Error 198: DIM and COVM dimension mismatch. Please correct.')
- }
- }
-
- nbitems <- sum(DIM)
-
- if (!is.null(DIF)) {
- nbdiff <- length(DIF)
- tmp <- TYPEDIF
- if (tmp=='gauss' | tmp=='uniform') {
- typediff <- tmp
- }
- else if (nbdiff != nbitems) {
- stop('Error 198: "You have indicated a number of difficulty parameters (DIF option) different of the number of items to simulate (DIM option). Please correct these options.')
- }
- }
-
- else if (is.null(DIF)) {
- DIF <- vector(mode='list', length=DIM)
- for (d in seq(1,DIM)) {
- DIF[[d]] <- c('gauss',0,1)
- }
- typediff <- 'gauss'
- nbdiff <- length(DIF)*3
- }
-
-}
-
-else if (is.null(DIM)) {
- if (is.null(DIF) & is.null(PCM)) {
- stop('Error 198: You must indicate the number of items to simulate in the DIM, DIF or PCM options.')
- }
- else if (!is.null(COVM)) {
- nbrowcovm <- nrow(COVM)
- if (nbrowcovm>1) {
- stop('Error 198: You affected dimensions with COVM, but you did not affect each item to a dimension with the DIM option. Please correct DIM.')
- }
- }
- else if (!is.null(PCM)) {
- nbitems <- nrow(PCM)
- DIM <- c(1)
- }
- else {
- nbdiff <- length(DIF)
- nbitems <- nbdiff
- DIM <- c(1)
- }
-}
-
-if ( (GR!=0 | DELTAGR!=0) & any(DIM != 1) & length(DIM)==1 ) {
- stop('The GR and DELTAGR options are available only with unidimensional simulated data.')
-}
-
-if (is.null(PREF)) {
- PREF <- 'item'
-}
-
-nbprefix <- length(PREF)
-
-if (nbprefix!=length(DIM) & nbprefix!=1) { # ici, DIM est un vecteur contenant les nombres d'items par dim, mais est juste le nbre de dim dans stata
- stop('Error 198: The PREF option is incorrect because the number of prefixes is different from the number of dimensions set in DIM. Please correct.')
-}
-
-if (nbprefix!=length(DIM)) {
- alphab <- c('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z')
- prefix <- paste0(prefix,alphab[seq(1,length(DIM))])
-}
-
-if (is.null(COVM)) {
- nbcov <- length(COV)
- if (length(DIM)==1) {
- if (is.null(COV)) {
- COV <- 1
- }
- if (nbcov>1) {
- stop('Error 198: You simulate only one dimension, you must indicate only the variance of the simulated latent trait in the COV argument.')
- }
- if (COV <0) {
- stop('Error 198: The variance of the latent trait cannot be negative. Please correct the COV option.')
- }
- covmatrix2 <- COV # cov doit être une matrice pré formatée
- }
- else if (length(DIM)==2) {
- if (nbcov!=4 & nbcov>0) {
- stop("Error 198: You simulate 2 dimensions. The COV option must be a 2x2 covariance matrix.")
- }
- else if (nbcov==0) {
- if (length(DIM)==1) {
- COV <- 1
- }
- else if (length(DIM)==2) {
- COV <- matrix(c(1,0,0,1),nrow=2,byrow = T)
- }
- nbcov <- length(COV)
- }
- if (nbcov==4) {
- cov1 <- COV[1,1]
- cov2 <- COV[2,2]
- cov3 <- COV[1,2]
- rho <- cov3/sqrt(cov1*cov2)
- if (cov1<0 | cov2<0 | rho< -1 | rho>1) {
- stop('Error 198: The covariance matrix in COV is not correct. Please correct it.')
- }
- }
- covmatrix2 <- COV
- }
- COVM <- COV
-}
-
-nbmu <- length(MU)
-if (nbmu!=length(DIM) & nbmu!=0) {
- stop('Error 198: You must indicate as many values in MU as the number of dimensions in DIM.')
-}
-
-nbdisc <- length(DIS)
-if (nbdisc!=nbitems & nbdisc!=0) {
- stop('Error 198: You must indicate as many values in DISC as the number of items in DIM and DIF.')
-}
-
-nbpmin <- length(PMIN)
-if (nbpmin!=nbitems & nbpmin!=0) {
- stop('Error 198: You must indicate as many values in PMIN as the number of items in DIM and DIF.')
-}
-
-nbpmax <- length(PMAX)
-if (nbpmax!=nbitems & nbpmax!=0) {
- stop('Error 198: You must indicate as many values in PMAX as the number of items in DIM and DIF.')
-}
-
-nbacc <- length(ACC)
-if (nbacc != nbitems & nbacc!=0) {
- stop('Error 198: You must indicate as many values in ACC as the number of items in DIM and DIF.')
-}
-
-if (!is.null(THR) & any(!is.null(c(DIS,PMIN,PMAX,ACC)))) {
- stop('Error 198: If you use the THR option, you cannot use DIS, PMIN, PMAX or ACC.')
-}
-
-if (any(!is.null(c(RSM1,RSM2))) & any(!is.null(c(DIS,PMIN,PMAX,ACC)))) {
- stop('Error 198: If you use the RSM1 and/or RSM2 option, you cannot use DIS, PMIN, PMAX or ACC.')
-}
-
-if (!is.null(PCM) & any(!is.null(c(DIS,PMIN,PMAX,ACC)))) {
- stop('Error 198: If you use the PCM option, you cannot use DIS, PMIN, PMAX or ACC.')
-}
-
-if (any(!is.null(c(RSM1,RSM2))) & !is.null(PCM)) {
- stop('Error 198: If you use the RSM1 and/or RSM2 option, you cannot use PCM.')
-}
-if (!is.null(RSM2) & length(DIM)==1) {
- stop('Error 198: You cannot use RSM2 if you simulate only one dimension.')
-}
-if (is.null(ID)) {
- ID <- 'ID'
-}
-
-
-##### Paramètres
-
-hour <- as.numeric(substr(Sys.time(),12,13))
-minu <- as.numeric(substr(Sys.time(),15,16))
-sec <- as.numeric(substr(Sys.time(),18,19))
-jour <- as.numeric(substr(Sys.Date(),9,10))
-
-s <- 256484+1000000*sec+10000*minu+100*hour+jour
-set.seed(s)
-while(s>2^31-1) {
- s <- s/231
-}
-set.seed(s)
-
-if (typediff=='uniform') {
- min <- c()
- max <- c()
- if (nbdiff %/% (2*length(DIM))==1) {
- min <- DIF[(1:length(DIM)-1)*2+2]
- max <- DIF[(1:length(DIM)-1)*2+3]
- }
- else if (nbdiff==1) {
- min <- rep(-2,length(DIM))
- max <- rep(2,length(DIM))
- }
- else {
- stop('Your DIF option is incorrect. Please correct.')
- }
- for (d in seq(1,length(DIM))) {
- for (i in seq(1,DIM[d])) {
- DIF <- c(DIF, min[d]+(max[d]-min[d])*i/(DIM[d]+1) ) # Pas compris, demander à JB
- }
- }
-}
-
-else if (typediff=='gauss') {
- meang <- c()
- varg <- c()
- if (nbdiff %/% (2*length(DIM))==1) {
- for (d in seq(1,length(DIM))) {
- meang[d] <- DIF[(d-1)*2+2]
- varg[d] <- DIF[(d-1)*2+3]
- }
- }
- else if (nbdiff == 1) {
- meang <- rep(0,length(DIM))
- varg <- rep(1,length(DIM))
- }
- else {
- stop('Error 198: Your DIF option is incorrect. Please correct.')
- }
- for (d in seq(1,length(DIM))) {
- for (i in seq(1,DIM[d])) {
- tmp <- qnorm(p=i/(DIM[d]+1))*sqrt(varg[d])+meang[d]
- DIF <- c(DIF, tmp)
- }
- }
-
-}
-
-nbrsm <- c()
-for (d in 1:2) {
- if (!is.null(get(paste0('RSM',d)))) {
- nbrsm[d] <- length(get(paste0('RSM',d)))
- for (i in seq(2,nbrsm[d]+1)) {
- rsm[[d]][i] <- get(paste0("RSM",d))[i-1] # RSM doit etre une liste de vecteurs
- if (!is.null(THR) & rsm[[d]][i]<0) {
- stop('Error 198: With the THR option, the numbers defined in RSM1 and RSM2 must nonnegative')
- }
- }
- }
-}
-
-if (!is.null(DIF) & is.null(PCM)) {
- PCM <- as.matrix(DIF)
-}
-
-matdiff <- as.matrix(rep(0,nbitems))
-matdisc <- as.matrix(rep(0,nbitems))
-matpmin <- as.matrix(rep(0,nbitems))
-matpmax <- as.matrix(rep(0,nbitems))
-matacc <- as.matrix(rep(0,nbitems))
-matmu <- as.matrix(rep(0,length(DIM)))
-matmu <- as.matrix(rep(0,(length(DIM)+1)*length(DIM)/2 ))
-
-if (nbdisc !=0) {
- matdisc <- as.matrix(DISC)
-}
-else {
- matdisc <- rep(1,nbitems)
-}
-
-
-
-
-
-}
diff --git a/Plans/plan_rct_base.md b/Plans/plan_rct_base.md
deleted file mode 100644
index 7975e0b..0000000
--- a/Plans/plan_rct_base.md
+++ /dev/null
@@ -1,3 +0,0 @@
-# Simulation 0 - Essai contrôlé randomisé sans DIF
-
-## Paramètres
diff --git a/README.md b/README.md
index 046e1a4..f5d5d5f 100644
--- a/README.md
+++ b/README.md
@@ -1,8 +1,8 @@
# Simulations
-Ce dépôt contient l'ensemble du code pour les simulations basées sur simIRT. Afin d'économiser de la place sur le serveur, les données générées ne sont pas inclues dans le dépôt mais sont disponibles sur https://osf.io.
+This repository contains all code files related to our ROSALI/Resiuals RCT simulation project. In order to save disk space, data files are not stored on this server and are instead available on https://osf.io.
-## Arborescence
+## File Structure
```
📦 simul_these
@@ -15,41 +15,41 @@ Ce dépôt contient l'ensemble du code pour les simulations basées sur simIRT.
│ ├─ 🗂️ rosali_custom - DATASETS WITH DIF
│ ├─ simirt.do
│ └─ simirt.R
-├─ 🗂️ Plans - SIMULATION PLANS
-├─ 🗂️ RProject - R SCRIPTS FOR COMPILING RESULTS
+├─ 🗂️ RProject - R SCRIPTS FOR VARIOUS TASKS
└─ 🗂️ Scripts - R AND STATA SCRIPTS
├─ 🗂️ Analysis - PCM ANALYSIS SCRIPTS
- ├─ 🗂️ R - VARIOUS USEFUL R SCRIPTS
- └─ 🗂️ Scenarios - SIMULATION SCENARIO SCRIPTS
+ └─ 🗂️ Data_generation - SIMULATION SCENARIO SCRIPTS
├─ 🗂️ DIF
└─ 🗂️ noDIF
```
-## Conventions de nomenclature
+## Naming conventions
-### Jeux de données initiaux
+### Initial Datasets
-**XX_N** - Scénarios de référence sans confusion / N réplications
-**1XX_N** - Scénarios avec confusion induite par 1 covariable / N réplications
-**2XX_N** - Scénarios avec confusion induite par 2 covariables / N réplications
-**3XX_N** - Scénarios avec confusion induite par 1 covariable induisant du DIF / N réplications
+**XX_N** - Scenario XX / N individuals per group
-### Jeux de données analysés
+### Analyzed Datasets
+
+**noDIF / XX_N.csv** - Analysis for scenario XX_N by PCM __without__ accounting for DIF
+**DIF / XX_N.xls** - Analysis for scenario XX_N by PCM __with__ DIF accounted for
+**ROSALI-DIF / XX_N_original.xls** - Analysis for scenario XX_N by PCM __with__ DIF accounted for after detection by ROSALI
+**RESIDUALS / XX_N_original.xls** - Analysis for scenario XX_N by PCM __with__ DIF accounted for after detection by Andrich & Hagquist's residuals method
-**noDIF / XX_N.csv** - Analyse du scénario XX_N par PCM __sans__ prise en compte du DIF
-**DIF / XX_N.xls** - Analyse du scénario XX_N par PCM __avec__ prise en compte du DIF
-**ROSALI-DIF / XX_N_original.xls** - Analyse du scénario XX_N par PCM __avec__ prise en compte du DIF détecté par ROSALI-DIF
-**RESALI / XX_N_original.xls** - Analyse du scénario XX_N par PCM __avec__ prise en compte du DIF détecté par la méthode des résidus de Andrich & Hagquist
## Reproduction
-1. Lancer **/Scripts/Scenarios/NoDIF/scenarios_noDIF_baseline.do** pour simuler les données des scénarios sans DIF
-2. Lancer tous les fichiers dans 🗂️ **/Scripts/Scenarios/DIF/** pour simuler les données des scénarios avec DIF
-3. Lancer les fichiers dans 🗂️ **/RProject/Scripts/functions/** puis **/RProject/Scripts/pcm_nodif.R** pour analyser les données sans prise en compte du DIF
-4. Lancer les fichiers dans 🗂️ **/Scripts/Analysis/DIF/** pour analyser les données avec prise en compte du DIF
-5. Lancer **/Scripts/Analysis/DIF-ROSALI/pcm_dif_rosali.do** pour analyser les données avec prise en compte du DIF détecté par ROSALI-DIF
-6. Lancer **/RProject/Scripts/resali_generate_newdata.R** pour mettre détecter le DIF avec la méthode des résidus et préparer les données pour l'analyse.
-7. Lancer **/Scripts/Analysis/DIF-RESIDUS/pcm_dif_residus.do** pour analyser les données avec prise en compte du DIF détecté par la méthode des résidus
-8. Lancer **/RProject/Scripts/aggregation.R** pour compiler les résultats dans des tableaux complets
+1. Run **/Scripts/Data_generation/NoDIF/scenarios_noDIF_baseline.do** to simulate no DIF data
+2. Run files in 🗂️ **/Scripts/Data_generation/DIF/** to simulate DIF data
+3. Run **/RProject/Scripts/Analysis/pcm_nodif.R** to analyze without accounting for DIF
+4. Run files in 🗂️ **/Scripts/Analysis/DIF/** to analyze while accounting for DIF
+5. Run **/Scripts/Analysis/DIF-ROSALI/pcm_dif_rosali.do** to analyze data after accounting for DIF as detected by ROSALI
+6. Run **/RProject/Scripts/Analysis/resali_analysis.R** to perform residuals DIF detection and prepare data for PCM analysis.
+7. Run **/Scripts/Analysis/DIF-RESIDUALS/pcm_dif_residus.do** to analyze data after accounting for DIF as detected by the residuals method
+8. Run **/RProject/Scripts/Analysis/aggregation.R** to compile and visualize results
+
+**OR**
+
+1. Run **autorun.sh** (by default, will take multiple weeks to run. Please modify to run in parrallel if necessary)
diff --git a/RProject/Scripts/aggregation.R b/RProject/Scripts/Analysis/aggregation.R
similarity index 99%
rename from RProject/Scripts/aggregation.R
rename to RProject/Scripts/Analysis/aggregation.R
index 2339800..9890421 100644
--- a/RProject/Scripts/aggregation.R
+++ b/RProject/Scripts/Analysis/aggregation.R
@@ -17,6 +17,8 @@ lastChar <- function(str){
substr(str, nchar(str), nchar(str))
}
+source(paste0(getwd(),"/functions/resali.R"))
+
##############################################################################
#----------------------------------------------------------------------------#
############################# ANALYSIS FUNCTIONS #############################
diff --git a/RProject/Scripts/article.R b/RProject/Scripts/Analysis/article.R
similarity index 99%
rename from RProject/Scripts/article.R
rename to RProject/Scripts/Analysis/article.R
index b396463..94c1e34 100644
--- a/RProject/Scripts/article.R
+++ b/RProject/Scripts/Analysis/article.R
@@ -1,9 +1,5 @@
-
-
-
-
-
+source(paste0(getwd(),"/functions/resali.R"))
##########################
# IGNORING DIF
@@ -110,11 +106,6 @@ summary(res.dat.dif.resali[res.dat.dif.resali$nb.dif==0,"true.value.in.ci.p"])
summary(res.dat.dif.rosali[res.dat.dif.rosali$nb.dif==0,"true.value.in.ci.p"])
-####################################################
-# TABLES
-####################################################
-
-
##########################
# TABLES NO DIF RECOVERY
##########################
diff --git a/RProject/Scripts/functions/resali.R b/RProject/Scripts/Analysis/functions/resali.R
similarity index 100%
rename from RProject/Scripts/functions/resali.R
rename to RProject/Scripts/Analysis/functions/resali.R
diff --git a/RProject/Scripts/pcm_nodif.R b/RProject/Scripts/Analysis/pcm_nodif.R
similarity index 96%
rename from RProject/Scripts/pcm_nodif.R
rename to RProject/Scripts/Analysis/pcm_nodif.R
index 9cd3e30..e4747ee 100644
--- a/RProject/Scripts/pcm_nodif.R
+++ b/RProject/Scripts/Analysis/pcm_nodif.R
@@ -16,6 +16,8 @@ lastChar <- function(str){
substr(str, nchar(str)-2, nchar(str))
}
+source(paste0(getwd(),"/functions/resali.R"))
+
##############################################################################
#----------------------------------------------------------------------------#
############################# ANALYSIS FUNCTIONS #############################
@@ -2058,26 +2060,26 @@ registerDoMC(5)
###################################### Scenario A
-dat1 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_1A_50.csv')
-dat2 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_2A_50.csv')
-dat3 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_3A_50.csv')
-dat4 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_4A_50.csv')
-dat5 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_5A_50.csv')
-dat6 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_6A_50.csv')
-dat7 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_7A_50.csv')
-dat8 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_8A_50.csv')
-dat9 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_9A_50.csv')
-dat10 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_10A_50.csv')
-dat11 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_11A_50.csv')
-dat12 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_12A_50.csv')
-dat13 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_13A_50.csv')
-dat14 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_14A_50.csv')
-dat15 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_15A_50.csv')
-dat16 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_16A_50.csv')
-dat17 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_17A_50.csv')
-dat18 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_18A_50.csv')
-dat19 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_19A_50.csv')
-dat20 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_20A_50.csv')
+dat1 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N50/scenario_1A_50.csv')
+dat2 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N50/scenario_2A_50.csv')
+dat3 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N50/scenario_3A_50.csv')
+dat4 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N50/scenario_4A_50.csv')
+dat5 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_5A_50.csv')
+dat6 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_6A_50.csv')
+dat7 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_7A_50.csv')
+dat8 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_8A_50.csv')
+dat9 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_9A_50.csv')
+dat10 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_10A_50.csv')
+dat11 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_11A_50.csv')
+dat12 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_12A_50.csv')
+dat13 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_13A_50.csv')
+dat14 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_14A_50.csv')
+dat15 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_15A_50.csv')
+dat16 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_16A_50.csv')
+dat17 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_17A_50.csv')
+dat18 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_18A_50.csv')
+dat19 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_19A_50.csv')
+dat20 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_20A_50.csv')
res <- pbmclapply(paste0("dat",1:20),function(x) replicate_pcm_analysis(get(x),eff.size = 0))
@@ -2106,26 +2108,26 @@ write.csv(res[[20]],'/home/corentin/Documents/These/Recherche/Simulations/Analys
###################################### Scenario B
-dat1 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_1B_50.csv')
-dat2 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_2B_50.csv')
-dat3 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_3B_50.csv')
-dat4 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_4B_50.csv')
-dat5 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_5B_50.csv')
-dat6 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_6B_50.csv')
-dat7 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_7B_50.csv')
-dat8 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_8B_50.csv')
-dat9 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_9B_50.csv')
-dat10 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_10B_50.csv')
-dat11 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_11B_50.csv')
-dat12 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_12B_50.csv')
-dat13 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_13B_50.csv')
-dat14 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_14B_50.csv')
-dat15 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_15B_50.csv')
-dat16 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_16B_50.csv')
-dat17 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_17B_50.csv')
-dat18 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_18B_50.csv')
-dat19 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_19B_50.csv')
-dat20 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_20B_50.csv')
+dat1 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N50/scenario_1B_50.csv')
+dat2 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N50/scenario_2B_50.csv')
+dat3 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N50/scenario_3B_50.csv')
+dat4 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N50/scenario_4B_50.csv')
+dat5 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_5B_50.csv')
+dat6 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_6B_50.csv')
+dat7 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_7B_50.csv')
+dat8 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_8B_50.csv')
+dat9 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_9B_50.csv')
+dat10 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_10B_50.csv')
+dat11 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_11B_50.csv')
+dat12 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_12B_50.csv')
+dat13 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_13B_50.csv')
+dat14 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_14B_50.csv')
+dat15 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_15B_50.csv')
+dat16 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_16B_50.csv')
+dat17 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_17B_50.csv')
+dat18 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_18B_50.csv')
+dat19 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_19B_50.csv')
+dat20 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_20B_50.csv')
res <- pbmclapply(paste0("dat",1:20),function(x) replicate_pcm_analysis(get(x),eff.size = 0.2))
@@ -2154,26 +2156,27 @@ write.csv(res[[20]],'/home/corentin/Documents/These/Recherche/Simulations/Analys
###################################### Scenario C
-dat1 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_1C_50.csv')
-dat2 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_2C_50.csv')
-dat3 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_3C_50.csv')
-dat4 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_4C_50.csv')
-dat5 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_5C_50.csv')
-dat6 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_6C_50.csv')
-dat7 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_7C_50.csv')
-dat8 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_8C_50.csv')
-dat9 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_9C_50.csv')
-dat10 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_10C_50.csv')
-dat11 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_11C_50.csv')
-dat12 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_12C_50.csv')
-dat13 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_13C_50.csv')
-dat14 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_14C_50.csv')
-dat15 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_15C_50.csv')
-dat16 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_16C_50.csv')
-dat17 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_17C_50.csv')
-dat18 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_18C_50.csv')
-dat19 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_19C_50.csv')
-dat20 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_20C_50.csv')
+dat1 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N50/scenario_1C_50.csv')
+dat2 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N50/scenario_2C_50.csv')
+dat3 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N50/scenario_3C_50.csv')
+dat4 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N50/scenario_4C_50.csv')
+dat5 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_5C_50.csv')
+dat6 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_6C_50.csv')
+dat7 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_7C_50.csv')
+dat8 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_8C_50.csv')
+dat9 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_9C_50.csv')
+dat10 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_10C_50.csv')
+dat11 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_11C_50.csv')
+dat12 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_12C_50.csv')
+dat13 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_13C_50.csv')
+dat14 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_14C_50.csv')
+dat15 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_15C_50.csv')
+dat16 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_16C_50.csv')
+dat17 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_17C_50.csv')
+dat18 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_18C_50.csv')
+dat19 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_19C_50.csv')
+dat20 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_20C_50.csv')
+
res <- pbmclapply(1:20,function(x) replicate_pcm_analysis(get(paste0("dat",x)),eff.size = ifelse(x>4,0.2,0.4)))
@@ -2204,26 +2207,27 @@ write.csv(res[[20]],'/home/corentin/Documents/These/Recherche/Simulations/Analys
###################################### Scenario D
-dat1 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_1D_50.csv')
-dat2 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_2D_50.csv')
-dat3 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_3D_50.csv')
-dat4 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_4D_50.csv')
-dat5 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_5D_50.csv')
-dat6 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_6D_50.csv')
-dat7 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_7D_50.csv')
-dat8 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_8D_50.csv')
-dat9 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_9D_50.csv')
-dat10 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_10D_50.csv')
-dat11 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_11D_50.csv')
-dat12 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_12D_50.csv')
-dat13 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_13D_50.csv')
-dat14 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_14D_50.csv')
-dat15 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_15D_50.csv')
-dat16 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_16D_50.csv')
-dat17 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_17D_50.csv')
-dat18 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_18D_50.csv')
-dat19 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_19D_50.csv')
-dat20 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_20D_50.csv')
+dat1 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N50/scenario_1D_50.csv')
+dat2 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N50/scenario_2D_50.csv')
+dat3 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N50/scenario_3D_50.csv')
+dat4 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N50/scenario_4D_50.csv')
+dat5 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_5D_50.csv')
+dat6 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_6D_50.csv')
+dat7 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_7D_50.csv')
+dat8 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_8D_50.csv')
+dat9 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_9D_50.csv')
+dat10 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_10D_50.csv')
+dat11 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_11D_50.csv')
+dat12 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_12D_50.csv')
+dat13 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_13D_50.csv')
+dat14 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_14D_50.csv')
+dat15 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_15D_50.csv')
+dat16 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_16D_50.csv')
+dat17 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_17D_50.csv')
+dat18 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_18D_50.csv')
+dat19 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_19D_50.csv')
+dat20 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_20D_50.csv')
+
res <- pbmclapply(1:20,function(x) replicate_pcm_analysis(get(paste0("dat",x)),eff.size = ifelse(x>4,0.4,-0.2)))
@@ -2253,26 +2257,27 @@ write.csv(res[[20]],'/home/corentin/Documents/These/Recherche/Simulations/Analys
###################################### Scenario E
-dat1 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_1E_50.csv')
-dat2 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_2E_50.csv')
-dat3 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_3E_50.csv')
-dat4 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_4E_50.csv')
-dat5 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_5E_50.csv')
-dat6 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_6E_50.csv')
-dat7 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_7E_50.csv')
-dat8 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_8E_50.csv')
-dat9 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_9E_50.csv')
-dat10 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_10E_50.csv')
-dat11 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_11E_50.csv')
-dat12 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_12E_50.csv')
-dat13 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_13E_50.csv')
-dat14 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_14E_50.csv')
-dat15 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_15E_50.csv')
-dat16 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_16E_50.csv')
-dat17 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_17E_50.csv')
-dat18 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_18E_50.csv')
-dat19 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_19E_50.csv')
-dat20 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_20E_50.csv')
+dat1 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N50/scenario_1E_50.csv')
+dat2 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N50/scenario_2E_50.csv')
+dat3 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N50/scenario_3E_50.csv')
+dat4 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N50/scenario_4E_50.csv')
+dat5 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_5E_50.csv')
+dat6 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_6E_50.csv')
+dat7 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_7E_50.csv')
+dat8 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_8E_50.csv')
+dat9 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_9E_50.csv')
+dat10 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_10E_50.csv')
+dat11 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_11E_50.csv')
+dat12 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_12E_50.csv')
+dat13 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_13E_50.csv')
+dat14 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_14E_50.csv')
+dat15 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_15E_50.csv')
+dat16 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_16E_50.csv')
+dat17 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_17E_50.csv')
+dat18 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_18E_50.csv')
+dat19 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_19E_50.csv')
+dat20 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_20E_50.csv')
+
res <- pbmclapply(1:20,function(x) replicate_pcm_analysis(get(paste0("dat",x)),eff.size = ifelse(x>4,0.4,-0.4)))
@@ -2299,22 +2304,22 @@ write.csv(res[[20]],'/home/corentin/Documents/These/Recherche/Simulations/Analys
###################################### Scenario F
-dat5 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_5F_50.csv')
-dat6 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_6F_50.csv')
-dat7 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_7F_50.csv')
-dat8 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_8F_50.csv')
-dat9 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_9F_50.csv')
-dat10 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_10F_50.csv')
-dat11 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_11F_50.csv')
-dat12 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_12F_50.csv')
-dat13 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_13F_50.csv')
-dat14 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_14F_50.csv')
-dat15 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_15F_50.csv')
-dat16 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_16F_50.csv')
-dat17 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_17F_50.csv')
-dat18 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_18F_50.csv')
-dat19 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_19F_50.csv')
-dat20 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_20F_50.csv')
+dat5 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_5F_50.csv')
+dat6 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_6F_50.csv')
+dat7 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_7F_50.csv')
+dat8 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_8F_50.csv')
+dat9 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_9F_50.csv')
+dat10 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_10F_50.csv')
+dat11 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_11F_50.csv')
+dat12 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_12F_50.csv')
+dat13 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_13F_50.csv')
+dat14 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_14F_50.csv')
+dat15 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_15F_50.csv')
+dat16 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_16F_50.csv')
+dat17 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_17F_50.csv')
+dat18 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_18F_50.csv')
+dat19 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_19F_50.csv')
+dat20 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_20F_50.csv')
res <- pbmclapply(5:20,function(x) replicate_pcm_analysis(get(paste0("dat",x)),eff.size = -0.2))
@@ -2337,22 +2342,22 @@ write.csv(res[[16]],'/home/corentin/Documents/These/Recherche/Simulations/Analys
###################################### Scenario G
-dat5 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_5G_50.csv')
-dat6 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_6G_50.csv')
-dat7 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_7G_50.csv')
-dat8 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_8G_50.csv')
-dat9 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_9G_50.csv')
-dat10 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_10G_50.csv')
-dat11 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_11G_50.csv')
-dat12 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_12G_50.csv')
-dat13 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_13G_50.csv')
-dat14 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_14G_50.csv')
-dat15 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_15G_50.csv')
-dat16 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_16G_50.csv')
-dat17 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_17G_50.csv')
-dat18 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_18G_50.csv')
-dat19 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_19G_50.csv')
-dat20 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/N50/scenario_20G_50.csv')
+dat5 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_5G_50.csv')
+dat6 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_6G_50.csv')
+dat7 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_7G_50.csv')
+dat8 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_8G_50.csv')
+dat9 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_9G_50.csv')
+dat10 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_10G_50.csv')
+dat11 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_11G_50.csv')
+dat12 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_12G_50.csv')
+dat13 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_13G_50.csv')
+dat14 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_14G_50.csv')
+dat15 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_15G_50.csv')
+dat16 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_16G_50.csv')
+dat17 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_17G_50.csv')
+dat18 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_18G_50.csv')
+dat19 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_19G_50.csv')
+dat20 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N50/scenario_20G_50.csv')
res <- pbmclapply(5:20,function(x) replicate_pcm_analysis(get(paste0("dat",x)),eff.size = -0.4))
diff --git a/RProject/Scripts/resali_generate_newdata.R b/RProject/Scripts/Analysis/resali_analysis.R
similarity index 99%
rename from RProject/Scripts/resali_generate_newdata.R
rename to RProject/Scripts/Analysis/resali_analysis.R
index 19c2d29..5e32ac3 100644
--- a/RProject/Scripts/resali_generate_newdata.R
+++ b/RProject/Scripts/Analysis/resali_analysis.R
@@ -4,6 +4,8 @@
#----------------------------------------------------------------------------#
##############################################################################
+source(paste0(getwd(),"/functions/resali.R"))
+
generate_resali <- function(scenario=NULL,grp=NULL) {
scen <- as.numeric(gsub("[A,B,C,D,E,F,G,_]","",substr(scenario,0,3)))
if (substr(scenario,start=nchar(scenario)-1,stop=nchar(scenario))=="50") {
diff --git a/Scripts/R/generate_item_difficulties.R b/RProject/Scripts/Tools/generate_item_difficulties.R
similarity index 100%
rename from Scripts/R/generate_item_difficulties.R
rename to RProject/Scripts/Tools/generate_item_difficulties.R
diff --git a/RProject/Scripts/dif.R b/RProject/Scripts/dif.R
deleted file mode 100644
index b133633..0000000
--- a/RProject/Scripts/dif.R
+++ /dev/null
@@ -1,27 +0,0 @@
-library(TAM)
-
-pcm_analysis <- function(df=NULL,treatment='TT',irtmodel='PCM2',method='MML') {
- nbitems <- sum(sapply(1:20,function(x) paste0('item',x)) %in% colnames(df))
- resp <- df[,sapply(seq(1,nbitems),function(x) paste0('item',x))]
- if (method=='MML') {
- tam1 <- tam.mml(resp=resp,Y=df[,treatment],irtmodel = irtmodel,est.variance = T,verbose=F)
- }
- if (method=='JML') {
- tam1 <- tam.jml(resp=resp,group=1+df[,treatment])
- }
- if (method!='MML' & method!='JML') {
- stop('Invalid method. Please choose among MML or JML')
- }
- return(tam1)
-}
-
-dff <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N100/scenario_5A_100.csv')
-dfff <- dff[dff$replication==1,]
-facets <- dfff$TT
-dfff$item4_noTT <- NA
-dfff$item4_TT <- NA
-dfff[dfff$TT==0,]$item4_noTT <- dfff[dfff$TT==0,"item4"]
-dfff[dfff$TT==1,]$item4_TT <- dfff[dfff$TT==1,"item4"]
-
-mml.mod <- tam.mml(resp=dfff[,c('item1','item2',"item3","item4_noTT",'item4_TT')],Y=dfff$TT,constraint='cases'
- ,irtmodel = "PCM2",est.variance = T,verbose=F)
diff --git a/RProject/Scripts/mdc.R b/RProject/Scripts/mdc.R
deleted file mode 100644
index 4d8e0e5..0000000
--- a/RProject/Scripts/mdc.R
+++ /dev/null
@@ -1,89 +0,0 @@
-##############################################################################
-#----------------------------------------------------------------------------#
-############################# DATA TRANSFORMATION ############################
-#----------------------------------------------------------------------------#
-##############################################################################
-
-# Import ROSALI and RESALI
-
-ros_mdc <- read_excel("/home/corentin/Documents/These/Recherche/Simulations/Analysis/ROSALI-DIF/N300/6A_300_original.xls")
-res_mdc <- read_excel("/home/corentin/Documents/These/Recherche/Simulations/Analysis/RESALI/Results/N300/6A_300_original.xls")
-
-
-# Perform MH
-
-library(difR)
-
-dat_mh <- read.csv('/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N300/scenario_6A_300.csv')[,c("item1","item2","item3","item4",'replication',"TT")]
-
-det_mh <- c()
-for (k in 1:1000) {
- if (k%%1000==0) {
- cat(paste0(k,'/1000\n'))
- }
- dat_mh_temp <- dat_mh[dat_mh$replication==k,c("item1",'item2',"item3","item4",'TT')]
- aa <- difMH(Data=dat_mh_temp,group = "TT",focal.name = 0,exact=F)
- det_mh <- c(det_mh,1:4 %in% aa$DIFitems)
-}
-
-# Create 1 line per item per replication in df
-library(tidyr)
-
-da <- as.data.frame(sapply(1:4, function(k) sapply(1:1000,function(x) k%in%ros_mdc[x,paste0("dif_detect_",1:4)])))
-db <- as.data.frame(sapply(1:4, function(k) sapply(1:1000,function(x) k%in%res_mdc[x,paste0("dif_detect_",1:4)])))
-dc <- as.data.frame(sapply(1:4, function(k) sapply(1:1000,function(x) k%in%res_mdc[x,paste0("real_dif_",1)])))
-
-data_mdca <- data.frame(rosali=da)
-data_mdca <- pivot_longer(data_mdca,cols=1:4)
-data_mdcb <- data.frame(resali=db)
-data_mdcb <- pivot_longer(data_mdcb,cols=1:4)
-data_mdcc <- data.frame(real=dc)
-data_mdcc <- pivot_longer(data_mdcc,cols=1:4)
-
-data_mdc <- cbind(data_mdca,data_mdcb,data_mdcc)[,c(2,4,6)]
-colnames(data_mdc) <- c("rosali","resali","real")
-
-make_repl <- function(kk) {
- b <- c()
- for (k in kk) {
- a <- rep(k,4)
- b <- c(b,a)
- }
- return(b)
-}
-
-data_mdc$mh <- det_mh
-
-data_mdc$replication <- make_repl(1:1000)
-
-
-##############################################################################
-#----------------------------------------------------------------------------#
-########################### FIT DIF DETECTION MODEL ##########################
-#----------------------------------------------------------------------------#
-##############################################################################
-
-# Fit TAN model
-
-
-
-# Fit logistic model, stratified on replication
-
-mod_glm <- glm(formula = real~rosali+resali,data = data_mdc[1:2000,],family = binomial())
-data_valid <- data_mdc[2000:4000,]
-data_valid$predict <- predict(mod_glm,newdata = data_valid)
-roc_c <- pROC::roc(response=data_valid$real,predictor=data_valid$predict)
-
-data_mdc$logit_pred <- predict(mod_glm,newdata = data_mdc)>=-0.6275167
-
-perf_moreflex <- c()
-for (k in 1:1000) {
- dattt <- data_mdc[4*(k-1)+1:4,]
- perf_moreflex <- c(perf_moreflex,all(rownames(dattt[dattt$real==TRUE,])%in%rownames(dattt[dattt$logit_pred==TRUE,])))
-}
-
-##############################################################################
-#----------------------------------------------------------------------------#
-######################## FIT UNIFORMITY DETECTION MODEL ######################
-#----------------------------------------------------------------------------#
-##############################################################################
\ No newline at end of file
diff --git a/RProject/Scripts/functions/desc_analysis_dif.R b/RProject/Scripts/misc/desc_analysis_dif.R
similarity index 100%
rename from RProject/Scripts/functions/desc_analysis_dif.R
rename to RProject/Scripts/misc/desc_analysis_dif.R
diff --git a/RProject/Scripts/functions/desc_analysis_nodif.R b/RProject/Scripts/misc/desc_analysis_nodif.R
similarity index 100%
rename from RProject/Scripts/functions/desc_analysis_nodif.R
rename to RProject/Scripts/misc/desc_analysis_nodif.R
diff --git a/RProject/Scripts/functions/power_analysis.R b/RProject/Scripts/misc/power_analysis.R
similarity index 100%
rename from RProject/Scripts/functions/power_analysis.R
rename to RProject/Scripts/misc/power_analysis.R
diff --git a/Scripts/Analysis/DIF-RESIDUS/pcm_dif_residus.do b/Scripts/Analysis/DIF-RESIDUALS/pcm_dif_residus.do
similarity index 100%
rename from Scripts/Analysis/DIF-RESIDUS/pcm_dif_residus.do
rename to Scripts/Analysis/DIF-RESIDUALS/pcm_dif_residus.do
diff --git a/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S1.do b/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S1.do
deleted file mode 100644
index 564b235..0000000
--- a/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S1.do
+++ /dev/null
@@ -1,364 +0,0 @@
-*=================================================================================================================================================
-* Date : 2024-01-23
-* Stata version : Stata 18 SE
-*
-* This program analyses simulated data accounting for DIF through a partial credit model
-*
-* ado-files needed : - pcm, rosali (version 5.5 October 25, 2023, available on gitea)
-*
-*
-*================================================================================================================================================
-adopath+"/home/corentin/Documents/These/Recherche/ROSALI-SIM/Modules/rosali_custom"
-
-
-local N = "50 100 200 300"
- local ss = "1"
- foreach s in `ss' {
- foreach Nnn in `N' {
- local Nn = `Nnn'
- local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N`Nn'"
- if (`s'<=4) {
- local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N`Nn'"
- }
- local path_res = "/home/corentin/Documents/These/Recherche/Simulations/Analysis/ROSALI-DIF/N`Nn'"
- local scenarios = "A B C D E F G"
- foreach scen in `scenarios' {
- clear
- import delim "`path_data'/scenario_`s'`scen'_`Nn'.csv", encoding(ISO-8859-2) case(preserve) clear
- rename TT tt
-
- if (`s'<=2) {
- local nbitems=4
- }
- else if (`s'<=4) {
- local nbitems=7
- }
- else if (`s'<=12) {
- local nbitems=4
- }
- else {
- local nbitems=7
- }
-
-if (mod(`s',2)==0) {
- local nbmoda=3
-}
-else {
- local nbmoda=1
-}
-
- if (`s'<=4) {
- local nbdif=0
- }
- else if (`s'<=8) {
- local nbdif=1
- }
- else if (`s'<=16) {
- local nbdif=2
- }
- else {
- local nbdif=3
- }
- * taillemat = Maximum J*M cases pour les items par et J*M cases pour les dif par + J cases pour les DIF detect + nbdif cases pour dif réel
- local taillemat=2*`nbitems'*`nbmoda'+`nbitems'+`nbdif'+2
- local colna=""
- forvalues i=1/`nbitems' {
- forvalues z=1/`nbmoda' {
- local colna = "`colna'"+"item`i'_`z' "
- local colna = "`colna'"+"dif_`i'_`z' "
- }
- }
- forvalues i=1/`nbitems' {
- local colna = "`colna'"+"dif_detect_`i' "
- }
-
- forvalues i=1/`nbdif' {
- local colna = "`colna'"+"real_dif_`i' "
- }
-local colna = "`colna'" + "beta " + "se_beta"
-
-
- mat outmat = J(1000,`taillemat',.)
- mat colnames outmat= `colna'
- di "Scenario `s'`scen' / N=`Nnn'"
- forvalues k=1/1000 {
- if (mod(`k',100)==0) {
- di "`k'/1000"
- }
- preserve
- qui keep if replication==`k'
-
-
- * MERGE des modalités si non représentées
-
- if (`nbmoda'>1 & `Nn'==50) {
- local com_z = 0
- qui gen comz = 0
- forvalues j = 1 / `nbitems' {
- local recoda_`j' = 0
- qui tab item`j' if tt == 0, matrow(rect1_g0_`j') matcell(nbrt1_g0_`j')
- local maxm`j'_t1_g0 = rect1_g0_`j'[r(r),1]
- local minm`j'_t1_g0 = rect1_g0_`j'[1,1]
-
- qui tab item`j' if tt == 1, matrow(rect1_g1_`j') matcell(nbrt1_g1_`j')
- local minm`j'_t1_g1 = rect1_g1_`j'[1,1]
- local maxm`j'_t1_g1 = rect1_g1_`j'[r(r),1]
-
- local minm_`j' = min(`minm`j'_t1_g0',`minm`j'_t1_g1')
- local maxm_`j' = max(`maxm`j'_t1_g0',`maxm`j'_t1_g1')
- local nbm_`j' = `=`maxm_`j''-`minm_`j'''
-
- if `minm_`j'' != 0 & `com_z' == 0 {
- local com_z = 1
- }
-
- qui count if item`j' == 3 & tt == 0
- local mod3plac = r(N)
- qui count if item`j' == 3 & tt == 1
- local mod3tt = r(N)
- local nb_rn3 = min(`mod3plac',`mod3tt')
- if `nb_rn3'==0 {
- qui replace comz = 1
- }
-
- forvalues m = 0/`=`nbm_`j''-1' {
- qui count if item`j' == `m' & tt == 0
- local nb_rn1_g0 = r(N)
- qui count if item`j' == `m' & tt == 1
- local nb_rn1_g1 = r(N)
- local nb_rn = min(`nb_rn1_g0',`nb_rn1_g1')
- if `nb_rn' == 0 {
- qui replace comz = 1
- local recoda_`j' = 1
- if `m' == 0 | `m' < `minm`j'_t1_g0' | `m' < `minm`j'_t1_g1' {
- local stop = 1
- forvalues kk = 1/`=`nbm_`j''-`m'' {
- qui count if item`j' == `=`m' + `kk'' & tt == 0
- local v`kk'1_0 = r(N)
- qui count if item`j' == `=`m' + `kk'' & tt == 1
- local v`kk'1_1 = r(N)
- if (`v`kk'1_0' != 0 | `v`kk'1_1' != 0) & `stop' != 0 {
- qui replace item`j'= `=`m'+`kk'' if item`j'==`m'
- local zzz=`j'+`nbitems'
- *qui replace item`zzz'=`=`m'+`kk'' if item``=`j'+`nbitems'''==`m'
- *di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
- local stop = 0
- }
- }
- }
- else if `m' == `=`nbm_`j''-1' | `m' >= `maxm`j'_t1_g1' {
- local stop = 1
- forvalues kk = 1/`=`m'' {
- qui count if item`j' == `=`m' - `kk'' & tt == 0
- local v`kk'1_0 = r(N)
- qui count if item`j' == `=`m' - `kk'' & tt == 1
- local v`kk'1_1 = r(N)
- if (`v`kk'1_0' != 0 | `v`kk'1_1' != 0) & `stop' != 0 {
- qui replace item`j'= `=`m' - `kk'' if item`j'==`m'
- local zzz=`j'+`nbitems'
- *qui replace item`zzz'= `=`m' - `kk'' if item`zzz'==`m'
- *di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
- local stop = 0
- }
- }
- }
- else {
- if runiform()>0.5{
- local stop = 1
- forvalues kk = 1/`m' {
- qui count if item`j' == `=`m' - `kk'' & tt == 0
- local v`kk'1_0 = r(N)
- qui count if item`j' == `=`m' - `kk'' & tt == 1
- local v`kk'1_1 = r(N)
- if (`v`kk'1_0' != 0 | `v`kk'1_1' != 0) & `stop' != 0 {
- qui replace item`j'= `=`m'-`kk'' if item`j'==`m'
- local zzz=`j'+`nbitems'
- *qui replace item`zzz'=`=`m'-`kk'' if item``=`j'+`nbitems'''==`m'
- *di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
- local stop = 0
- }
- }
- }
- else {
- local stop = 1
- forvalues kk = 1/`=`nbm_`j''-`m'' {
- qui count if item`j' == `=`m' + `kk'' & tt == 0
- local v`kk'1_0 = r(N)
- qui count if item`j' == `=`m' + `kk'' & tt == 1
- local v`kk'1_1 = r(N)
- if (`v`kk'1_0' != 0 | `v`kk'1_1' != 0) & `stop' != 0{
- qui replace item`j'=`=`m' + `kk'' if item`j'==`m'
- local zzz=`j'+`nbitems'
- *qui replace item`zzz'=`=`m' + `kk'' if item``=`j'+`nbitems'''==`m'
- *di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
- local stop = 0
- }
- else {
- if `stop' != 0 {
- qui replace item`j'= `nbm_`j'' if item`j'==`m'
- local zzz=`j'+`nbitems'
- *qui replace item`zzz'= `nbm_`j'' if item``=`j'+`nbitems'''==`m'
- *di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
- local stop = 0
- }
- }
- }
- }
- }
- }
- }
- qui levelsof item`j'
- local val = r(levels)
- local checker: word 1 of `val'
- local checker2: word 2 of `val'
- local checker3: word 3 of `val'
- local nummoda=r(r)
- local nbmoda_`j'=`nummoda'
- if (`nummoda'==2) {
- qui recode item`j' (`checker'=0) (`checker2'=1)
- }
- if (`nummoda'==3) {
- if (`checker'!=0) {
- qui recode item`j' (`checker'=0) (`checker2'=1) (`checker3'=2)
- }
- else if (`checker2'!=1) {
- qui recode item`j' (`checker2'=1) (`checker3'=2)
- }
- else if (`checker3'!=2) {
- qui recode item`j' (`checker3'=2)
- }
- }
- }
-
- qui valuesof comz
- local val = r(values)
- local checker: word 1 of `val'
- }
- else {
- forvalues jj=1/`nbitems' {
- local nbmoda_`jj'=`nbmoda'
- }
- }
-
-
- * ROSALI
- qui rosali_original item1-item`nbitems' item1-item`nbitems', group(tt)
- qui mat resmat=r(difitems)
- local nbitems2 = 2*`nbitems'
-
- * Calculer le nbre d'items détectés
- local nbdetect = 0
- local stop = 0
- forvalues jj=1/`nbitems' {
- if (`stop'==0) {
- mat testm=J(1,1,.)
- if (resmat[1,`jj']==testm[1,1]) {
- local stop = 1
- local nbdetect = `jj'-1
- }
- }
- }
-
- * Stocker les items détectés +
- * Définition des contraintes
- local csrt=0
- mat testm=J(1,1,0)
- forvalues u=1/`nbdetect' {
- local difitems`u'=resmat[1,`u']
- local i=`difitems`u''
- if (`nbmoda_`i''==3 & resmat[1,`nbitems'+`i']!=testm[1,1]){
- local constrnt`u' = "constraint `u' 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))"
- qui `constrnt`u''
- local v=`u'+100
- local constrnt`u'_2 = "constraint `v' 3*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([3.item`i']_cons-([3.item`i']_cons+[3.item`i'] tt))"
- qui `constrnt`u'_2'
- }
- if (`nbmoda_`i''==2 & resmat[1,`nbitems'+`i']!=testm[1,1]){
- local constrnt`u' = "constraint `u' 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))"
- qui `constrnt`u''
- }
- }
-
- * Définition du modèle
- local mod "gsem "
- local conformula = ""
- forvalues i=1/`nbitems' {
- local mod = "`mod'"+"(1.item`i'<-THETA@1)"
- if (`nbmoda_`i''==3) {
- local mod = "`mod'"+"(2.item`i'<-THETA@2)(3.item`i'<-THETA@3)"
- }
- else if (`nbmoda_`i''==2) {
- local mod = "`mod'"+"(2.item`i'<-THETA@2)"
- }
- }
- forvalues u=1/`nbdetect' {
- local v=`difitems`u''
- local mod = "`mod'"+"(1.item`v'<-THETA@1 tt)"
- if (`nbmoda_`v''==3) {
- local mod = "`mod'"+"(2.item`v'<-THETA@2 tt)(3.item`v'<-THETA@3 tt)"
- }
- else if (`nbmoda_`v''==2) {
- local mod = "`mod'"+"(2.item`v'<-THETA@2 tt)"
- }
- local w= 100+`u'
- if (resmat[1,`nbitems'+`v']!=testm[1,1] & `nbmoda_`v''==3) {
- local conformula = "`conformula'" + "`u' " + "`w' "
- }
- else if (resmat[1,`nbitems'+`v']!=testm[1,1] & `nbmoda_`v''==2) {
- local conformula = "`conformula'" + "`u' "
- }
- }
- if ("`conformula'" != "") {
- local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent constraint(`conformula')"
- }
- else {
- local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent"
- }
- *calcul du modèle
- qui `mod'
- mat V=r(table)
- mat W=V[1..2,1...]
-
- * compilation
- forvalues j=1/`nbitems' {
- forvalues z=1/`nbmoda_`j'' {
- mat outmat[`k',colnumb(outmat,"item`j'_`z'")] = W[1,colnumb(W,"`z'.item`j':_cons")]
- }
- }
- * compilation DIF
- forvalues u=1/`nbdetect' {
- local j=`difitems`u''
- forvalues z=1/`nbmoda_`j'' {
- mat outmat[`k',colnumb(outmat,"dif_`u'_`z'")] = W[1,colnumb(W,"`z'.item`j':tt")]
- mat outmat[`k',colnumb(outmat,"dif_detect_`u'")] = `j'
- }
- }
-
- * Stocker les items de DIF originaux
- if (`nbdif' > 0) {
- qui levelsof dif1
- local ldif1 = r(levels)
- local diff1: word 1 of `ldif1'
- qui mat outmat[`k',colnumb(outmat,"real_dif_1")]=`diff1'
- if (`nbdif' > 1) {
- qui levelsof dif2
- local ldif2 = r(levels)
- local diff2: word 1 of `ldif2'
- qui mat outmat[`k',colnumb(outmat,"real_dif_2")]=`diff2'
- if (`nbdif' > 2) {
- qui levelsof dif3
- local ldif3 = r(levels)
- local diff3: word 1 of `ldif3'
- qui mat outmat[`k',colnumb(outmat,"real_dif_3")]=`diff3'
- }
- }
- }
- qui mat outmat[`k',colnumb(outmat,"beta")]=W[1,colnumb(W,"THETA:tt")]
- qui mat outmat[`k',colnumb(outmat,"se_beta")]=W[2,colnumb(W,"THETA:tt")]
- restore
- }
- putexcel set "`path_res'/`s'`scen'_`Nn'_original.xls", sheet("outmat") replace
- putexcel A1=matrix(outmat), colnames
-}
-}
-}
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
deleted file mode 100644
index 17deac6..0000000
--- a/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S10.do
+++ /dev/null
@@ -1,378 +0,0 @@
-*=================================================================================================================================================
-* Date : 2024-01-23
-* Stata version : Stata 18 SE
-*
-* This program analyses simulated data accounting for DIF through a partial credit model
-*
-* ado-files needed : - pcm, rosali (version 5.5 October 25, 2023, available on gitea)
-*
-*
-*================================================================================================================================================
-adopath+"/home/corentin/Documents/These/Recherche/ROSALI-SIM/Modules/rosali_custom"
-
-
-local N = "50 100 200 300"
- local ss = "10"
- foreach s in `ss' {
- foreach Nnn in `N' {
- local Nn = `Nnn'
- local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N`Nn'"
- if (`s'<=4) {
- local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N`Nn'"
- }
- local path_res = "/home/corentin/Documents/These/Recherche/Simulations/Analysis/ROSALI-DIF/N`Nn'"
- local scenarios = "A B C D E F G"
- foreach scen in `scenarios' {
- clear
- import delim "`path_data'/scenario_`s'`scen'_`Nn'.csv", encoding(ISO-8859-2) case(preserve) clear
- rename TT tt
-
- if (`s'<=2) {
- local nbitems=4
- }
- else if (`s'<=4) {
- local nbitems=7
- }
- else if (`s'<=12) {
- local nbitems=4
- }
- else {
- local nbitems=7
- }
-
- if (mod(`s',2)==0) {
- local nbmoda=3
- }
- else {
- local nbmoda=1
- }
-
- if (`s'<=4) {
- local nbdif=0
- }
- else if (`s'<=8) {
- local nbdif=1
- }
- else if (`s'<=16) {
- local nbdif=2
- }
- else {
- local nbdif=3
- }
- * taillemat = Maximum J*M cases pour les items par et J*M cases pour les dif par + J cases pour les DIF detect + nbdif cases pour dif réel
- local taillemat=2*`nbitems'*`nbmoda'+`nbitems'+`nbdif'+2
- 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'
- }
- }
-
-
- * ROSALI
- qui rosali_original item1-item`nbitems' item1-item`nbitems', group(tt)
- qui mat resmat=r(difitems)
- local nbitems2 = 2*`nbitems'
-
- * Calculer le nbre d'items détectés
- local nbdetect = 0
- local stop = 0
- forvalues jj=1/`nbitems' {
- if (`stop'==0) {
- mat testm=J(1,1,.)
- if (resmat[1,`jj']==testm[1,1]) {
- local stop = 1
- local nbdetect = `jj'-1
- }
- }
- }
-
- * Stocker les items détectés +
- * Définition des contraintes
- local csrt=0
- mat testm=J(1,1,0)
- forvalues u=1/`nbdetect' {
- local difitems`u'=resmat[1,`u']
- local i=`difitems`u''
- if (`nbmoda_`i''==3 & resmat[1,`nbitems'+`i']!=testm[1,1]){
- local constrnt`u' = "constraint `u' 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))"
- qui `constrnt`u''
- local v=`u'+100
- local constrnt`u'_2 = "constraint `v' 3*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([3.item`i']_cons-([3.item`i']_cons+[3.item`i'] tt))"
- qui `constrnt`u'_2'
- }
- if (`nbmoda_`i''==2 & resmat[1,`nbitems'+`i']!=testm[1,1]){
- local constrnt`u' = "constraint `u' 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))"
- qui `constrnt`u''
- }
- }
-
- * Définition du modèle
- local mod "gsem "
- local conformula = ""
- forvalues i=1/`nbitems' {
- local mod = "`mod'"+"(1.item`i'<-THETA@1)"
- if (`nbmoda_`i''==3) {
- local mod = "`mod'"+"(2.item`i'<-THETA@2)(3.item`i'<-THETA@3)"
- }
- else if (`nbmoda_`i''==2) {
- local mod = "`mod'"+"(2.item`i'<-THETA@2)"
- }
- }
- forvalues u=1/`nbdetect' {
- local v=`difitems`u''
- local mod = "`mod'"+"(1.item`v'<-THETA@1 tt)"
- if (`nbmoda_`v''==3) {
- local mod = "`mod'"+"(2.item`v'<-THETA@2 tt)(3.item`v'<-THETA@3 tt)"
- }
- else if (`nbmoda_`v''==2) {
- local mod = "`mod'"+"(2.item`v'<-THETA@2 tt)"
- }
- local w= 100+`u'
- 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'
- 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
- }
- }
- }
diff --git a/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S11.do b/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S11.do
deleted file mode 100644
index d20bc42..0000000
--- a/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S11.do
+++ /dev/null
@@ -1,364 +0,0 @@
-*=================================================================================================================================================
-* Date : 2024-01-23
-* Stata version : Stata 18 SE
-*
-* This program analyses simulated data accounting for DIF through a partial credit model
-*
-* ado-files needed : - pcm, rosali (version 5.5 October 25, 2023, available on gitea)
-*
-*
-*================================================================================================================================================
-adopath+"/home/corentin/Documents/These/Recherche/ROSALI-SIM/Modules/rosali_custom"
-
-
-local N = "50 100 200 300"
- local ss = "11"
- foreach s in `ss' {
- foreach Nnn in `N' {
- local Nn = `Nnn'
- local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N`Nn'"
- if (`s'<=4) {
- local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N`Nn'"
- }
- local path_res = "/home/corentin/Documents/These/Recherche/Simulations/Analysis/ROSALI-DIF/N`Nn'"
- local scenarios = "A B C D E F G"
- foreach scen in `scenarios' {
- clear
- import delim "`path_data'/scenario_`s'`scen'_`Nn'.csv", encoding(ISO-8859-2) case(preserve) clear
- rename TT tt
-
- if (`s'<=2) {
- local nbitems=4
- }
- else if (`s'<=4) {
- local nbitems=7
- }
- else if (`s'<=12) {
- local nbitems=4
- }
- else {
- local nbitems=7
- }
-
-if (mod(`s',2)==0) {
- local nbmoda=3
-}
-else {
- local nbmoda=1
-}
-
- if (`s'<=4) {
- local nbdif=0
- }
- else if (`s'<=8) {
- local nbdif=1
- }
- else if (`s'<=16) {
- local nbdif=2
- }
- else {
- local nbdif=3
- }
- * taillemat = Maximum J*M cases pour les items par et J*M cases pour les dif par + J cases pour les DIF detect + nbdif cases pour dif réel
- local taillemat=2*`nbitems'*`nbmoda'+`nbitems'+`nbdif'+2
- local colna=""
- forvalues i=1/`nbitems' {
- forvalues z=1/`nbmoda' {
- local colna = "`colna'"+"item`i'_`z' "
- local colna = "`colna'"+"dif_`i'_`z' "
- }
- }
- forvalues i=1/`nbitems' {
- local colna = "`colna'"+"dif_detect_`i' "
- }
-
- forvalues i=1/`nbdif' {
- local colna = "`colna'"+"real_dif_`i' "
- }
-local colna = "`colna'" + "beta " + "se_beta"
-
-
- mat outmat = J(1000,`taillemat',.)
- mat colnames outmat= `colna'
- di "Scenario `s'`scen' / N=`Nnn'"
- forvalues k=1/1000 {
- if (mod(`k',100)==0) {
- di "`k'/1000"
- }
- preserve
- qui keep if replication==`k'
-
-
- * MERGE des modalités si non représentées
-
- if (`nbmoda'>1 & `Nn'==50) {
- local com_z = 0
- qui gen comz = 0
- forvalues j = 1 / `nbitems' {
- local recoda_`j' = 0
- qui tab item`j' if tt == 0, matrow(rect1_g0_`j') matcell(nbrt1_g0_`j')
- local maxm`j'_t1_g0 = rect1_g0_`j'[r(r),1]
- local minm`j'_t1_g0 = rect1_g0_`j'[1,1]
-
- qui tab item`j' if tt == 1, matrow(rect1_g1_`j') matcell(nbrt1_g1_`j')
- local minm`j'_t1_g1 = rect1_g1_`j'[1,1]
- local maxm`j'_t1_g1 = rect1_g1_`j'[r(r),1]
-
- local minm_`j' = min(`minm`j'_t1_g0',`minm`j'_t1_g1')
- local maxm_`j' = max(`maxm`j'_t1_g0',`maxm`j'_t1_g1')
- local nbm_`j' = `=`maxm_`j''-`minm_`j'''
-
- if `minm_`j'' != 0 & `com_z' == 0 {
- local com_z = 1
- }
-
- qui count if item`j' == 3 & tt == 0
- local mod3plac = r(N)
- qui count if item`j' == 3 & tt == 1
- local mod3tt = r(N)
- local nb_rn3 = min(`mod3plac',`mod3tt')
- if `nb_rn3'==0 {
- qui replace comz = 1
- }
-
- forvalues m = 0/`=`nbm_`j''-1' {
- qui count if item`j' == `m' & tt == 0
- local nb_rn1_g0 = r(N)
- qui count if item`j' == `m' & tt == 1
- local nb_rn1_g1 = r(N)
- local nb_rn = min(`nb_rn1_g0',`nb_rn1_g1')
- if `nb_rn' == 0 {
- qui replace comz = 1
- local recoda_`j' = 1
- if `m' == 0 | `m' < `minm`j'_t1_g0' | `m' < `minm`j'_t1_g1' {
- local stop = 1
- forvalues kk = 1/`=`nbm_`j''-`m'' {
- qui count if item`j' == `=`m' + `kk'' & tt == 0
- local v`kk'1_0 = r(N)
- qui count if item`j' == `=`m' + `kk'' & tt == 1
- local v`kk'1_1 = r(N)
- if (`v`kk'1_0' != 0 | `v`kk'1_1' != 0) & `stop' != 0 {
- qui replace item`j'= `=`m'+`kk'' if item`j'==`m'
- local zzz=`j'+`nbitems'
- *qui replace item`zzz'=`=`m'+`kk'' if item``=`j'+`nbitems'''==`m'
- *di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
- local stop = 0
- }
- }
- }
- else if `m' == `=`nbm_`j''-1' | `m' >= `maxm`j'_t1_g1' {
- local stop = 1
- forvalues kk = 1/`=`m'' {
- qui count if item`j' == `=`m' - `kk'' & tt == 0
- local v`kk'1_0 = r(N)
- qui count if item`j' == `=`m' - `kk'' & tt == 1
- local v`kk'1_1 = r(N)
- if (`v`kk'1_0' != 0 | `v`kk'1_1' != 0) & `stop' != 0 {
- qui replace item`j'= `=`m' - `kk'' if item`j'==`m'
- local zzz=`j'+`nbitems'
- *qui replace item`zzz'= `=`m' - `kk'' if item`zzz'==`m'
- *di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
- local stop = 0
- }
- }
- }
- else {
- if runiform()>0.5{
- local stop = 1
- forvalues kk = 1/`m' {
- qui count if item`j' == `=`m' - `kk'' & tt == 0
- local v`kk'1_0 = r(N)
- qui count if item`j' == `=`m' - `kk'' & tt == 1
- local v`kk'1_1 = r(N)
- if (`v`kk'1_0' != 0 | `v`kk'1_1' != 0) & `stop' != 0 {
- qui replace item`j'= `=`m'-`kk'' if item`j'==`m'
- local zzz=`j'+`nbitems'
- *qui replace item`zzz'=`=`m'-`kk'' if item``=`j'+`nbitems'''==`m'
- *di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
- local stop = 0
- }
- }
- }
- else {
- local stop = 1
- forvalues kk = 1/`=`nbm_`j''-`m'' {
- qui count if item`j' == `=`m' + `kk'' & tt == 0
- local v`kk'1_0 = r(N)
- qui count if item`j' == `=`m' + `kk'' & tt == 1
- local v`kk'1_1 = r(N)
- if (`v`kk'1_0' != 0 | `v`kk'1_1' != 0) & `stop' != 0{
- qui replace item`j'=`=`m' + `kk'' if item`j'==`m'
- local zzz=`j'+`nbitems'
- *qui replace item`zzz'=`=`m' + `kk'' if item``=`j'+`nbitems'''==`m'
- *di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
- local stop = 0
- }
- else {
- if `stop' != 0 {
- qui replace item`j'= `nbm_`j'' if item`j'==`m'
- local zzz=`j'+`nbitems'
- *qui replace item`zzz'= `nbm_`j'' if item``=`j'+`nbitems'''==`m'
- *di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
- local stop = 0
- }
- }
- }
- }
- }
- }
- }
- qui levelsof item`j'
- local val = r(levels)
- local checker: word 1 of `val'
- local checker2: word 2 of `val'
- local checker3: word 3 of `val'
- local nummoda=r(r)
- local nbmoda_`j'=`nummoda'
- if (`nummoda'==2) {
- qui recode item`j' (`checker'=0) (`checker2'=1)
- }
- if (`nummoda'==3) {
- if (`checker'!=0) {
- qui recode item`j' (`checker'=0) (`checker2'=1) (`checker3'=2)
- }
- else if (`checker2'!=1) {
- qui recode item`j' (`checker2'=1) (`checker3'=2)
- }
- else if (`checker3'!=2) {
- qui recode item`j' (`checker3'=2)
- }
- }
- }
-
- qui valuesof comz
- local val = r(values)
- local checker: word 1 of `val'
- }
- else {
- forvalues jj=1/`nbitems' {
- local nbmoda_`jj'=`nbmoda'
- }
- }
-
-
- * ROSALI
- qui rosali_original item1-item`nbitems' item1-item`nbitems', group(tt)
- qui mat resmat=r(difitems)
- local nbitems2 = 2*`nbitems'
-
- * Calculer le nbre d'items détectés
- local nbdetect = 0
- local stop = 0
- forvalues jj=1/`nbitems' {
- if (`stop'==0) {
- mat testm=J(1,1,.)
- if (resmat[1,`jj']==testm[1,1]) {
- local stop = 1
- local nbdetect = `jj'-1
- }
- }
- }
-
- * Stocker les items détectés +
- * Définition des contraintes
- local csrt=0
- mat testm=J(1,1,0)
- forvalues u=1/`nbdetect' {
- local difitems`u'=resmat[1,`u']
- local i=`difitems`u''
- if (`nbmoda_`i''==3 & resmat[1,`nbitems'+`i']!=testm[1,1]){
- local constrnt`u' = "constraint `u' 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))"
- qui `constrnt`u''
- local v=`u'+100
- local constrnt`u'_2 = "constraint `v' 3*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([3.item`i']_cons-([3.item`i']_cons+[3.item`i'] tt))"
- qui `constrnt`u'_2'
- }
- if (`nbmoda_`i''==2 & resmat[1,`nbitems'+`i']!=testm[1,1]){
- local constrnt`u' = "constraint `u' 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))"
- qui `constrnt`u''
- }
- }
-
- * Définition du modèle
- local mod "gsem "
- local conformula = ""
- forvalues i=1/`nbitems' {
- local mod = "`mod'"+"(1.item`i'<-THETA@1)"
- if (`nbmoda_`i''==3) {
- local mod = "`mod'"+"(2.item`i'<-THETA@2)(3.item`i'<-THETA@3)"
- }
- else if (`nbmoda_`i''==2) {
- local mod = "`mod'"+"(2.item`i'<-THETA@2)"
- }
- }
- forvalues u=1/`nbdetect' {
- local v=`difitems`u''
- local mod = "`mod'"+"(1.item`v'<-THETA@1 tt)"
- if (`nbmoda_`v''==3) {
- local mod = "`mod'"+"(2.item`v'<-THETA@2 tt)(3.item`v'<-THETA@3 tt)"
- }
- else if (`nbmoda_`v''==2) {
- local mod = "`mod'"+"(2.item`v'<-THETA@2 tt)"
- }
- local w= 100+`u'
- if (resmat[1,`nbitems'+`v']!=testm[1,1] & `nbmoda_`v''==3) {
- local conformula = "`conformula'" + "`u' " + "`w' "
- }
- else if (resmat[1,`nbitems'+`v']!=testm[1,1] & `nbmoda_`v''==2) {
- local conformula = "`conformula'" + "`u' "
- }
- }
- if ("`conformula'" != "") {
- local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent constraint(`conformula')"
- }
- else {
- local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent"
- }
- *calcul du modèle
- qui `mod'
- mat V=r(table)
- mat W=V[1..2,1...]
-
- * compilation
- forvalues j=1/`nbitems' {
- forvalues z=1/`nbmoda_`j'' {
- mat outmat[`k',colnumb(outmat,"item`j'_`z'")] = W[1,colnumb(W,"`z'.item`j':_cons")]
- }
- }
- * compilation DIF
- forvalues u=1/`nbdetect' {
- local j=`difitems`u''
- forvalues z=1/`nbmoda_`j'' {
- mat outmat[`k',colnumb(outmat,"dif_`u'_`z'")] = W[1,colnumb(W,"`z'.item`j':tt")]
- mat outmat[`k',colnumb(outmat,"dif_detect_`u'")] = `j'
- }
- }
-
- * Stocker les items de DIF originaux
- if (`nbdif' > 0) {
- qui levelsof dif1
- local ldif1 = r(levels)
- local diff1: word 1 of `ldif1'
- qui mat outmat[`k',colnumb(outmat,"real_dif_1")]=`diff1'
- if (`nbdif' > 1) {
- qui levelsof dif2
- local ldif2 = r(levels)
- local diff2: word 1 of `ldif2'
- qui mat outmat[`k',colnumb(outmat,"real_dif_2")]=`diff2'
- if (`nbdif' > 2) {
- qui levelsof dif3
- local ldif3 = r(levels)
- local diff3: word 1 of `ldif3'
- qui mat outmat[`k',colnumb(outmat,"real_dif_3")]=`diff3'
- }
- }
- }
- qui mat outmat[`k',colnumb(outmat,"beta")]=W[1,colnumb(W,"THETA:tt")]
- qui mat outmat[`k',colnumb(outmat,"se_beta")]=W[2,colnumb(W,"THETA:tt")]
- restore
- }
- putexcel set "`path_res'/`s'`scen'_`Nn'_original.xls", sheet("outmat") replace
- putexcel A1=matrix(outmat), colnames
-}
-}
-}
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
deleted file mode 100644
index 8e7e251..0000000
--- a/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S12.do
+++ /dev/null
@@ -1,378 +0,0 @@
-*=================================================================================================================================================
-* Date : 2024-01-23
-* Stata version : Stata 18 SE
-*
-* This program analyses simulated data accounting for DIF through a partial credit model
-*
-* ado-files needed : - pcm, rosali (version 5.5 October 25, 2023, available on gitea)
-*
-*
-*================================================================================================================================================
-adopath+"/home/corentin/Documents/These/Recherche/ROSALI-SIM/Modules/rosali_custom"
-
-
-local N = "50 100 200 300"
- local ss = "12"
- foreach s in `ss' {
- foreach Nnn in `N' {
- local Nn = `Nnn'
- local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N`Nn'"
- if (`s'<=4) {
- local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N`Nn'"
- }
- local path_res = "/home/corentin/Documents/These/Recherche/Simulations/Analysis/ROSALI-DIF/N`Nn'"
- local scenarios = "A B C D E F G"
- foreach scen in `scenarios' {
- clear
- import delim "`path_data'/scenario_`s'`scen'_`Nn'.csv", encoding(ISO-8859-2) case(preserve) clear
- rename TT tt
-
- if (`s'<=2) {
- local nbitems=4
- }
- else if (`s'<=4) {
- local nbitems=7
- }
- else if (`s'<=12) {
- local nbitems=4
- }
- else {
- local nbitems=7
- }
-
- if (mod(`s',2)==0) {
- local nbmoda=3
- }
- else {
- local nbmoda=1
- }
-
- if (`s'<=4) {
- local nbdif=0
- }
- else if (`s'<=8) {
- local nbdif=1
- }
- else if (`s'<=16) {
- local nbdif=2
- }
- else {
- local nbdif=3
- }
- * taillemat = Maximum J*M cases pour les items par et J*M cases pour les dif par + J cases pour les DIF detect + nbdif cases pour dif réel
- local taillemat=2*`nbitems'*`nbmoda'+`nbitems'+`nbdif'+2
- 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'
- }
- }
-
-
- * ROSALI
- qui rosali_original item1-item`nbitems' item1-item`nbitems', group(tt)
- qui mat resmat=r(difitems)
- local nbitems2 = 2*`nbitems'
-
- * Calculer le nbre d'items détectés
- local nbdetect = 0
- local stop = 0
- forvalues jj=1/`nbitems' {
- if (`stop'==0) {
- mat testm=J(1,1,.)
- if (resmat[1,`jj']==testm[1,1]) {
- local stop = 1
- local nbdetect = `jj'-1
- }
- }
- }
-
- * Stocker les items détectés +
- * Définition des contraintes
- local csrt=0
- mat testm=J(1,1,0)
- forvalues u=1/`nbdetect' {
- local difitems`u'=resmat[1,`u']
- local i=`difitems`u''
- if (`nbmoda_`i''==3 & resmat[1,`nbitems'+`i']!=testm[1,1]){
- local constrnt`u' = "constraint `u' 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))"
- qui `constrnt`u''
- local v=`u'+100
- local constrnt`u'_2 = "constraint `v' 3*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([3.item`i']_cons-([3.item`i']_cons+[3.item`i'] tt))"
- qui `constrnt`u'_2'
- }
- if (`nbmoda_`i''==2 & resmat[1,`nbitems'+`i']!=testm[1,1]){
- local constrnt`u' = "constraint `u' 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))"
- qui `constrnt`u''
- }
- }
-
- * Définition du modèle
- local mod "gsem "
- local conformula = ""
- forvalues i=1/`nbitems' {
- local mod = "`mod'"+"(1.item`i'<-THETA@1)"
- if (`nbmoda_`i''==3) {
- local mod = "`mod'"+"(2.item`i'<-THETA@2)(3.item`i'<-THETA@3)"
- }
- else if (`nbmoda_`i''==2) {
- local mod = "`mod'"+"(2.item`i'<-THETA@2)"
- }
- }
- forvalues u=1/`nbdetect' {
- local v=`difitems`u''
- local mod = "`mod'"+"(1.item`v'<-THETA@1 tt)"
- if (`nbmoda_`v''==3) {
- local mod = "`mod'"+"(2.item`v'<-THETA@2 tt)(3.item`v'<-THETA@3 tt)"
- }
- else if (`nbmoda_`v''==2) {
- local mod = "`mod'"+"(2.item`v'<-THETA@2 tt)"
- }
- local w= 100+`u'
- 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'
- 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
- }
- }
- }
diff --git a/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S13.do b/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S13.do
deleted file mode 100644
index ff9a7e8..0000000
--- a/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S13.do
+++ /dev/null
@@ -1,364 +0,0 @@
-*=================================================================================================================================================
-* Date : 2024-01-23
-* Stata version : Stata 18 SE
-*
-* This program analyses simulated data accounting for DIF through a partial credit model
-*
-* ado-files needed : - pcm, rosali (version 5.5 October 25, 2023, available on gitea)
-*
-*
-*================================================================================================================================================
-adopath+"/home/corentin/Documents/These/Recherche/ROSALI-SIM/Modules/rosali_custom"
-
-
-local N = "50 100 200 300"
- local ss = "13"
- foreach s in `ss' {
- foreach Nnn in `N' {
- local Nn = `Nnn'
- local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N`Nn'"
- if (`s'<=4) {
- local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N`Nn'"
- }
- local path_res = "/home/corentin/Documents/These/Recherche/Simulations/Analysis/ROSALI-DIF/N`Nn'"
- local scenarios = "A B C D E F G"
- foreach scen in `scenarios' {
- clear
- import delim "`path_data'/scenario_`s'`scen'_`Nn'.csv", encoding(ISO-8859-2) case(preserve) clear
- rename TT tt
-
- if (`s'<=2) {
- local nbitems=4
- }
- else if (`s'<=4) {
- local nbitems=7
- }
- else if (`s'<=12) {
- local nbitems=4
- }
- else {
- local nbitems=7
- }
-
-if (mod(`s',2)==0) {
- local nbmoda=3
-}
-else {
- local nbmoda=1
-}
-
- if (`s'<=4) {
- local nbdif=0
- }
- else if (`s'<=8) {
- local nbdif=1
- }
- else if (`s'<=16) {
- local nbdif=2
- }
- else {
- local nbdif=3
- }
- * taillemat = Maximum J*M cases pour les items par et J*M cases pour les dif par + J cases pour les DIF detect + nbdif cases pour dif réel
- local taillemat=2*`nbitems'*`nbmoda'+`nbitems'+`nbdif'+2
- local colna=""
- forvalues i=1/`nbitems' {
- forvalues z=1/`nbmoda' {
- local colna = "`colna'"+"item`i'_`z' "
- local colna = "`colna'"+"dif_`i'_`z' "
- }
- }
- forvalues i=1/`nbitems' {
- local colna = "`colna'"+"dif_detect_`i' "
- }
-
- forvalues i=1/`nbdif' {
- local colna = "`colna'"+"real_dif_`i' "
- }
-local colna = "`colna'" + "beta " + "se_beta"
-
-
- mat outmat = J(1000,`taillemat',.)
- mat colnames outmat= `colna'
- di "Scenario `s'`scen' / N=`Nnn'"
- forvalues k=1/1000 {
- if (mod(`k',100)==0) {
- di "`k'/1000"
- }
- preserve
- qui keep if replication==`k'
-
-
- * MERGE des modalités si non représentées
-
- if (`nbmoda'>1 & `Nn'==50) {
- local com_z = 0
- qui gen comz = 0
- forvalues j = 1 / `nbitems' {
- local recoda_`j' = 0
- qui tab item`j' if tt == 0, matrow(rect1_g0_`j') matcell(nbrt1_g0_`j')
- local maxm`j'_t1_g0 = rect1_g0_`j'[r(r),1]
- local minm`j'_t1_g0 = rect1_g0_`j'[1,1]
-
- qui tab item`j' if tt == 1, matrow(rect1_g1_`j') matcell(nbrt1_g1_`j')
- local minm`j'_t1_g1 = rect1_g1_`j'[1,1]
- local maxm`j'_t1_g1 = rect1_g1_`j'[r(r),1]
-
- local minm_`j' = min(`minm`j'_t1_g0',`minm`j'_t1_g1')
- local maxm_`j' = max(`maxm`j'_t1_g0',`maxm`j'_t1_g1')
- local nbm_`j' = `=`maxm_`j''-`minm_`j'''
-
- if `minm_`j'' != 0 & `com_z' == 0 {
- local com_z = 1
- }
-
- qui count if item`j' == 3 & tt == 0
- local mod3plac = r(N)
- qui count if item`j' == 3 & tt == 1
- local mod3tt = r(N)
- local nb_rn3 = min(`mod3plac',`mod3tt')
- if `nb_rn3'==0 {
- qui replace comz = 1
- }
-
- forvalues m = 0/`=`nbm_`j''-1' {
- qui count if item`j' == `m' & tt == 0
- local nb_rn1_g0 = r(N)
- qui count if item`j' == `m' & tt == 1
- local nb_rn1_g1 = r(N)
- local nb_rn = min(`nb_rn1_g0',`nb_rn1_g1')
- if `nb_rn' == 0 {
- qui replace comz = 1
- local recoda_`j' = 1
- if `m' == 0 | `m' < `minm`j'_t1_g0' | `m' < `minm`j'_t1_g1' {
- local stop = 1
- forvalues kk = 1/`=`nbm_`j''-`m'' {
- qui count if item`j' == `=`m' + `kk'' & tt == 0
- local v`kk'1_0 = r(N)
- qui count if item`j' == `=`m' + `kk'' & tt == 1
- local v`kk'1_1 = r(N)
- if (`v`kk'1_0' != 0 | `v`kk'1_1' != 0) & `stop' != 0 {
- qui replace item`j'= `=`m'+`kk'' if item`j'==`m'
- local zzz=`j'+`nbitems'
- *qui replace item`zzz'=`=`m'+`kk'' if item``=`j'+`nbitems'''==`m'
- *di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
- local stop = 0
- }
- }
- }
- else if `m' == `=`nbm_`j''-1' | `m' >= `maxm`j'_t1_g1' {
- local stop = 1
- forvalues kk = 1/`=`m'' {
- qui count if item`j' == `=`m' - `kk'' & tt == 0
- local v`kk'1_0 = r(N)
- qui count if item`j' == `=`m' - `kk'' & tt == 1
- local v`kk'1_1 = r(N)
- if (`v`kk'1_0' != 0 | `v`kk'1_1' != 0) & `stop' != 0 {
- qui replace item`j'= `=`m' - `kk'' if item`j'==`m'
- local zzz=`j'+`nbitems'
- *qui replace item`zzz'= `=`m' - `kk'' if item`zzz'==`m'
- *di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
- local stop = 0
- }
- }
- }
- else {
- if runiform()>0.5{
- local stop = 1
- forvalues kk = 1/`m' {
- qui count if item`j' == `=`m' - `kk'' & tt == 0
- local v`kk'1_0 = r(N)
- qui count if item`j' == `=`m' - `kk'' & tt == 1
- local v`kk'1_1 = r(N)
- if (`v`kk'1_0' != 0 | `v`kk'1_1' != 0) & `stop' != 0 {
- qui replace item`j'= `=`m'-`kk'' if item`j'==`m'
- local zzz=`j'+`nbitems'
- *qui replace item`zzz'=`=`m'-`kk'' if item``=`j'+`nbitems'''==`m'
- *di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
- local stop = 0
- }
- }
- }
- else {
- local stop = 1
- forvalues kk = 1/`=`nbm_`j''-`m'' {
- qui count if item`j' == `=`m' + `kk'' & tt == 0
- local v`kk'1_0 = r(N)
- qui count if item`j' == `=`m' + `kk'' & tt == 1
- local v`kk'1_1 = r(N)
- if (`v`kk'1_0' != 0 | `v`kk'1_1' != 0) & `stop' != 0{
- qui replace item`j'=`=`m' + `kk'' if item`j'==`m'
- local zzz=`j'+`nbitems'
- *qui replace item`zzz'=`=`m' + `kk'' if item``=`j'+`nbitems'''==`m'
- *di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
- local stop = 0
- }
- else {
- if `stop' != 0 {
- qui replace item`j'= `nbm_`j'' if item`j'==`m'
- local zzz=`j'+`nbitems'
- *qui replace item`zzz'= `nbm_`j'' if item``=`j'+`nbitems'''==`m'
- *di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
- local stop = 0
- }
- }
- }
- }
- }
- }
- }
- qui levelsof item`j'
- local val = r(levels)
- local checker: word 1 of `val'
- local checker2: word 2 of `val'
- local checker3: word 3 of `val'
- local nummoda=r(r)
- local nbmoda_`j'=`nummoda'
- if (`nummoda'==2) {
- qui recode item`j' (`checker'=0) (`checker2'=1)
- }
- if (`nummoda'==3) {
- if (`checker'!=0) {
- qui recode item`j' (`checker'=0) (`checker2'=1) (`checker3'=2)
- }
- else if (`checker2'!=1) {
- qui recode item`j' (`checker2'=1) (`checker3'=2)
- }
- else if (`checker3'!=2) {
- qui recode item`j' (`checker3'=2)
- }
- }
- }
-
- qui valuesof comz
- local val = r(values)
- local checker: word 1 of `val'
- }
- else {
- forvalues jj=1/`nbitems' {
- local nbmoda_`jj'=`nbmoda'
- }
- }
-
-
- * ROSALI
- qui rosali_original item1-item`nbitems' item1-item`nbitems', group(tt)
- qui mat resmat=r(difitems)
- local nbitems2 = 2*`nbitems'
-
- * Calculer le nbre d'items détectés
- local nbdetect = 0
- local stop = 0
- forvalues jj=1/`nbitems' {
- if (`stop'==0) {
- mat testm=J(1,1,.)
- if (resmat[1,`jj']==testm[1,1]) {
- local stop = 1
- local nbdetect = `jj'-1
- }
- }
- }
-
- * Stocker les items détectés +
- * Définition des contraintes
- local csrt=0
- mat testm=J(1,1,0)
- forvalues u=1/`nbdetect' {
- local difitems`u'=resmat[1,`u']
- local i=`difitems`u''
- if (`nbmoda_`i''==3 & resmat[1,`nbitems'+`i']!=testm[1,1]){
- local constrnt`u' = "constraint `u' 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))"
- qui `constrnt`u''
- local v=`u'+100
- local constrnt`u'_2 = "constraint `v' 3*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([3.item`i']_cons-([3.item`i']_cons+[3.item`i'] tt))"
- qui `constrnt`u'_2'
- }
- if (`nbmoda_`i''==2 & resmat[1,`nbitems'+`i']!=testm[1,1]){
- local constrnt`u' = "constraint `u' 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))"
- qui `constrnt`u''
- }
- }
-
- * Définition du modèle
- local mod "gsem "
- local conformula = ""
- forvalues i=1/`nbitems' {
- local mod = "`mod'"+"(1.item`i'<-THETA@1)"
- if (`nbmoda_`i''==3) {
- local mod = "`mod'"+"(2.item`i'<-THETA@2)(3.item`i'<-THETA@3)"
- }
- else if (`nbmoda_`i''==2) {
- local mod = "`mod'"+"(2.item`i'<-THETA@2)"
- }
- }
- forvalues u=1/`nbdetect' {
- local v=`difitems`u''
- local mod = "`mod'"+"(1.item`v'<-THETA@1 tt)"
- if (`nbmoda_`v''==3) {
- local mod = "`mod'"+"(2.item`v'<-THETA@2 tt)(3.item`v'<-THETA@3 tt)"
- }
- else if (`nbmoda_`v''==2) {
- local mod = "`mod'"+"(2.item`v'<-THETA@2 tt)"
- }
- local w= 100+`u'
- if (resmat[1,`nbitems'+`v']!=testm[1,1] & `nbmoda_`v''==3) {
- local conformula = "`conformula'" + "`u' " + "`w' "
- }
- else if (resmat[1,`nbitems'+`v']!=testm[1,1] & `nbmoda_`v''==2) {
- local conformula = "`conformula'" + "`u' "
- }
- }
- if ("`conformula'" != "") {
- local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent constraint(`conformula')"
- }
- else {
- local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent"
- }
- *calcul du modèle
- qui `mod'
- mat V=r(table)
- mat W=V[1..2,1...]
-
- * compilation
- forvalues j=1/`nbitems' {
- forvalues z=1/`nbmoda_`j'' {
- mat outmat[`k',colnumb(outmat,"item`j'_`z'")] = W[1,colnumb(W,"`z'.item`j':_cons")]
- }
- }
- * compilation DIF
- forvalues u=1/`nbdetect' {
- local j=`difitems`u''
- forvalues z=1/`nbmoda_`j'' {
- mat outmat[`k',colnumb(outmat,"dif_`u'_`z'")] = W[1,colnumb(W,"`z'.item`j':tt")]
- mat outmat[`k',colnumb(outmat,"dif_detect_`u'")] = `j'
- }
- }
-
- * Stocker les items de DIF originaux
- if (`nbdif' > 0) {
- qui levelsof dif1
- local ldif1 = r(levels)
- local diff1: word 1 of `ldif1'
- qui mat outmat[`k',colnumb(outmat,"real_dif_1")]=`diff1'
- if (`nbdif' > 1) {
- qui levelsof dif2
- local ldif2 = r(levels)
- local diff2: word 1 of `ldif2'
- qui mat outmat[`k',colnumb(outmat,"real_dif_2")]=`diff2'
- if (`nbdif' > 2) {
- qui levelsof dif3
- local ldif3 = r(levels)
- local diff3: word 1 of `ldif3'
- qui mat outmat[`k',colnumb(outmat,"real_dif_3")]=`diff3'
- }
- }
- }
- qui mat outmat[`k',colnumb(outmat,"beta")]=W[1,colnumb(W,"THETA:tt")]
- qui mat outmat[`k',colnumb(outmat,"se_beta")]=W[2,colnumb(W,"THETA:tt")]
- restore
- }
- putexcel set "`path_res'/`s'`scen'_`Nn'_original.xls", sheet("outmat") replace
- putexcel A1=matrix(outmat), colnames
-}
-}
-}
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
deleted file mode 100644
index 9c67cfa..0000000
--- a/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S14.do
+++ /dev/null
@@ -1,378 +0,0 @@
-*=================================================================================================================================================
-* Date : 2024-01-23
-* Stata version : Stata 18 SE
-*
-* This program analyses simulated data accounting for DIF through a partial credit model
-*
-* ado-files needed : - pcm, rosali (version 5.5 October 25, 2023, available on gitea)
-*
-*
-*================================================================================================================================================
-adopath+"/home/corentin/Documents/These/Recherche/ROSALI-SIM/Modules/rosali_custom"
-
-
-local N = "50 100 200 300"
- local ss = "14"
- foreach s in `ss' {
- foreach Nnn in `N' {
- local Nn = `Nnn'
- local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N`Nn'"
- if (`s'<=4) {
- local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N`Nn'"
- }
- local path_res = "/home/corentin/Documents/These/Recherche/Simulations/Analysis/ROSALI-DIF/N`Nn'"
- local scenarios = "A B C D E F G"
- foreach scen in `scenarios' {
- clear
- import delim "`path_data'/scenario_`s'`scen'_`Nn'.csv", encoding(ISO-8859-2) case(preserve) clear
- rename TT tt
-
- if (`s'<=2) {
- local nbitems=4
- }
- else if (`s'<=4) {
- local nbitems=7
- }
- else if (`s'<=12) {
- local nbitems=4
- }
- else {
- local nbitems=7
- }
-
- if (mod(`s',2)==0) {
- local nbmoda=3
- }
- else {
- local nbmoda=1
- }
-
- if (`s'<=4) {
- local nbdif=0
- }
- else if (`s'<=8) {
- local nbdif=1
- }
- else if (`s'<=16) {
- local nbdif=2
- }
- else {
- local nbdif=3
- }
- * taillemat = Maximum J*M cases pour les items par et J*M cases pour les dif par + J cases pour les DIF detect + nbdif cases pour dif réel
- local taillemat=2*`nbitems'*`nbmoda'+`nbitems'+`nbdif'+2
- 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'
- }
- }
-
-
- * ROSALI
- qui rosali_original item1-item`nbitems' item1-item`nbitems', group(tt)
- qui mat resmat=r(difitems)
- local nbitems2 = 2*`nbitems'
-
- * Calculer le nbre d'items détectés
- local nbdetect = 0
- local stop = 0
- forvalues jj=1/`nbitems' {
- if (`stop'==0) {
- mat testm=J(1,1,.)
- if (resmat[1,`jj']==testm[1,1]) {
- local stop = 1
- local nbdetect = `jj'-1
- }
- }
- }
-
- * Stocker les items détectés +
- * Définition des contraintes
- local csrt=0
- mat testm=J(1,1,0)
- forvalues u=1/`nbdetect' {
- local difitems`u'=resmat[1,`u']
- local i=`difitems`u''
- if (`nbmoda_`i''==3 & resmat[1,`nbitems'+`i']!=testm[1,1]){
- local constrnt`u' = "constraint `u' 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))"
- qui `constrnt`u''
- local v=`u'+100
- local constrnt`u'_2 = "constraint `v' 3*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([3.item`i']_cons-([3.item`i']_cons+[3.item`i'] tt))"
- qui `constrnt`u'_2'
- }
- if (`nbmoda_`i''==2 & resmat[1,`nbitems'+`i']!=testm[1,1]){
- local constrnt`u' = "constraint `u' 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))"
- qui `constrnt`u''
- }
- }
-
- * Définition du modèle
- local mod "gsem "
- local conformula = ""
- forvalues i=1/`nbitems' {
- local mod = "`mod'"+"(1.item`i'<-THETA@1)"
- if (`nbmoda_`i''==3) {
- local mod = "`mod'"+"(2.item`i'<-THETA@2)(3.item`i'<-THETA@3)"
- }
- else if (`nbmoda_`i''==2) {
- local mod = "`mod'"+"(2.item`i'<-THETA@2)"
- }
- }
- forvalues u=1/`nbdetect' {
- local v=`difitems`u''
- local mod = "`mod'"+"(1.item`v'<-THETA@1 tt)"
- if (`nbmoda_`v''==3) {
- local mod = "`mod'"+"(2.item`v'<-THETA@2 tt)(3.item`v'<-THETA@3 tt)"
- }
- else if (`nbmoda_`v''==2) {
- local mod = "`mod'"+"(2.item`v'<-THETA@2 tt)"
- }
- local w= 100+`u'
- 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'
- 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
- }
- }
- }
diff --git a/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S15.do b/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S15.do
deleted file mode 100644
index 9611f26..0000000
--- a/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S15.do
+++ /dev/null
@@ -1,364 +0,0 @@
-*=================================================================================================================================================
-* Date : 2024-01-23
-* Stata version : Stata 18 SE
-*
-* This program analyses simulated data accounting for DIF through a partial credit model
-*
-* ado-files needed : - pcm, rosali (version 5.5 October 25, 2023, available on gitea)
-*
-*
-*================================================================================================================================================
-adopath+"/home/corentin/Documents/These/Recherche/ROSALI-SIM/Modules/rosali_custom"
-
-
-local N = "50 100 200 300"
- local ss = "15"
- foreach s in `ss' {
- foreach Nnn in `N' {
- local Nn = `Nnn'
- local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N`Nn'"
- if (`s'<=4) {
- local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N`Nn'"
- }
- local path_res = "/home/corentin/Documents/These/Recherche/Simulations/Analysis/ROSALI-DIF/N`Nn'"
- local scenarios = "A B C D E F G"
- foreach scen in `scenarios' {
- clear
- import delim "`path_data'/scenario_`s'`scen'_`Nn'.csv", encoding(ISO-8859-2) case(preserve) clear
- rename TT tt
-
- if (`s'<=2) {
- local nbitems=4
- }
- else if (`s'<=4) {
- local nbitems=7
- }
- else if (`s'<=12) {
- local nbitems=4
- }
- else {
- local nbitems=7
- }
-
-if (mod(`s',2)==0) {
- local nbmoda=3
-}
-else {
- local nbmoda=1
-}
-
- if (`s'<=4) {
- local nbdif=0
- }
- else if (`s'<=8) {
- local nbdif=1
- }
- else if (`s'<=16) {
- local nbdif=2
- }
- else {
- local nbdif=3
- }
- * taillemat = Maximum J*M cases pour les items par et J*M cases pour les dif par + J cases pour les DIF detect + nbdif cases pour dif réel
- local taillemat=2*`nbitems'*`nbmoda'+`nbitems'+`nbdif'+2
- local colna=""
- forvalues i=1/`nbitems' {
- forvalues z=1/`nbmoda' {
- local colna = "`colna'"+"item`i'_`z' "
- local colna = "`colna'"+"dif_`i'_`z' "
- }
- }
- forvalues i=1/`nbitems' {
- local colna = "`colna'"+"dif_detect_`i' "
- }
-
- forvalues i=1/`nbdif' {
- local colna = "`colna'"+"real_dif_`i' "
- }
-local colna = "`colna'" + "beta " + "se_beta"
-
-
- mat outmat = J(1000,`taillemat',.)
- mat colnames outmat= `colna'
- di "Scenario `s'`scen' / N=`Nnn'"
- forvalues k=1/1000 {
- if (mod(`k',100)==0) {
- di "`k'/1000"
- }
- preserve
- qui keep if replication==`k'
-
-
- * MERGE des modalités si non représentées
-
- if (`nbmoda'>1 & `Nn'==50) {
- local com_z = 0
- qui gen comz = 0
- forvalues j = 1 / `nbitems' {
- local recoda_`j' = 0
- qui tab item`j' if tt == 0, matrow(rect1_g0_`j') matcell(nbrt1_g0_`j')
- local maxm`j'_t1_g0 = rect1_g0_`j'[r(r),1]
- local minm`j'_t1_g0 = rect1_g0_`j'[1,1]
-
- qui tab item`j' if tt == 1, matrow(rect1_g1_`j') matcell(nbrt1_g1_`j')
- local minm`j'_t1_g1 = rect1_g1_`j'[1,1]
- local maxm`j'_t1_g1 = rect1_g1_`j'[r(r),1]
-
- local minm_`j' = min(`minm`j'_t1_g0',`minm`j'_t1_g1')
- local maxm_`j' = max(`maxm`j'_t1_g0',`maxm`j'_t1_g1')
- local nbm_`j' = `=`maxm_`j''-`minm_`j'''
-
- if `minm_`j'' != 0 & `com_z' == 0 {
- local com_z = 1
- }
-
- qui count if item`j' == 3 & tt == 0
- local mod3plac = r(N)
- qui count if item`j' == 3 & tt == 1
- local mod3tt = r(N)
- local nb_rn3 = min(`mod3plac',`mod3tt')
- if `nb_rn3'==0 {
- qui replace comz = 1
- }
-
- forvalues m = 0/`=`nbm_`j''-1' {
- qui count if item`j' == `m' & tt == 0
- local nb_rn1_g0 = r(N)
- qui count if item`j' == `m' & tt == 1
- local nb_rn1_g1 = r(N)
- local nb_rn = min(`nb_rn1_g0',`nb_rn1_g1')
- if `nb_rn' == 0 {
- qui replace comz = 1
- local recoda_`j' = 1
- if `m' == 0 | `m' < `minm`j'_t1_g0' | `m' < `minm`j'_t1_g1' {
- local stop = 1
- forvalues kk = 1/`=`nbm_`j''-`m'' {
- qui count if item`j' == `=`m' + `kk'' & tt == 0
- local v`kk'1_0 = r(N)
- qui count if item`j' == `=`m' + `kk'' & tt == 1
- local v`kk'1_1 = r(N)
- if (`v`kk'1_0' != 0 | `v`kk'1_1' != 0) & `stop' != 0 {
- qui replace item`j'= `=`m'+`kk'' if item`j'==`m'
- local zzz=`j'+`nbitems'
- *qui replace item`zzz'=`=`m'+`kk'' if item``=`j'+`nbitems'''==`m'
- *di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
- local stop = 0
- }
- }
- }
- else if `m' == `=`nbm_`j''-1' | `m' >= `maxm`j'_t1_g1' {
- local stop = 1
- forvalues kk = 1/`=`m'' {
- qui count if item`j' == `=`m' - `kk'' & tt == 0
- local v`kk'1_0 = r(N)
- qui count if item`j' == `=`m' - `kk'' & tt == 1
- local v`kk'1_1 = r(N)
- if (`v`kk'1_0' != 0 | `v`kk'1_1' != 0) & `stop' != 0 {
- qui replace item`j'= `=`m' - `kk'' if item`j'==`m'
- local zzz=`j'+`nbitems'
- *qui replace item`zzz'= `=`m' - `kk'' if item`zzz'==`m'
- *di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
- local stop = 0
- }
- }
- }
- else {
- if runiform()>0.5{
- local stop = 1
- forvalues kk = 1/`m' {
- qui count if item`j' == `=`m' - `kk'' & tt == 0
- local v`kk'1_0 = r(N)
- qui count if item`j' == `=`m' - `kk'' & tt == 1
- local v`kk'1_1 = r(N)
- if (`v`kk'1_0' != 0 | `v`kk'1_1' != 0) & `stop' != 0 {
- qui replace item`j'= `=`m'-`kk'' if item`j'==`m'
- local zzz=`j'+`nbitems'
- *qui replace item`zzz'=`=`m'-`kk'' if item``=`j'+`nbitems'''==`m'
- *di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
- local stop = 0
- }
- }
- }
- else {
- local stop = 1
- forvalues kk = 1/`=`nbm_`j''-`m'' {
- qui count if item`j' == `=`m' + `kk'' & tt == 0
- local v`kk'1_0 = r(N)
- qui count if item`j' == `=`m' + `kk'' & tt == 1
- local v`kk'1_1 = r(N)
- if (`v`kk'1_0' != 0 | `v`kk'1_1' != 0) & `stop' != 0{
- qui replace item`j'=`=`m' + `kk'' if item`j'==`m'
- local zzz=`j'+`nbitems'
- *qui replace item`zzz'=`=`m' + `kk'' if item``=`j'+`nbitems'''==`m'
- *di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
- local stop = 0
- }
- else {
- if `stop' != 0 {
- qui replace item`j'= `nbm_`j'' if item`j'==`m'
- local zzz=`j'+`nbitems'
- *qui replace item`zzz'= `nbm_`j'' if item``=`j'+`nbitems'''==`m'
- *di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
- local stop = 0
- }
- }
- }
- }
- }
- }
- }
- qui levelsof item`j'
- local val = r(levels)
- local checker: word 1 of `val'
- local checker2: word 2 of `val'
- local checker3: word 3 of `val'
- local nummoda=r(r)
- local nbmoda_`j'=`nummoda'
- if (`nummoda'==2) {
- qui recode item`j' (`checker'=0) (`checker2'=1)
- }
- if (`nummoda'==3) {
- if (`checker'!=0) {
- qui recode item`j' (`checker'=0) (`checker2'=1) (`checker3'=2)
- }
- else if (`checker2'!=1) {
- qui recode item`j' (`checker2'=1) (`checker3'=2)
- }
- else if (`checker3'!=2) {
- qui recode item`j' (`checker3'=2)
- }
- }
- }
-
- qui valuesof comz
- local val = r(values)
- local checker: word 1 of `val'
- }
- else {
- forvalues jj=1/`nbitems' {
- local nbmoda_`jj'=`nbmoda'
- }
- }
-
-
- * ROSALI
- qui rosali_original item1-item`nbitems' item1-item`nbitems', group(tt)
- qui mat resmat=r(difitems)
- local nbitems2 = 2*`nbitems'
-
- * Calculer le nbre d'items détectés
- local nbdetect = 0
- local stop = 0
- forvalues jj=1/`nbitems' {
- if (`stop'==0) {
- mat testm=J(1,1,.)
- if (resmat[1,`jj']==testm[1,1]) {
- local stop = 1
- local nbdetect = `jj'-1
- }
- }
- }
-
- * Stocker les items détectés +
- * Définition des contraintes
- local csrt=0
- mat testm=J(1,1,0)
- forvalues u=1/`nbdetect' {
- local difitems`u'=resmat[1,`u']
- local i=`difitems`u''
- if (`nbmoda_`i''==3 & resmat[1,`nbitems'+`i']!=testm[1,1]){
- local constrnt`u' = "constraint `u' 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))"
- qui `constrnt`u''
- local v=`u'+100
- local constrnt`u'_2 = "constraint `v' 3*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([3.item`i']_cons-([3.item`i']_cons+[3.item`i'] tt))"
- qui `constrnt`u'_2'
- }
- if (`nbmoda_`i''==2 & resmat[1,`nbitems'+`i']!=testm[1,1]){
- local constrnt`u' = "constraint `u' 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))"
- qui `constrnt`u''
- }
- }
-
- * Définition du modèle
- local mod "gsem "
- local conformula = ""
- forvalues i=1/`nbitems' {
- local mod = "`mod'"+"(1.item`i'<-THETA@1)"
- if (`nbmoda_`i''==3) {
- local mod = "`mod'"+"(2.item`i'<-THETA@2)(3.item`i'<-THETA@3)"
- }
- else if (`nbmoda_`i''==2) {
- local mod = "`mod'"+"(2.item`i'<-THETA@2)"
- }
- }
- forvalues u=1/`nbdetect' {
- local v=`difitems`u''
- local mod = "`mod'"+"(1.item`v'<-THETA@1 tt)"
- if (`nbmoda_`v''==3) {
- local mod = "`mod'"+"(2.item`v'<-THETA@2 tt)(3.item`v'<-THETA@3 tt)"
- }
- else if (`nbmoda_`v''==2) {
- local mod = "`mod'"+"(2.item`v'<-THETA@2 tt)"
- }
- local w= 100+`u'
- if (resmat[1,`nbitems'+`v']!=testm[1,1] & `nbmoda_`v''==3) {
- local conformula = "`conformula'" + "`u' " + "`w' "
- }
- else if (resmat[1,`nbitems'+`v']!=testm[1,1] & `nbmoda_`v''==2) {
- local conformula = "`conformula'" + "`u' "
- }
- }
- if ("`conformula'" != "") {
- local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent constraint(`conformula')"
- }
- else {
- local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent"
- }
- *calcul du modèle
- qui `mod'
- mat V=r(table)
- mat W=V[1..2,1...]
-
- * compilation
- forvalues j=1/`nbitems' {
- forvalues z=1/`nbmoda_`j'' {
- mat outmat[`k',colnumb(outmat,"item`j'_`z'")] = W[1,colnumb(W,"`z'.item`j':_cons")]
- }
- }
- * compilation DIF
- forvalues u=1/`nbdetect' {
- local j=`difitems`u''
- forvalues z=1/`nbmoda_`j'' {
- mat outmat[`k',colnumb(outmat,"dif_`u'_`z'")] = W[1,colnumb(W,"`z'.item`j':tt")]
- mat outmat[`k',colnumb(outmat,"dif_detect_`u'")] = `j'
- }
- }
-
- * Stocker les items de DIF originaux
- if (`nbdif' > 0) {
- qui levelsof dif1
- local ldif1 = r(levels)
- local diff1: word 1 of `ldif1'
- qui mat outmat[`k',colnumb(outmat,"real_dif_1")]=`diff1'
- if (`nbdif' > 1) {
- qui levelsof dif2
- local ldif2 = r(levels)
- local diff2: word 1 of `ldif2'
- qui mat outmat[`k',colnumb(outmat,"real_dif_2")]=`diff2'
- if (`nbdif' > 2) {
- qui levelsof dif3
- local ldif3 = r(levels)
- local diff3: word 1 of `ldif3'
- qui mat outmat[`k',colnumb(outmat,"real_dif_3")]=`diff3'
- }
- }
- }
- qui mat outmat[`k',colnumb(outmat,"beta")]=W[1,colnumb(W,"THETA:tt")]
- qui mat outmat[`k',colnumb(outmat,"se_beta")]=W[2,colnumb(W,"THETA:tt")]
- restore
- }
- putexcel set "`path_res'/`s'`scen'_`Nn'_original.xls", sheet("outmat") replace
- putexcel A1=matrix(outmat), colnames
-}
-}
-}
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
deleted file mode 100644
index e58031b..0000000
--- a/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S16.do
+++ /dev/null
@@ -1,378 +0,0 @@
-*=================================================================================================================================================
-* Date : 2024-01-23
-* Stata version : Stata 18 SE
-*
-* This program analyses simulated data accounting for DIF through a partial credit model
-*
-* ado-files needed : - pcm, rosali (version 5.5 October 25, 2023, available on gitea)
-*
-*
-*================================================================================================================================================
-adopath+"/home/corentin/Documents/These/Recherche/ROSALI-SIM/Modules/rosali_custom"
-
-
-local N = "50 100 200 300"
- local ss = "16"
- foreach s in `ss' {
- foreach Nnn in `N' {
- local Nn = `Nnn'
- local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N`Nn'"
- if (`s'<=4) {
- local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N`Nn'"
- }
- local path_res = "/home/corentin/Documents/These/Recherche/Simulations/Analysis/ROSALI-DIF/N`Nn'"
- local scenarios = "A B C D E F G"
- foreach scen in `scenarios' {
- clear
- import delim "`path_data'/scenario_`s'`scen'_`Nn'.csv", encoding(ISO-8859-2) case(preserve) clear
- rename TT tt
-
- if (`s'<=2) {
- local nbitems=4
- }
- else if (`s'<=4) {
- local nbitems=7
- }
- else if (`s'<=12) {
- local nbitems=4
- }
- else {
- local nbitems=7
- }
-
- if (mod(`s',2)==0) {
- local nbmoda=3
- }
- else {
- local nbmoda=1
- }
-
- if (`s'<=4) {
- local nbdif=0
- }
- else if (`s'<=8) {
- local nbdif=1
- }
- else if (`s'<=16) {
- local nbdif=2
- }
- else {
- local nbdif=3
- }
- * taillemat = Maximum J*M cases pour les items par et J*M cases pour les dif par + J cases pour les DIF detect + nbdif cases pour dif réel
- local taillemat=2*`nbitems'*`nbmoda'+`nbitems'+`nbdif'+2
- 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'
- }
- }
-
-
- * ROSALI
- qui rosali_original item1-item`nbitems' item1-item`nbitems', group(tt)
- qui mat resmat=r(difitems)
- local nbitems2 = 2*`nbitems'
-
- * Calculer le nbre d'items détectés
- local nbdetect = 0
- local stop = 0
- forvalues jj=1/`nbitems' {
- if (`stop'==0) {
- mat testm=J(1,1,.)
- if (resmat[1,`jj']==testm[1,1]) {
- local stop = 1
- local nbdetect = `jj'-1
- }
- }
- }
-
- * Stocker les items détectés +
- * Définition des contraintes
- local csrt=0
- mat testm=J(1,1,0)
- forvalues u=1/`nbdetect' {
- local difitems`u'=resmat[1,`u']
- local i=`difitems`u''
- if (`nbmoda_`i''==3 & resmat[1,`nbitems'+`i']!=testm[1,1]){
- local constrnt`u' = "constraint `u' 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))"
- qui `constrnt`u''
- local v=`u'+100
- local constrnt`u'_2 = "constraint `v' 3*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([3.item`i']_cons-([3.item`i']_cons+[3.item`i'] tt))"
- qui `constrnt`u'_2'
- }
- if (`nbmoda_`i''==2 & resmat[1,`nbitems'+`i']!=testm[1,1]){
- local constrnt`u' = "constraint `u' 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))"
- qui `constrnt`u''
- }
- }
-
- * Définition du modèle
- local mod "gsem "
- local conformula = ""
- forvalues i=1/`nbitems' {
- local mod = "`mod'"+"(1.item`i'<-THETA@1)"
- if (`nbmoda_`i''==3) {
- local mod = "`mod'"+"(2.item`i'<-THETA@2)(3.item`i'<-THETA@3)"
- }
- else if (`nbmoda_`i''==2) {
- local mod = "`mod'"+"(2.item`i'<-THETA@2)"
- }
- }
- forvalues u=1/`nbdetect' {
- local v=`difitems`u''
- local mod = "`mod'"+"(1.item`v'<-THETA@1 tt)"
- if (`nbmoda_`v''==3) {
- local mod = "`mod'"+"(2.item`v'<-THETA@2 tt)(3.item`v'<-THETA@3 tt)"
- }
- else if (`nbmoda_`v''==2) {
- local mod = "`mod'"+"(2.item`v'<-THETA@2 tt)"
- }
- local w= 100+`u'
- 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'
- 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
- }
- }
- }
diff --git a/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S17.do b/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S17.do
deleted file mode 100644
index 218bc08..0000000
--- a/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S17.do
+++ /dev/null
@@ -1,364 +0,0 @@
-*=================================================================================================================================================
-* Date : 2024-01-23
-* Stata version : Stata 18 SE
-*
-* This program analyses simulated data accounting for DIF through a partial credit model
-*
-* ado-files needed : - pcm, rosali (version 5.5 October 25, 2023, available on gitea)
-*
-*
-*================================================================================================================================================
-adopath+"/home/corentin/Documents/These/Recherche/ROSALI-SIM/Modules/rosali_custom"
-
-
-local N = "50 100 200 300"
- local ss = "17"
- foreach s in `ss' {
- foreach Nnn in `N' {
- local Nn = `Nnn'
- local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N`Nn'"
- if (`s'<=4) {
- local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N`Nn'"
- }
- local path_res = "/home/corentin/Documents/These/Recherche/Simulations/Analysis/ROSALI-DIF/N`Nn'"
- local scenarios = "A B C D E F G"
- foreach scen in `scenarios' {
- clear
- import delim "`path_data'/scenario_`s'`scen'_`Nn'.csv", encoding(ISO-8859-2) case(preserve) clear
- rename TT tt
-
- if (`s'<=2) {
- local nbitems=4
- }
- else if (`s'<=4) {
- local nbitems=7
- }
- else if (`s'<=12) {
- local nbitems=4
- }
- else {
- local nbitems=7
- }
-
-if (mod(`s',2)==0) {
- local nbmoda=3
-}
-else {
- local nbmoda=1
-}
-
- if (`s'<=4) {
- local nbdif=0
- }
- else if (`s'<=8) {
- local nbdif=1
- }
- else if (`s'<=16) {
- local nbdif=2
- }
- else {
- local nbdif=3
- }
- * taillemat = Maximum J*M cases pour les items par et J*M cases pour les dif par + J cases pour les DIF detect + nbdif cases pour dif réel
- local taillemat=2*`nbitems'*`nbmoda'+`nbitems'+`nbdif'+2
- local colna=""
- forvalues i=1/`nbitems' {
- forvalues z=1/`nbmoda' {
- local colna = "`colna'"+"item`i'_`z' "
- local colna = "`colna'"+"dif_`i'_`z' "
- }
- }
- forvalues i=1/`nbitems' {
- local colna = "`colna'"+"dif_detect_`i' "
- }
-
- forvalues i=1/`nbdif' {
- local colna = "`colna'"+"real_dif_`i' "
- }
-local colna = "`colna'" + "beta " + "se_beta"
-
-
- mat outmat = J(1000,`taillemat',.)
- mat colnames outmat= `colna'
- di "Scenario `s'`scen' / N=`Nnn'"
- forvalues k=1/1000 {
- if (mod(`k',100)==0) {
- di "`k'/1000"
- }
- preserve
- qui keep if replication==`k'
-
-
- * MERGE des modalités si non représentées
-
- if (`nbmoda'>1 & `Nn'==50) {
- local com_z = 0
- qui gen comz = 0
- forvalues j = 1 / `nbitems' {
- local recoda_`j' = 0
- qui tab item`j' if tt == 0, matrow(rect1_g0_`j') matcell(nbrt1_g0_`j')
- local maxm`j'_t1_g0 = rect1_g0_`j'[r(r),1]
- local minm`j'_t1_g0 = rect1_g0_`j'[1,1]
-
- qui tab item`j' if tt == 1, matrow(rect1_g1_`j') matcell(nbrt1_g1_`j')
- local minm`j'_t1_g1 = rect1_g1_`j'[1,1]
- local maxm`j'_t1_g1 = rect1_g1_`j'[r(r),1]
-
- local minm_`j' = min(`minm`j'_t1_g0',`minm`j'_t1_g1')
- local maxm_`j' = max(`maxm`j'_t1_g0',`maxm`j'_t1_g1')
- local nbm_`j' = `=`maxm_`j''-`minm_`j'''
-
- if `minm_`j'' != 0 & `com_z' == 0 {
- local com_z = 1
- }
-
- qui count if item`j' == 3 & tt == 0
- local mod3plac = r(N)
- qui count if item`j' == 3 & tt == 1
- local mod3tt = r(N)
- local nb_rn3 = min(`mod3plac',`mod3tt')
- if `nb_rn3'==0 {
- qui replace comz = 1
- }
-
- forvalues m = 0/`=`nbm_`j''-1' {
- qui count if item`j' == `m' & tt == 0
- local nb_rn1_g0 = r(N)
- qui count if item`j' == `m' & tt == 1
- local nb_rn1_g1 = r(N)
- local nb_rn = min(`nb_rn1_g0',`nb_rn1_g1')
- if `nb_rn' == 0 {
- qui replace comz = 1
- local recoda_`j' = 1
- if `m' == 0 | `m' < `minm`j'_t1_g0' | `m' < `minm`j'_t1_g1' {
- local stop = 1
- forvalues kk = 1/`=`nbm_`j''-`m'' {
- qui count if item`j' == `=`m' + `kk'' & tt == 0
- local v`kk'1_0 = r(N)
- qui count if item`j' == `=`m' + `kk'' & tt == 1
- local v`kk'1_1 = r(N)
- if (`v`kk'1_0' != 0 | `v`kk'1_1' != 0) & `stop' != 0 {
- qui replace item`j'= `=`m'+`kk'' if item`j'==`m'
- local zzz=`j'+`nbitems'
- *qui replace item`zzz'=`=`m'+`kk'' if item``=`j'+`nbitems'''==`m'
- *di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
- local stop = 0
- }
- }
- }
- else if `m' == `=`nbm_`j''-1' | `m' >= `maxm`j'_t1_g1' {
- local stop = 1
- forvalues kk = 1/`=`m'' {
- qui count if item`j' == `=`m' - `kk'' & tt == 0
- local v`kk'1_0 = r(N)
- qui count if item`j' == `=`m' - `kk'' & tt == 1
- local v`kk'1_1 = r(N)
- if (`v`kk'1_0' != 0 | `v`kk'1_1' != 0) & `stop' != 0 {
- qui replace item`j'= `=`m' - `kk'' if item`j'==`m'
- local zzz=`j'+`nbitems'
- *qui replace item`zzz'= `=`m' - `kk'' if item`zzz'==`m'
- *di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
- local stop = 0
- }
- }
- }
- else {
- if runiform()>0.5{
- local stop = 1
- forvalues kk = 1/`m' {
- qui count if item`j' == `=`m' - `kk'' & tt == 0
- local v`kk'1_0 = r(N)
- qui count if item`j' == `=`m' - `kk'' & tt == 1
- local v`kk'1_1 = r(N)
- if (`v`kk'1_0' != 0 | `v`kk'1_1' != 0) & `stop' != 0 {
- qui replace item`j'= `=`m'-`kk'' if item`j'==`m'
- local zzz=`j'+`nbitems'
- *qui replace item`zzz'=`=`m'-`kk'' if item``=`j'+`nbitems'''==`m'
- *di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
- local stop = 0
- }
- }
- }
- else {
- local stop = 1
- forvalues kk = 1/`=`nbm_`j''-`m'' {
- qui count if item`j' == `=`m' + `kk'' & tt == 0
- local v`kk'1_0 = r(N)
- qui count if item`j' == `=`m' + `kk'' & tt == 1
- local v`kk'1_1 = r(N)
- if (`v`kk'1_0' != 0 | `v`kk'1_1' != 0) & `stop' != 0{
- qui replace item`j'=`=`m' + `kk'' if item`j'==`m'
- local zzz=`j'+`nbitems'
- *qui replace item`zzz'=`=`m' + `kk'' if item``=`j'+`nbitems'''==`m'
- *di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
- local stop = 0
- }
- else {
- if `stop' != 0 {
- qui replace item`j'= `nbm_`j'' if item`j'==`m'
- local zzz=`j'+`nbitems'
- *qui replace item`zzz'= `nbm_`j'' if item``=`j'+`nbitems'''==`m'
- *di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
- local stop = 0
- }
- }
- }
- }
- }
- }
- }
- qui levelsof item`j'
- local val = r(levels)
- local checker: word 1 of `val'
- local checker2: word 2 of `val'
- local checker3: word 3 of `val'
- local nummoda=r(r)
- local nbmoda_`j'=`nummoda'
- if (`nummoda'==2) {
- qui recode item`j' (`checker'=0) (`checker2'=1)
- }
- if (`nummoda'==3) {
- if (`checker'!=0) {
- qui recode item`j' (`checker'=0) (`checker2'=1) (`checker3'=2)
- }
- else if (`checker2'!=1) {
- qui recode item`j' (`checker2'=1) (`checker3'=2)
- }
- else if (`checker3'!=2) {
- qui recode item`j' (`checker3'=2)
- }
- }
- }
-
- qui valuesof comz
- local val = r(values)
- local checker: word 1 of `val'
- }
- else {
- forvalues jj=1/`nbitems' {
- local nbmoda_`jj'=`nbmoda'
- }
- }
-
-
- * ROSALI
- qui rosali_original item1-item`nbitems' item1-item`nbitems', group(tt)
- qui mat resmat=r(difitems)
- local nbitems2 = 2*`nbitems'
-
- * Calculer le nbre d'items détectés
- local nbdetect = 0
- local stop = 0
- forvalues jj=1/`nbitems' {
- if (`stop'==0) {
- mat testm=J(1,1,.)
- if (resmat[1,`jj']==testm[1,1]) {
- local stop = 1
- local nbdetect = `jj'-1
- }
- }
- }
-
- * Stocker les items détectés +
- * Définition des contraintes
- local csrt=0
- mat testm=J(1,1,0)
- forvalues u=1/`nbdetect' {
- local difitems`u'=resmat[1,`u']
- local i=`difitems`u''
- if (`nbmoda_`i''==3 & resmat[1,`nbitems'+`i']!=testm[1,1]){
- local constrnt`u' = "constraint `u' 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))"
- qui `constrnt`u''
- local v=`u'+100
- local constrnt`u'_2 = "constraint `v' 3*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([3.item`i']_cons-([3.item`i']_cons+[3.item`i'] tt))"
- qui `constrnt`u'_2'
- }
- if (`nbmoda_`i''==2 & resmat[1,`nbitems'+`i']!=testm[1,1]){
- local constrnt`u' = "constraint `u' 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))"
- qui `constrnt`u''
- }
- }
-
- * Définition du modèle
- local mod "gsem "
- local conformula = ""
- forvalues i=1/`nbitems' {
- local mod = "`mod'"+"(1.item`i'<-THETA@1)"
- if (`nbmoda_`i''==3) {
- local mod = "`mod'"+"(2.item`i'<-THETA@2)(3.item`i'<-THETA@3)"
- }
- else if (`nbmoda_`i''==2) {
- local mod = "`mod'"+"(2.item`i'<-THETA@2)"
- }
- }
- forvalues u=1/`nbdetect' {
- local v=`difitems`u''
- local mod = "`mod'"+"(1.item`v'<-THETA@1 tt)"
- if (`nbmoda_`v''==3) {
- local mod = "`mod'"+"(2.item`v'<-THETA@2 tt)(3.item`v'<-THETA@3 tt)"
- }
- else if (`nbmoda_`v''==2) {
- local mod = "`mod'"+"(2.item`v'<-THETA@2 tt)"
- }
- local w= 100+`u'
- if (resmat[1,`nbitems'+`v']!=testm[1,1] & `nbmoda_`v''==3) {
- local conformula = "`conformula'" + "`u' " + "`w' "
- }
- else if (resmat[1,`nbitems'+`v']!=testm[1,1] & `nbmoda_`v''==2) {
- local conformula = "`conformula'" + "`u' "
- }
- }
- if ("`conformula'" != "") {
- local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent constraint(`conformula')"
- }
- else {
- local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent"
- }
- *calcul du modèle
- qui `mod'
- mat V=r(table)
- mat W=V[1..2,1...]
-
- * compilation
- forvalues j=1/`nbitems' {
- forvalues z=1/`nbmoda_`j'' {
- mat outmat[`k',colnumb(outmat,"item`j'_`z'")] = W[1,colnumb(W,"`z'.item`j':_cons")]
- }
- }
- * compilation DIF
- forvalues u=1/`nbdetect' {
- local j=`difitems`u''
- forvalues z=1/`nbmoda_`j'' {
- mat outmat[`k',colnumb(outmat,"dif_`u'_`z'")] = W[1,colnumb(W,"`z'.item`j':tt")]
- mat outmat[`k',colnumb(outmat,"dif_detect_`u'")] = `j'
- }
- }
-
- * Stocker les items de DIF originaux
- if (`nbdif' > 0) {
- qui levelsof dif1
- local ldif1 = r(levels)
- local diff1: word 1 of `ldif1'
- qui mat outmat[`k',colnumb(outmat,"real_dif_1")]=`diff1'
- if (`nbdif' > 1) {
- qui levelsof dif2
- local ldif2 = r(levels)
- local diff2: word 1 of `ldif2'
- qui mat outmat[`k',colnumb(outmat,"real_dif_2")]=`diff2'
- if (`nbdif' > 2) {
- qui levelsof dif3
- local ldif3 = r(levels)
- local diff3: word 1 of `ldif3'
- qui mat outmat[`k',colnumb(outmat,"real_dif_3")]=`diff3'
- }
- }
- }
- qui mat outmat[`k',colnumb(outmat,"beta")]=W[1,colnumb(W,"THETA:tt")]
- qui mat outmat[`k',colnumb(outmat,"se_beta")]=W[2,colnumb(W,"THETA:tt")]
- restore
- }
- putexcel set "`path_res'/`s'`scen'_`Nn'_original.xls", sheet("outmat") replace
- putexcel A1=matrix(outmat), colnames
-}
-}
-}
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
deleted file mode 100644
index 203ad44..0000000
--- a/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S18.do
+++ /dev/null
@@ -1,378 +0,0 @@
-*=================================================================================================================================================
-* Date : 2024-01-23
-* Stata version : Stata 18 SE
-*
-* This program analyses simulated data accounting for DIF through a partial credit model
-*
-* ado-files needed : - pcm, rosali (version 5.5 October 25, 2023, available on gitea)
-*
-*
-*================================================================================================================================================
-adopath+"/home/corentin/Documents/These/Recherche/ROSALI-SIM/Modules/rosali_custom"
-
-
-local N = "50 100 200 300"
- local ss = "18"
- foreach s in `ss' {
- foreach Nnn in `N' {
- local Nn = `Nnn'
- local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N`Nn'"
- if (`s'<=4) {
- local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N`Nn'"
- }
- local path_res = "/home/corentin/Documents/These/Recherche/Simulations/Analysis/ROSALI-DIF/N`Nn'"
- local scenarios = "A B C D E F G"
- foreach scen in `scenarios' {
- clear
- import delim "`path_data'/scenario_`s'`scen'_`Nn'.csv", encoding(ISO-8859-2) case(preserve) clear
- rename TT tt
-
- if (`s'<=2) {
- local nbitems=4
- }
- else if (`s'<=4) {
- local nbitems=7
- }
- else if (`s'<=12) {
- local nbitems=4
- }
- else {
- local nbitems=7
- }
-
- if (mod(`s',2)==0) {
- local nbmoda=3
- }
- else {
- local nbmoda=1
- }
-
- if (`s'<=4) {
- local nbdif=0
- }
- else if (`s'<=8) {
- local nbdif=1
- }
- else if (`s'<=16) {
- local nbdif=2
- }
- else {
- local nbdif=3
- }
- * taillemat = Maximum J*M cases pour les items par et J*M cases pour les dif par + J cases pour les DIF detect + nbdif cases pour dif réel
- local taillemat=2*`nbitems'*`nbmoda'+`nbitems'+`nbdif'+2
- 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'
- }
- }
-
-
- * ROSALI
- qui rosali_original item1-item`nbitems' item1-item`nbitems', group(tt)
- qui mat resmat=r(difitems)
- local nbitems2 = 2*`nbitems'
-
- * Calculer le nbre d'items détectés
- local nbdetect = 0
- local stop = 0
- forvalues jj=1/`nbitems' {
- if (`stop'==0) {
- mat testm=J(1,1,.)
- if (resmat[1,`jj']==testm[1,1]) {
- local stop = 1
- local nbdetect = `jj'-1
- }
- }
- }
-
- * Stocker les items détectés +
- * Définition des contraintes
- local csrt=0
- mat testm=J(1,1,0)
- forvalues u=1/`nbdetect' {
- local difitems`u'=resmat[1,`u']
- local i=`difitems`u''
- if (`nbmoda_`i''==3 & resmat[1,`nbitems'+`i']!=testm[1,1]){
- local constrnt`u' = "constraint `u' 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))"
- qui `constrnt`u''
- local v=`u'+100
- local constrnt`u'_2 = "constraint `v' 3*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([3.item`i']_cons-([3.item`i']_cons+[3.item`i'] tt))"
- qui `constrnt`u'_2'
- }
- if (`nbmoda_`i''==2 & resmat[1,`nbitems'+`i']!=testm[1,1]){
- local constrnt`u' = "constraint `u' 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))"
- qui `constrnt`u''
- }
- }
-
- * Définition du modèle
- local mod "gsem "
- local conformula = ""
- forvalues i=1/`nbitems' {
- local mod = "`mod'"+"(1.item`i'<-THETA@1)"
- if (`nbmoda_`i''==3) {
- local mod = "`mod'"+"(2.item`i'<-THETA@2)(3.item`i'<-THETA@3)"
- }
- else if (`nbmoda_`i''==2) {
- local mod = "`mod'"+"(2.item`i'<-THETA@2)"
- }
- }
- forvalues u=1/`nbdetect' {
- local v=`difitems`u''
- local mod = "`mod'"+"(1.item`v'<-THETA@1 tt)"
- if (`nbmoda_`v''==3) {
- local mod = "`mod'"+"(2.item`v'<-THETA@2 tt)(3.item`v'<-THETA@3 tt)"
- }
- else if (`nbmoda_`v''==2) {
- local mod = "`mod'"+"(2.item`v'<-THETA@2 tt)"
- }
- local w= 100+`u'
- 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'
- 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
- }
- }
- }
diff --git a/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S19.do b/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S19.do
deleted file mode 100644
index a58cb17..0000000
--- a/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S19.do
+++ /dev/null
@@ -1,364 +0,0 @@
-*=================================================================================================================================================
-* Date : 2024-01-23
-* Stata version : Stata 18 SE
-*
-* This program analyses simulated data accounting for DIF through a partial credit model
-*
-* ado-files needed : - pcm, rosali (version 5.5 October 25, 2023, available on gitea)
-*
-*
-*================================================================================================================================================
-adopath+"/home/corentin/Documents/These/Recherche/ROSALI-SIM/Modules/rosali_custom"
-
-
-local N = "50 100 200 300"
- local ss = "19"
- foreach s in `ss' {
- foreach Nnn in `N' {
- local Nn = `Nnn'
- local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N`Nn'"
- if (`s'<=4) {
- local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N`Nn'"
- }
- local path_res = "/home/corentin/Documents/These/Recherche/Simulations/Analysis/ROSALI-DIF/N`Nn'"
- local scenarios = "A B C D E F G"
- foreach scen in `scenarios' {
- clear
- import delim "`path_data'/scenario_`s'`scen'_`Nn'.csv", encoding(ISO-8859-2) case(preserve) clear
- rename TT tt
-
- if (`s'<=2) {
- local nbitems=4
- }
- else if (`s'<=4) {
- local nbitems=7
- }
- else if (`s'<=12) {
- local nbitems=4
- }
- else {
- local nbitems=7
- }
-
-if (mod(`s',2)==0) {
- local nbmoda=3
-}
-else {
- local nbmoda=1
-}
-
- if (`s'<=4) {
- local nbdif=0
- }
- else if (`s'<=8) {
- local nbdif=1
- }
- else if (`s'<=16) {
- local nbdif=2
- }
- else {
- local nbdif=3
- }
- * taillemat = Maximum J*M cases pour les items par et J*M cases pour les dif par + J cases pour les DIF detect + nbdif cases pour dif réel
- local taillemat=2*`nbitems'*`nbmoda'+`nbitems'+`nbdif'+2
- local colna=""
- forvalues i=1/`nbitems' {
- forvalues z=1/`nbmoda' {
- local colna = "`colna'"+"item`i'_`z' "
- local colna = "`colna'"+"dif_`i'_`z' "
- }
- }
- forvalues i=1/`nbitems' {
- local colna = "`colna'"+"dif_detect_`i' "
- }
-
- forvalues i=1/`nbdif' {
- local colna = "`colna'"+"real_dif_`i' "
- }
-local colna = "`colna'" + "beta " + "se_beta"
-
-
- mat outmat = J(1000,`taillemat',.)
- mat colnames outmat= `colna'
- di "Scenario `s'`scen' / N=`Nnn'"
- forvalues k=1/1000 {
- if (mod(`k',100)==0) {
- di "`k'/1000"
- }
- preserve
- qui keep if replication==`k'
-
-
- * MERGE des modalités si non représentées
-
- if (`nbmoda'>1 & `Nn'==50) {
- local com_z = 0
- qui gen comz = 0
- forvalues j = 1 / `nbitems' {
- local recoda_`j' = 0
- qui tab item`j' if tt == 0, matrow(rect1_g0_`j') matcell(nbrt1_g0_`j')
- local maxm`j'_t1_g0 = rect1_g0_`j'[r(r),1]
- local minm`j'_t1_g0 = rect1_g0_`j'[1,1]
-
- qui tab item`j' if tt == 1, matrow(rect1_g1_`j') matcell(nbrt1_g1_`j')
- local minm`j'_t1_g1 = rect1_g1_`j'[1,1]
- local maxm`j'_t1_g1 = rect1_g1_`j'[r(r),1]
-
- local minm_`j' = min(`minm`j'_t1_g0',`minm`j'_t1_g1')
- local maxm_`j' = max(`maxm`j'_t1_g0',`maxm`j'_t1_g1')
- local nbm_`j' = `=`maxm_`j''-`minm_`j'''
-
- if `minm_`j'' != 0 & `com_z' == 0 {
- local com_z = 1
- }
-
- qui count if item`j' == 3 & tt == 0
- local mod3plac = r(N)
- qui count if item`j' == 3 & tt == 1
- local mod3tt = r(N)
- local nb_rn3 = min(`mod3plac',`mod3tt')
- if `nb_rn3'==0 {
- qui replace comz = 1
- }
-
- forvalues m = 0/`=`nbm_`j''-1' {
- qui count if item`j' == `m' & tt == 0
- local nb_rn1_g0 = r(N)
- qui count if item`j' == `m' & tt == 1
- local nb_rn1_g1 = r(N)
- local nb_rn = min(`nb_rn1_g0',`nb_rn1_g1')
- if `nb_rn' == 0 {
- qui replace comz = 1
- local recoda_`j' = 1
- if `m' == 0 | `m' < `minm`j'_t1_g0' | `m' < `minm`j'_t1_g1' {
- local stop = 1
- forvalues kk = 1/`=`nbm_`j''-`m'' {
- qui count if item`j' == `=`m' + `kk'' & tt == 0
- local v`kk'1_0 = r(N)
- qui count if item`j' == `=`m' + `kk'' & tt == 1
- local v`kk'1_1 = r(N)
- if (`v`kk'1_0' != 0 | `v`kk'1_1' != 0) & `stop' != 0 {
- qui replace item`j'= `=`m'+`kk'' if item`j'==`m'
- local zzz=`j'+`nbitems'
- *qui replace item`zzz'=`=`m'+`kk'' if item``=`j'+`nbitems'''==`m'
- *di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
- local stop = 0
- }
- }
- }
- else if `m' == `=`nbm_`j''-1' | `m' >= `maxm`j'_t1_g1' {
- local stop = 1
- forvalues kk = 1/`=`m'' {
- qui count if item`j' == `=`m' - `kk'' & tt == 0
- local v`kk'1_0 = r(N)
- qui count if item`j' == `=`m' - `kk'' & tt == 1
- local v`kk'1_1 = r(N)
- if (`v`kk'1_0' != 0 | `v`kk'1_1' != 0) & `stop' != 0 {
- qui replace item`j'= `=`m' - `kk'' if item`j'==`m'
- local zzz=`j'+`nbitems'
- *qui replace item`zzz'= `=`m' - `kk'' if item`zzz'==`m'
- *di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
- local stop = 0
- }
- }
- }
- else {
- if runiform()>0.5{
- local stop = 1
- forvalues kk = 1/`m' {
- qui count if item`j' == `=`m' - `kk'' & tt == 0
- local v`kk'1_0 = r(N)
- qui count if item`j' == `=`m' - `kk'' & tt == 1
- local v`kk'1_1 = r(N)
- if (`v`kk'1_0' != 0 | `v`kk'1_1' != 0) & `stop' != 0 {
- qui replace item`j'= `=`m'-`kk'' if item`j'==`m'
- local zzz=`j'+`nbitems'
- *qui replace item`zzz'=`=`m'-`kk'' if item``=`j'+`nbitems'''==`m'
- *di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
- local stop = 0
- }
- }
- }
- else {
- local stop = 1
- forvalues kk = 1/`=`nbm_`j''-`m'' {
- qui count if item`j' == `=`m' + `kk'' & tt == 0
- local v`kk'1_0 = r(N)
- qui count if item`j' == `=`m' + `kk'' & tt == 1
- local v`kk'1_1 = r(N)
- if (`v`kk'1_0' != 0 | `v`kk'1_1' != 0) & `stop' != 0{
- qui replace item`j'=`=`m' + `kk'' if item`j'==`m'
- local zzz=`j'+`nbitems'
- *qui replace item`zzz'=`=`m' + `kk'' if item``=`j'+`nbitems'''==`m'
- *di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
- local stop = 0
- }
- else {
- if `stop' != 0 {
- qui replace item`j'= `nbm_`j'' if item`j'==`m'
- local zzz=`j'+`nbitems'
- *qui replace item`zzz'= `nbm_`j'' if item``=`j'+`nbitems'''==`m'
- *di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
- local stop = 0
- }
- }
- }
- }
- }
- }
- }
- qui levelsof item`j'
- local val = r(levels)
- local checker: word 1 of `val'
- local checker2: word 2 of `val'
- local checker3: word 3 of `val'
- local nummoda=r(r)
- local nbmoda_`j'=`nummoda'
- if (`nummoda'==2) {
- qui recode item`j' (`checker'=0) (`checker2'=1)
- }
- if (`nummoda'==3) {
- if (`checker'!=0) {
- qui recode item`j' (`checker'=0) (`checker2'=1) (`checker3'=2)
- }
- else if (`checker2'!=1) {
- qui recode item`j' (`checker2'=1) (`checker3'=2)
- }
- else if (`checker3'!=2) {
- qui recode item`j' (`checker3'=2)
- }
- }
- }
-
- qui valuesof comz
- local val = r(values)
- local checker: word 1 of `val'
- }
- else {
- forvalues jj=1/`nbitems' {
- local nbmoda_`jj'=`nbmoda'
- }
- }
-
-
- * ROSALI
- qui rosali_original item1-item`nbitems' item1-item`nbitems', group(tt)
- qui mat resmat=r(difitems)
- local nbitems2 = 2*`nbitems'
-
- * Calculer le nbre d'items détectés
- local nbdetect = 0
- local stop = 0
- forvalues jj=1/`nbitems' {
- if (`stop'==0) {
- mat testm=J(1,1,.)
- if (resmat[1,`jj']==testm[1,1]) {
- local stop = 1
- local nbdetect = `jj'-1
- }
- }
- }
-
- * Stocker les items détectés +
- * Définition des contraintes
- local csrt=0
- mat testm=J(1,1,0)
- forvalues u=1/`nbdetect' {
- local difitems`u'=resmat[1,`u']
- local i=`difitems`u''
- if (`nbmoda_`i''==3 & resmat[1,`nbitems'+`i']!=testm[1,1]){
- local constrnt`u' = "constraint `u' 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))"
- qui `constrnt`u''
- local v=`u'+100
- local constrnt`u'_2 = "constraint `v' 3*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([3.item`i']_cons-([3.item`i']_cons+[3.item`i'] tt))"
- qui `constrnt`u'_2'
- }
- if (`nbmoda_`i''==2 & resmat[1,`nbitems'+`i']!=testm[1,1]){
- local constrnt`u' = "constraint `u' 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))"
- qui `constrnt`u''
- }
- }
-
- * Définition du modèle
- local mod "gsem "
- local conformula = ""
- forvalues i=1/`nbitems' {
- local mod = "`mod'"+"(1.item`i'<-THETA@1)"
- if (`nbmoda_`i''==3) {
- local mod = "`mod'"+"(2.item`i'<-THETA@2)(3.item`i'<-THETA@3)"
- }
- else if (`nbmoda_`i''==2) {
- local mod = "`mod'"+"(2.item`i'<-THETA@2)"
- }
- }
- forvalues u=1/`nbdetect' {
- local v=`difitems`u''
- local mod = "`mod'"+"(1.item`v'<-THETA@1 tt)"
- if (`nbmoda_`v''==3) {
- local mod = "`mod'"+"(2.item`v'<-THETA@2 tt)(3.item`v'<-THETA@3 tt)"
- }
- else if (`nbmoda_`v''==2) {
- local mod = "`mod'"+"(2.item`v'<-THETA@2 tt)"
- }
- local w= 100+`u'
- if (resmat[1,`nbitems'+`v']!=testm[1,1] & `nbmoda_`v''==3) {
- local conformula = "`conformula'" + "`u' " + "`w' "
- }
- else if (resmat[1,`nbitems'+`v']!=testm[1,1] & `nbmoda_`v''==2) {
- local conformula = "`conformula'" + "`u' "
- }
- }
- if ("`conformula'" != "") {
- local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent constraint(`conformula')"
- }
- else {
- local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent"
- }
- *calcul du modèle
- qui `mod'
- mat V=r(table)
- mat W=V[1..2,1...]
-
- * compilation
- forvalues j=1/`nbitems' {
- forvalues z=1/`nbmoda_`j'' {
- mat outmat[`k',colnumb(outmat,"item`j'_`z'")] = W[1,colnumb(W,"`z'.item`j':_cons")]
- }
- }
- * compilation DIF
- forvalues u=1/`nbdetect' {
- local j=`difitems`u''
- forvalues z=1/`nbmoda_`j'' {
- mat outmat[`k',colnumb(outmat,"dif_`u'_`z'")] = W[1,colnumb(W,"`z'.item`j':tt")]
- mat outmat[`k',colnumb(outmat,"dif_detect_`u'")] = `j'
- }
- }
-
- * Stocker les items de DIF originaux
- if (`nbdif' > 0) {
- qui levelsof dif1
- local ldif1 = r(levels)
- local diff1: word 1 of `ldif1'
- qui mat outmat[`k',colnumb(outmat,"real_dif_1")]=`diff1'
- if (`nbdif' > 1) {
- qui levelsof dif2
- local ldif2 = r(levels)
- local diff2: word 1 of `ldif2'
- qui mat outmat[`k',colnumb(outmat,"real_dif_2")]=`diff2'
- if (`nbdif' > 2) {
- qui levelsof dif3
- local ldif3 = r(levels)
- local diff3: word 1 of `ldif3'
- qui mat outmat[`k',colnumb(outmat,"real_dif_3")]=`diff3'
- }
- }
- }
- qui mat outmat[`k',colnumb(outmat,"beta")]=W[1,colnumb(W,"THETA:tt")]
- qui mat outmat[`k',colnumb(outmat,"se_beta")]=W[2,colnumb(W,"THETA:tt")]
- restore
- }
- putexcel set "`path_res'/`s'`scen'_`Nn'_original.xls", sheet("outmat") replace
- putexcel A1=matrix(outmat), colnames
-}
-}
-}
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
deleted file mode 100644
index af802d4..0000000
--- a/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S2.do
+++ /dev/null
@@ -1,378 +0,0 @@
-*=================================================================================================================================================
-* Date : 2024-01-23
-* Stata version : Stata 18 SE
-*
-* This program analyses simulated data accounting for DIF through a partial credit model
-*
-* ado-files needed : - pcm, rosali (version 5.5 October 25, 2023, available on gitea)
-*
-*
-*================================================================================================================================================
-adopath+"/home/corentin/Documents/These/Recherche/ROSALI-SIM/Modules/rosali_custom"
-
-
-local N = "50 100 200 300"
- local ss = "2"
- foreach s in `ss' {
- foreach Nnn in `N' {
- local Nn = `Nnn'
- local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N`Nn'"
- if (`s'<=4) {
- local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N`Nn'"
- }
- local path_res = "/home/corentin/Documents/These/Recherche/Simulations/Analysis/ROSALI-DIF/N`Nn'"
- local scenarios = "A B C D E F G"
- foreach scen in `scenarios' {
- clear
- import delim "`path_data'/scenario_`s'`scen'_`Nn'.csv", encoding(ISO-8859-2) case(preserve) clear
- rename TT tt
-
- if (`s'<=2) {
- local nbitems=4
- }
- else if (`s'<=4) {
- local nbitems=7
- }
- else if (`s'<=12) {
- local nbitems=4
- }
- else {
- local nbitems=7
- }
-
- if (mod(`s',2)==0) {
- local nbmoda=3
- }
- else {
- local nbmoda=1
- }
-
- if (`s'<=4) {
- local nbdif=0
- }
- else if (`s'<=8) {
- local nbdif=1
- }
- else if (`s'<=16) {
- local nbdif=2
- }
- else {
- local nbdif=3
- }
- * taillemat = Maximum J*M cases pour les items par et J*M cases pour les dif par + J cases pour les DIF detect + nbdif cases pour dif réel
- local taillemat=2*`nbitems'*`nbmoda'+`nbitems'+`nbdif'+2
- 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'
- }
- }
-
-
- * ROSALI
- qui rosali_original item1-item`nbitems' item1-item`nbitems', group(tt)
- qui mat resmat=r(difitems)
- local nbitems2 = 2*`nbitems'
-
- * Calculer le nbre d'items détectés
- local nbdetect = 0
- local stop = 0
- forvalues jj=1/`nbitems' {
- if (`stop'==0) {
- mat testm=J(1,1,.)
- if (resmat[1,`jj']==testm[1,1]) {
- local stop = 1
- local nbdetect = `jj'-1
- }
- }
- }
-
- * Stocker les items détectés +
- * Définition des contraintes
- local csrt=0
- mat testm=J(1,1,0)
- forvalues u=1/`nbdetect' {
- local difitems`u'=resmat[1,`u']
- local i=`difitems`u''
- if (`nbmoda_`i''==3 & resmat[1,`nbitems'+`i']!=testm[1,1]){
- local constrnt`u' = "constraint `u' 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))"
- qui `constrnt`u''
- local v=`u'+100
- local constrnt`u'_2 = "constraint `v' 3*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([3.item`i']_cons-([3.item`i']_cons+[3.item`i'] tt))"
- qui `constrnt`u'_2'
- }
- if (`nbmoda_`i''==2 & resmat[1,`nbitems'+`i']!=testm[1,1]){
- local constrnt`u' = "constraint `u' 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))"
- qui `constrnt`u''
- }
- }
-
- * Définition du modèle
- local mod "gsem "
- local conformula = ""
- forvalues i=1/`nbitems' {
- local mod = "`mod'"+"(1.item`i'<-THETA@1)"
- if (`nbmoda_`i''==3) {
- local mod = "`mod'"+"(2.item`i'<-THETA@2)(3.item`i'<-THETA@3)"
- }
- else if (`nbmoda_`i''==2) {
- local mod = "`mod'"+"(2.item`i'<-THETA@2)"
- }
- }
- forvalues u=1/`nbdetect' {
- local v=`difitems`u''
- local mod = "`mod'"+"(1.item`v'<-THETA@1 tt)"
- if (`nbmoda_`v''==3) {
- local mod = "`mod'"+"(2.item`v'<-THETA@2 tt)(3.item`v'<-THETA@3 tt)"
- }
- else if (`nbmoda_`v''==2) {
- local mod = "`mod'"+"(2.item`v'<-THETA@2 tt)"
- }
- local w= 100+`u'
- 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'
- 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
- }
- }
- }
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
deleted file mode 100644
index a32c0c6..0000000
--- a/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S20.do
+++ /dev/null
@@ -1,378 +0,0 @@
-*=================================================================================================================================================
-* Date : 2024-01-23
-* Stata version : Stata 18 SE
-*
-* This program analyses simulated data accounting for DIF through a partial credit model
-*
-* ado-files needed : - pcm, rosali (version 5.5 October 25, 2023, available on gitea)
-*
-*
-*================================================================================================================================================
-adopath+"/home/corentin/Documents/These/Recherche/ROSALI-SIM/Modules/rosali_custom"
-
-
-local N = "50 100 200 300"
- local ss = "20"
- foreach s in `ss' {
- foreach Nnn in `N' {
- local Nn = `Nnn'
- local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N`Nn'"
- if (`s'<=4) {
- local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N`Nn'"
- }
- local path_res = "/home/corentin/Documents/These/Recherche/Simulations/Analysis/ROSALI-DIF/N`Nn'"
- local scenarios = "A B C D E F G"
- foreach scen in `scenarios' {
- clear
- import delim "`path_data'/scenario_`s'`scen'_`Nn'.csv", encoding(ISO-8859-2) case(preserve) clear
- rename TT tt
-
- if (`s'<=2) {
- local nbitems=4
- }
- else if (`s'<=4) {
- local nbitems=7
- }
- else if (`s'<=12) {
- local nbitems=4
- }
- else {
- local nbitems=7
- }
-
- if (mod(`s',2)==0) {
- local nbmoda=3
- }
- else {
- local nbmoda=1
- }
-
- if (`s'<=4) {
- local nbdif=0
- }
- else if (`s'<=8) {
- local nbdif=1
- }
- else if (`s'<=16) {
- local nbdif=2
- }
- else {
- local nbdif=3
- }
- * taillemat = Maximum J*M cases pour les items par et J*M cases pour les dif par + J cases pour les DIF detect + nbdif cases pour dif réel
- local taillemat=2*`nbitems'*`nbmoda'+`nbitems'+`nbdif'+2
- 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'
- }
- }
-
-
- * ROSALI
- qui rosali_original item1-item`nbitems' item1-item`nbitems', group(tt)
- qui mat resmat=r(difitems)
- local nbitems2 = 2*`nbitems'
-
- * Calculer le nbre d'items détectés
- local nbdetect = 0
- local stop = 0
- forvalues jj=1/`nbitems' {
- if (`stop'==0) {
- mat testm=J(1,1,.)
- if (resmat[1,`jj']==testm[1,1]) {
- local stop = 1
- local nbdetect = `jj'-1
- }
- }
- }
-
- * Stocker les items détectés +
- * Définition des contraintes
- local csrt=0
- mat testm=J(1,1,0)
- forvalues u=1/`nbdetect' {
- local difitems`u'=resmat[1,`u']
- local i=`difitems`u''
- if (`nbmoda_`i''==3 & resmat[1,`nbitems'+`i']!=testm[1,1]){
- local constrnt`u' = "constraint `u' 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))"
- qui `constrnt`u''
- local v=`u'+100
- local constrnt`u'_2 = "constraint `v' 3*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([3.item`i']_cons-([3.item`i']_cons+[3.item`i'] tt))"
- qui `constrnt`u'_2'
- }
- if (`nbmoda_`i''==2 & resmat[1,`nbitems'+`i']!=testm[1,1]){
- local constrnt`u' = "constraint `u' 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))"
- qui `constrnt`u''
- }
- }
-
- * Définition du modèle
- local mod "gsem "
- local conformula = ""
- forvalues i=1/`nbitems' {
- local mod = "`mod'"+"(1.item`i'<-THETA@1)"
- if (`nbmoda_`i''==3) {
- local mod = "`mod'"+"(2.item`i'<-THETA@2)(3.item`i'<-THETA@3)"
- }
- else if (`nbmoda_`i''==2) {
- local mod = "`mod'"+"(2.item`i'<-THETA@2)"
- }
- }
- forvalues u=1/`nbdetect' {
- local v=`difitems`u''
- local mod = "`mod'"+"(1.item`v'<-THETA@1 tt)"
- if (`nbmoda_`v''==3) {
- local mod = "`mod'"+"(2.item`v'<-THETA@2 tt)(3.item`v'<-THETA@3 tt)"
- }
- else if (`nbmoda_`v''==2) {
- local mod = "`mod'"+"(2.item`v'<-THETA@2 tt)"
- }
- local w= 100+`u'
- 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'
- 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
- }
- }
- }
diff --git a/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S3.do b/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S3.do
deleted file mode 100644
index 6b353a7..0000000
--- a/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S3.do
+++ /dev/null
@@ -1,364 +0,0 @@
-*=================================================================================================================================================
-* Date : 2024-01-23
-* Stata version : Stata 18 SE
-*
-* This program analyses simulated data accounting for DIF through a partial credit model
-*
-* ado-files needed : - pcm, rosali (version 5.5 October 25, 2023, available on gitea)
-*
-*
-*================================================================================================================================================
-adopath+"/home/corentin/Documents/These/Recherche/ROSALI-SIM/Modules/rosali_custom"
-
-
-local N = "50 100 200 300"
- local ss = "3"
- foreach s in `ss' {
- foreach Nnn in `N' {
- local Nn = `Nnn'
- local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N`Nn'"
- if (`s'<=4) {
- local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N`Nn'"
- }
- local path_res = "/home/corentin/Documents/These/Recherche/Simulations/Analysis/ROSALI-DIF/N`Nn'"
- local scenarios = "A B C D E F G"
- foreach scen in `scenarios' {
- clear
- import delim "`path_data'/scenario_`s'`scen'_`Nn'.csv", encoding(ISO-8859-2) case(preserve) clear
- rename TT tt
-
- if (`s'<=2) {
- local nbitems=4
- }
- else if (`s'<=4) {
- local nbitems=7
- }
- else if (`s'<=12) {
- local nbitems=4
- }
- else {
- local nbitems=7
- }
-
-if (mod(`s',2)==0) {
- local nbmoda=3
-}
-else {
- local nbmoda=1
-}
-
- if (`s'<=4) {
- local nbdif=0
- }
- else if (`s'<=8) {
- local nbdif=1
- }
- else if (`s'<=16) {
- local nbdif=2
- }
- else {
- local nbdif=3
- }
- * taillemat = Maximum J*M cases pour les items par et J*M cases pour les dif par + J cases pour les DIF detect + nbdif cases pour dif réel
- local taillemat=2*`nbitems'*`nbmoda'+`nbitems'+`nbdif'+2
- local colna=""
- forvalues i=1/`nbitems' {
- forvalues z=1/`nbmoda' {
- local colna = "`colna'"+"item`i'_`z' "
- local colna = "`colna'"+"dif_`i'_`z' "
- }
- }
- forvalues i=1/`nbitems' {
- local colna = "`colna'"+"dif_detect_`i' "
- }
-
- forvalues i=1/`nbdif' {
- local colna = "`colna'"+"real_dif_`i' "
- }
-local colna = "`colna'" + "beta " + "se_beta"
-
-
- mat outmat = J(1000,`taillemat',.)
- mat colnames outmat= `colna'
- di "Scenario `s'`scen' / N=`Nnn'"
- forvalues k=1/1000 {
- if (mod(`k',100)==0) {
- di "`k'/1000"
- }
- preserve
- qui keep if replication==`k'
-
-
- * MERGE des modalités si non représentées
-
- if (`nbmoda'>1 & `Nn'==50) {
- local com_z = 0
- qui gen comz = 0
- forvalues j = 1 / `nbitems' {
- local recoda_`j' = 0
- qui tab item`j' if tt == 0, matrow(rect1_g0_`j') matcell(nbrt1_g0_`j')
- local maxm`j'_t1_g0 = rect1_g0_`j'[r(r),1]
- local minm`j'_t1_g0 = rect1_g0_`j'[1,1]
-
- qui tab item`j' if tt == 1, matrow(rect1_g1_`j') matcell(nbrt1_g1_`j')
- local minm`j'_t1_g1 = rect1_g1_`j'[1,1]
- local maxm`j'_t1_g1 = rect1_g1_`j'[r(r),1]
-
- local minm_`j' = min(`minm`j'_t1_g0',`minm`j'_t1_g1')
- local maxm_`j' = max(`maxm`j'_t1_g0',`maxm`j'_t1_g1')
- local nbm_`j' = `=`maxm_`j''-`minm_`j'''
-
- if `minm_`j'' != 0 & `com_z' == 0 {
- local com_z = 1
- }
-
- qui count if item`j' == 3 & tt == 0
- local mod3plac = r(N)
- qui count if item`j' == 3 & tt == 1
- local mod3tt = r(N)
- local nb_rn3 = min(`mod3plac',`mod3tt')
- if `nb_rn3'==0 {
- qui replace comz = 1
- }
-
- forvalues m = 0/`=`nbm_`j''-1' {
- qui count if item`j' == `m' & tt == 0
- local nb_rn1_g0 = r(N)
- qui count if item`j' == `m' & tt == 1
- local nb_rn1_g1 = r(N)
- local nb_rn = min(`nb_rn1_g0',`nb_rn1_g1')
- if `nb_rn' == 0 {
- qui replace comz = 1
- local recoda_`j' = 1
- if `m' == 0 | `m' < `minm`j'_t1_g0' | `m' < `minm`j'_t1_g1' {
- local stop = 1
- forvalues kk = 1/`=`nbm_`j''-`m'' {
- qui count if item`j' == `=`m' + `kk'' & tt == 0
- local v`kk'1_0 = r(N)
- qui count if item`j' == `=`m' + `kk'' & tt == 1
- local v`kk'1_1 = r(N)
- if (`v`kk'1_0' != 0 | `v`kk'1_1' != 0) & `stop' != 0 {
- qui replace item`j'= `=`m'+`kk'' if item`j'==`m'
- local zzz=`j'+`nbitems'
- *qui replace item`zzz'=`=`m'+`kk'' if item``=`j'+`nbitems'''==`m'
- *di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
- local stop = 0
- }
- }
- }
- else if `m' == `=`nbm_`j''-1' | `m' >= `maxm`j'_t1_g1' {
- local stop = 1
- forvalues kk = 1/`=`m'' {
- qui count if item`j' == `=`m' - `kk'' & tt == 0
- local v`kk'1_0 = r(N)
- qui count if item`j' == `=`m' - `kk'' & tt == 1
- local v`kk'1_1 = r(N)
- if (`v`kk'1_0' != 0 | `v`kk'1_1' != 0) & `stop' != 0 {
- qui replace item`j'= `=`m' - `kk'' if item`j'==`m'
- local zzz=`j'+`nbitems'
- *qui replace item`zzz'= `=`m' - `kk'' if item`zzz'==`m'
- *di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
- local stop = 0
- }
- }
- }
- else {
- if runiform()>0.5{
- local stop = 1
- forvalues kk = 1/`m' {
- qui count if item`j' == `=`m' - `kk'' & tt == 0
- local v`kk'1_0 = r(N)
- qui count if item`j' == `=`m' - `kk'' & tt == 1
- local v`kk'1_1 = r(N)
- if (`v`kk'1_0' != 0 | `v`kk'1_1' != 0) & `stop' != 0 {
- qui replace item`j'= `=`m'-`kk'' if item`j'==`m'
- local zzz=`j'+`nbitems'
- *qui replace item`zzz'=`=`m'-`kk'' if item``=`j'+`nbitems'''==`m'
- *di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
- local stop = 0
- }
- }
- }
- else {
- local stop = 1
- forvalues kk = 1/`=`nbm_`j''-`m'' {
- qui count if item`j' == `=`m' + `kk'' & tt == 0
- local v`kk'1_0 = r(N)
- qui count if item`j' == `=`m' + `kk'' & tt == 1
- local v`kk'1_1 = r(N)
- if (`v`kk'1_0' != 0 | `v`kk'1_1' != 0) & `stop' != 0{
- qui replace item`j'=`=`m' + `kk'' if item`j'==`m'
- local zzz=`j'+`nbitems'
- *qui replace item`zzz'=`=`m' + `kk'' if item``=`j'+`nbitems'''==`m'
- *di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
- local stop = 0
- }
- else {
- if `stop' != 0 {
- qui replace item`j'= `nbm_`j'' if item`j'==`m'
- local zzz=`j'+`nbitems'
- *qui replace item`zzz'= `nbm_`j'' if item``=`j'+`nbitems'''==`m'
- *di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
- local stop = 0
- }
- }
- }
- }
- }
- }
- }
- qui levelsof item`j'
- local val = r(levels)
- local checker: word 1 of `val'
- local checker2: word 2 of `val'
- local checker3: word 3 of `val'
- local nummoda=r(r)
- local nbmoda_`j'=`nummoda'
- if (`nummoda'==2) {
- qui recode item`j' (`checker'=0) (`checker2'=1)
- }
- if (`nummoda'==3) {
- if (`checker'!=0) {
- qui recode item`j' (`checker'=0) (`checker2'=1) (`checker3'=2)
- }
- else if (`checker2'!=1) {
- qui recode item`j' (`checker2'=1) (`checker3'=2)
- }
- else if (`checker3'!=2) {
- qui recode item`j' (`checker3'=2)
- }
- }
- }
-
- qui valuesof comz
- local val = r(values)
- local checker: word 1 of `val'
- }
- else {
- forvalues jj=1/`nbitems' {
- local nbmoda_`jj'=`nbmoda'
- }
- }
-
-
- * ROSALI
- qui rosali_original item1-item`nbitems' item1-item`nbitems', group(tt)
- qui mat resmat=r(difitems)
- local nbitems2 = 2*`nbitems'
-
- * Calculer le nbre d'items détectés
- local nbdetect = 0
- local stop = 0
- forvalues jj=1/`nbitems' {
- if (`stop'==0) {
- mat testm=J(1,1,.)
- if (resmat[1,`jj']==testm[1,1]) {
- local stop = 1
- local nbdetect = `jj'-1
- }
- }
- }
-
- * Stocker les items détectés +
- * Définition des contraintes
- local csrt=0
- mat testm=J(1,1,0)
- forvalues u=1/`nbdetect' {
- local difitems`u'=resmat[1,`u']
- local i=`difitems`u''
- if (`nbmoda_`i''==3 & resmat[1,`nbitems'+`i']!=testm[1,1]){
- local constrnt`u' = "constraint `u' 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))"
- qui `constrnt`u''
- local v=`u'+100
- local constrnt`u'_2 = "constraint `v' 3*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([3.item`i']_cons-([3.item`i']_cons+[3.item`i'] tt))"
- qui `constrnt`u'_2'
- }
- if (`nbmoda_`i''==2 & resmat[1,`nbitems'+`i']!=testm[1,1]){
- local constrnt`u' = "constraint `u' 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))"
- qui `constrnt`u''
- }
- }
-
- * Définition du modèle
- local mod "gsem "
- local conformula = ""
- forvalues i=1/`nbitems' {
- local mod = "`mod'"+"(1.item`i'<-THETA@1)"
- if (`nbmoda_`i''==3) {
- local mod = "`mod'"+"(2.item`i'<-THETA@2)(3.item`i'<-THETA@3)"
- }
- else if (`nbmoda_`i''==2) {
- local mod = "`mod'"+"(2.item`i'<-THETA@2)"
- }
- }
- forvalues u=1/`nbdetect' {
- local v=`difitems`u''
- local mod = "`mod'"+"(1.item`v'<-THETA@1 tt)"
- if (`nbmoda_`v''==3) {
- local mod = "`mod'"+"(2.item`v'<-THETA@2 tt)(3.item`v'<-THETA@3 tt)"
- }
- else if (`nbmoda_`v''==2) {
- local mod = "`mod'"+"(2.item`v'<-THETA@2 tt)"
- }
- local w= 100+`u'
- if (resmat[1,`nbitems'+`v']!=testm[1,1] & `nbmoda_`v''==3) {
- local conformula = "`conformula'" + "`u' " + "`w' "
- }
- else if (resmat[1,`nbitems'+`v']!=testm[1,1] & `nbmoda_`v''==2) {
- local conformula = "`conformula'" + "`u' "
- }
- }
- if ("`conformula'" != "") {
- local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent constraint(`conformula')"
- }
- else {
- local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent"
- }
- *calcul du modèle
- qui `mod'
- mat V=r(table)
- mat W=V[1..2,1...]
-
- * compilation
- forvalues j=1/`nbitems' {
- forvalues z=1/`nbmoda_`j'' {
- mat outmat[`k',colnumb(outmat,"item`j'_`z'")] = W[1,colnumb(W,"`z'.item`j':_cons")]
- }
- }
- * compilation DIF
- forvalues u=1/`nbdetect' {
- local j=`difitems`u''
- forvalues z=1/`nbmoda_`j'' {
- mat outmat[`k',colnumb(outmat,"dif_`u'_`z'")] = W[1,colnumb(W,"`z'.item`j':tt")]
- mat outmat[`k',colnumb(outmat,"dif_detect_`u'")] = `j'
- }
- }
-
- * Stocker les items de DIF originaux
- if (`nbdif' > 0) {
- qui levelsof dif1
- local ldif1 = r(levels)
- local diff1: word 1 of `ldif1'
- qui mat outmat[`k',colnumb(outmat,"real_dif_1")]=`diff1'
- if (`nbdif' > 1) {
- qui levelsof dif2
- local ldif2 = r(levels)
- local diff2: word 1 of `ldif2'
- qui mat outmat[`k',colnumb(outmat,"real_dif_2")]=`diff2'
- if (`nbdif' > 2) {
- qui levelsof dif3
- local ldif3 = r(levels)
- local diff3: word 1 of `ldif3'
- qui mat outmat[`k',colnumb(outmat,"real_dif_3")]=`diff3'
- }
- }
- }
- qui mat outmat[`k',colnumb(outmat,"beta")]=W[1,colnumb(W,"THETA:tt")]
- qui mat outmat[`k',colnumb(outmat,"se_beta")]=W[2,colnumb(W,"THETA:tt")]
- restore
- }
- putexcel set "`path_res'/`s'`scen'_`Nn'_original.xls", sheet("outmat") replace
- putexcel A1=matrix(outmat), colnames
-}
-}
-}
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
deleted file mode 100644
index 76f75cd..0000000
--- a/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S4.do
+++ /dev/null
@@ -1,378 +0,0 @@
-*=================================================================================================================================================
-* Date : 2024-01-23
-* Stata version : Stata 18 SE
-*
-* This program analyses simulated data accounting for DIF through a partial credit model
-*
-* ado-files needed : - pcm, rosali (version 5.5 October 25, 2023, available on gitea)
-*
-*
-*================================================================================================================================================
-adopath+"/home/corentin/Documents/These/Recherche/ROSALI-SIM/Modules/rosali_custom"
-
-
-local N = "50 100 200 300"
- local ss = "4"
- foreach s in `ss' {
- foreach Nnn in `N' {
- local Nn = `Nnn'
- local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N`Nn'"
- if (`s'<=4) {
- local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N`Nn'"
- }
- local path_res = "/home/corentin/Documents/These/Recherche/Simulations/Analysis/ROSALI-DIF/N`Nn'"
- local scenarios = "A B C D E F G"
- foreach scen in `scenarios' {
- clear
- import delim "`path_data'/scenario_`s'`scen'_`Nn'.csv", encoding(ISO-8859-2) case(preserve) clear
- rename TT tt
-
- if (`s'<=2) {
- local nbitems=4
- }
- else if (`s'<=4) {
- local nbitems=7
- }
- else if (`s'<=12) {
- local nbitems=4
- }
- else {
- local nbitems=7
- }
-
- if (mod(`s',2)==0) {
- local nbmoda=3
- }
- else {
- local nbmoda=1
- }
-
- if (`s'<=4) {
- local nbdif=0
- }
- else if (`s'<=8) {
- local nbdif=1
- }
- else if (`s'<=16) {
- local nbdif=2
- }
- else {
- local nbdif=3
- }
- * taillemat = Maximum J*M cases pour les items par et J*M cases pour les dif par + J cases pour les DIF detect + nbdif cases pour dif réel
- local taillemat=2*`nbitems'*`nbmoda'+`nbitems'+`nbdif'+2
- 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'
- }
- }
-
-
- * ROSALI
- qui rosali_original item1-item`nbitems' item1-item`nbitems', group(tt)
- qui mat resmat=r(difitems)
- local nbitems2 = 2*`nbitems'
-
- * Calculer le nbre d'items détectés
- local nbdetect = 0
- local stop = 0
- forvalues jj=1/`nbitems' {
- if (`stop'==0) {
- mat testm=J(1,1,.)
- if (resmat[1,`jj']==testm[1,1]) {
- local stop = 1
- local nbdetect = `jj'-1
- }
- }
- }
-
- * Stocker les items détectés +
- * Définition des contraintes
- local csrt=0
- mat testm=J(1,1,0)
- forvalues u=1/`nbdetect' {
- local difitems`u'=resmat[1,`u']
- local i=`difitems`u''
- if (`nbmoda_`i''==3 & resmat[1,`nbitems'+`i']!=testm[1,1]){
- local constrnt`u' = "constraint `u' 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))"
- qui `constrnt`u''
- local v=`u'+100
- local constrnt`u'_2 = "constraint `v' 3*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([3.item`i']_cons-([3.item`i']_cons+[3.item`i'] tt))"
- qui `constrnt`u'_2'
- }
- if (`nbmoda_`i''==2 & resmat[1,`nbitems'+`i']!=testm[1,1]){
- local constrnt`u' = "constraint `u' 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))"
- qui `constrnt`u''
- }
- }
-
- * Définition du modèle
- local mod "gsem "
- local conformula = ""
- forvalues i=1/`nbitems' {
- local mod = "`mod'"+"(1.item`i'<-THETA@1)"
- if (`nbmoda_`i''==3) {
- local mod = "`mod'"+"(2.item`i'<-THETA@2)(3.item`i'<-THETA@3)"
- }
- else if (`nbmoda_`i''==2) {
- local mod = "`mod'"+"(2.item`i'<-THETA@2)"
- }
- }
- forvalues u=1/`nbdetect' {
- local v=`difitems`u''
- local mod = "`mod'"+"(1.item`v'<-THETA@1 tt)"
- if (`nbmoda_`v''==3) {
- local mod = "`mod'"+"(2.item`v'<-THETA@2 tt)(3.item`v'<-THETA@3 tt)"
- }
- else if (`nbmoda_`v''==2) {
- local mod = "`mod'"+"(2.item`v'<-THETA@2 tt)"
- }
- local w= 100+`u'
- 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'
- 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
- }
- }
- }
diff --git a/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S5.do b/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S5.do
deleted file mode 100644
index 7223c34..0000000
--- a/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S5.do
+++ /dev/null
@@ -1,364 +0,0 @@
-*=================================================================================================================================================
-* Date : 2024-01-23
-* Stata version : Stata 18 SE
-*
-* This program analyses simulated data accounting for DIF through a partial credit model
-*
-* ado-files needed : - pcm, rosali (version 5.5 October 25, 2023, available on gitea)
-*
-*
-*================================================================================================================================================
-adopath+"/home/corentin/Documents/These/Recherche/ROSALI-SIM/Modules/rosali_custom"
-
-
-local N = "50 100 200 300"
- local ss = "5"
- foreach s in `ss' {
- foreach Nnn in `N' {
- local Nn = `Nnn'
- local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N`Nn'"
- if (`s'<=4) {
- local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N`Nn'"
- }
- local path_res = "/home/corentin/Documents/These/Recherche/Simulations/Analysis/ROSALI-DIF/N`Nn'"
- local scenarios = "A B C D E F G"
- foreach scen in `scenarios' {
- clear
- import delim "`path_data'/scenario_`s'`scen'_`Nn'.csv", encoding(ISO-8859-2) case(preserve) clear
- rename TT tt
-
- if (`s'<=2) {
- local nbitems=4
- }
- else if (`s'<=4) {
- local nbitems=7
- }
- else if (`s'<=12) {
- local nbitems=4
- }
- else {
- local nbitems=7
- }
-
-if (mod(`s',2)==0) {
- local nbmoda=3
-}
-else {
- local nbmoda=1
-}
-
- if (`s'<=4) {
- local nbdif=0
- }
- else if (`s'<=8) {
- local nbdif=1
- }
- else if (`s'<=16) {
- local nbdif=2
- }
- else {
- local nbdif=3
- }
- * taillemat = Maximum J*M cases pour les items par et J*M cases pour les dif par + J cases pour les DIF detect + nbdif cases pour dif réel
- local taillemat=2*`nbitems'*`nbmoda'+`nbitems'+`nbdif'+2
- local colna=""
- forvalues i=1/`nbitems' {
- forvalues z=1/`nbmoda' {
- local colna = "`colna'"+"item`i'_`z' "
- local colna = "`colna'"+"dif_`i'_`z' "
- }
- }
- forvalues i=1/`nbitems' {
- local colna = "`colna'"+"dif_detect_`i' "
- }
-
- forvalues i=1/`nbdif' {
- local colna = "`colna'"+"real_dif_`i' "
- }
-local colna = "`colna'" + "beta " + "se_beta"
-
-
- mat outmat = J(1000,`taillemat',.)
- mat colnames outmat= `colna'
- di "Scenario `s'`scen' / N=`Nnn'"
- forvalues k=1/1000 {
- if (mod(`k',100)==0) {
- di "`k'/1000"
- }
- preserve
- qui keep if replication==`k'
-
-
- * MERGE des modalités si non représentées
-
- if (`nbmoda'>1 & `Nn'==50) {
- local com_z = 0
- qui gen comz = 0
- forvalues j = 1 / `nbitems' {
- local recoda_`j' = 0
- qui tab item`j' if tt == 0, matrow(rect1_g0_`j') matcell(nbrt1_g0_`j')
- local maxm`j'_t1_g0 = rect1_g0_`j'[r(r),1]
- local minm`j'_t1_g0 = rect1_g0_`j'[1,1]
-
- qui tab item`j' if tt == 1, matrow(rect1_g1_`j') matcell(nbrt1_g1_`j')
- local minm`j'_t1_g1 = rect1_g1_`j'[1,1]
- local maxm`j'_t1_g1 = rect1_g1_`j'[r(r),1]
-
- local minm_`j' = min(`minm`j'_t1_g0',`minm`j'_t1_g1')
- local maxm_`j' = max(`maxm`j'_t1_g0',`maxm`j'_t1_g1')
- local nbm_`j' = `=`maxm_`j''-`minm_`j'''
-
- if `minm_`j'' != 0 & `com_z' == 0 {
- local com_z = 1
- }
-
- qui count if item`j' == 3 & tt == 0
- local mod3plac = r(N)
- qui count if item`j' == 3 & tt == 1
- local mod3tt = r(N)
- local nb_rn3 = min(`mod3plac',`mod3tt')
- if `nb_rn3'==0 {
- qui replace comz = 1
- }
-
- forvalues m = 0/`=`nbm_`j''-1' {
- qui count if item`j' == `m' & tt == 0
- local nb_rn1_g0 = r(N)
- qui count if item`j' == `m' & tt == 1
- local nb_rn1_g1 = r(N)
- local nb_rn = min(`nb_rn1_g0',`nb_rn1_g1')
- if `nb_rn' == 0 {
- qui replace comz = 1
- local recoda_`j' = 1
- if `m' == 0 | `m' < `minm`j'_t1_g0' | `m' < `minm`j'_t1_g1' {
- local stop = 1
- forvalues kk = 1/`=`nbm_`j''-`m'' {
- qui count if item`j' == `=`m' + `kk'' & tt == 0
- local v`kk'1_0 = r(N)
- qui count if item`j' == `=`m' + `kk'' & tt == 1
- local v`kk'1_1 = r(N)
- if (`v`kk'1_0' != 0 | `v`kk'1_1' != 0) & `stop' != 0 {
- qui replace item`j'= `=`m'+`kk'' if item`j'==`m'
- local zzz=`j'+`nbitems'
- *qui replace item`zzz'=`=`m'+`kk'' if item``=`j'+`nbitems'''==`m'
- *di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
- local stop = 0
- }
- }
- }
- else if `m' == `=`nbm_`j''-1' | `m' >= `maxm`j'_t1_g1' {
- local stop = 1
- forvalues kk = 1/`=`m'' {
- qui count if item`j' == `=`m' - `kk'' & tt == 0
- local v`kk'1_0 = r(N)
- qui count if item`j' == `=`m' - `kk'' & tt == 1
- local v`kk'1_1 = r(N)
- if (`v`kk'1_0' != 0 | `v`kk'1_1' != 0) & `stop' != 0 {
- qui replace item`j'= `=`m' - `kk'' if item`j'==`m'
- local zzz=`j'+`nbitems'
- *qui replace item`zzz'= `=`m' - `kk'' if item`zzz'==`m'
- *di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
- local stop = 0
- }
- }
- }
- else {
- if runiform()>0.5{
- local stop = 1
- forvalues kk = 1/`m' {
- qui count if item`j' == `=`m' - `kk'' & tt == 0
- local v`kk'1_0 = r(N)
- qui count if item`j' == `=`m' - `kk'' & tt == 1
- local v`kk'1_1 = r(N)
- if (`v`kk'1_0' != 0 | `v`kk'1_1' != 0) & `stop' != 0 {
- qui replace item`j'= `=`m'-`kk'' if item`j'==`m'
- local zzz=`j'+`nbitems'
- *qui replace item`zzz'=`=`m'-`kk'' if item``=`j'+`nbitems'''==`m'
- *di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
- local stop = 0
- }
- }
- }
- else {
- local stop = 1
- forvalues kk = 1/`=`nbm_`j''-`m'' {
- qui count if item`j' == `=`m' + `kk'' & tt == 0
- local v`kk'1_0 = r(N)
- qui count if item`j' == `=`m' + `kk'' & tt == 1
- local v`kk'1_1 = r(N)
- if (`v`kk'1_0' != 0 | `v`kk'1_1' != 0) & `stop' != 0{
- qui replace item`j'=`=`m' + `kk'' if item`j'==`m'
- local zzz=`j'+`nbitems'
- *qui replace item`zzz'=`=`m' + `kk'' if item``=`j'+`nbitems'''==`m'
- *di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
- local stop = 0
- }
- else {
- if `stop' != 0 {
- qui replace item`j'= `nbm_`j'' if item`j'==`m'
- local zzz=`j'+`nbitems'
- *qui replace item`zzz'= `nbm_`j'' if item``=`j'+`nbitems'''==`m'
- *di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
- local stop = 0
- }
- }
- }
- }
- }
- }
- }
- qui levelsof item`j'
- local val = r(levels)
- local checker: word 1 of `val'
- local checker2: word 2 of `val'
- local checker3: word 3 of `val'
- local nummoda=r(r)
- local nbmoda_`j'=`nummoda'
- if (`nummoda'==2) {
- qui recode item`j' (`checker'=0) (`checker2'=1)
- }
- if (`nummoda'==3) {
- if (`checker'!=0) {
- qui recode item`j' (`checker'=0) (`checker2'=1) (`checker3'=2)
- }
- else if (`checker2'!=1) {
- qui recode item`j' (`checker2'=1) (`checker3'=2)
- }
- else if (`checker3'!=2) {
- qui recode item`j' (`checker3'=2)
- }
- }
- }
-
- qui valuesof comz
- local val = r(values)
- local checker: word 1 of `val'
- }
- else {
- forvalues jj=1/`nbitems' {
- local nbmoda_`jj'=`nbmoda'
- }
- }
-
-
- * ROSALI
- qui rosali_original item1-item`nbitems' item1-item`nbitems', group(tt)
- qui mat resmat=r(difitems)
- local nbitems2 = 2*`nbitems'
-
- * Calculer le nbre d'items détectés
- local nbdetect = 0
- local stop = 0
- forvalues jj=1/`nbitems' {
- if (`stop'==0) {
- mat testm=J(1,1,.)
- if (resmat[1,`jj']==testm[1,1]) {
- local stop = 1
- local nbdetect = `jj'-1
- }
- }
- }
-
- * Stocker les items détectés +
- * Définition des contraintes
- local csrt=0
- mat testm=J(1,1,0)
- forvalues u=1/`nbdetect' {
- local difitems`u'=resmat[1,`u']
- local i=`difitems`u''
- if (`nbmoda_`i''==3 & resmat[1,`nbitems'+`i']!=testm[1,1]){
- local constrnt`u' = "constraint `u' 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))"
- qui `constrnt`u''
- local v=`u'+100
- local constrnt`u'_2 = "constraint `v' 3*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([3.item`i']_cons-([3.item`i']_cons+[3.item`i'] tt))"
- qui `constrnt`u'_2'
- }
- if (`nbmoda_`i''==2 & resmat[1,`nbitems'+`i']!=testm[1,1]){
- local constrnt`u' = "constraint `u' 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))"
- qui `constrnt`u''
- }
- }
-
- * Définition du modèle
- local mod "gsem "
- local conformula = ""
- forvalues i=1/`nbitems' {
- local mod = "`mod'"+"(1.item`i'<-THETA@1)"
- if (`nbmoda_`i''==3) {
- local mod = "`mod'"+"(2.item`i'<-THETA@2)(3.item`i'<-THETA@3)"
- }
- else if (`nbmoda_`i''==2) {
- local mod = "`mod'"+"(2.item`i'<-THETA@2)"
- }
- }
- forvalues u=1/`nbdetect' {
- local v=`difitems`u''
- local mod = "`mod'"+"(1.item`v'<-THETA@1 tt)"
- if (`nbmoda_`v''==3) {
- local mod = "`mod'"+"(2.item`v'<-THETA@2 tt)(3.item`v'<-THETA@3 tt)"
- }
- else if (`nbmoda_`v''==2) {
- local mod = "`mod'"+"(2.item`v'<-THETA@2 tt)"
- }
- local w= 100+`u'
- if (resmat[1,`nbitems'+`v']!=testm[1,1] & `nbmoda_`v''==3) {
- local conformula = "`conformula'" + "`u' " + "`w' "
- }
- else if (resmat[1,`nbitems'+`v']!=testm[1,1] & `nbmoda_`v''==2) {
- local conformula = "`conformula'" + "`u' "
- }
- }
- if ("`conformula'" != "") {
- local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent constraint(`conformula')"
- }
- else {
- local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent"
- }
- *calcul du modèle
- qui `mod'
- mat V=r(table)
- mat W=V[1..2,1...]
-
- * compilation
- forvalues j=1/`nbitems' {
- forvalues z=1/`nbmoda_`j'' {
- mat outmat[`k',colnumb(outmat,"item`j'_`z'")] = W[1,colnumb(W,"`z'.item`j':_cons")]
- }
- }
- * compilation DIF
- forvalues u=1/`nbdetect' {
- local j=`difitems`u''
- forvalues z=1/`nbmoda_`j'' {
- mat outmat[`k',colnumb(outmat,"dif_`u'_`z'")] = W[1,colnumb(W,"`z'.item`j':tt")]
- mat outmat[`k',colnumb(outmat,"dif_detect_`u'")] = `j'
- }
- }
-
- * Stocker les items de DIF originaux
- if (`nbdif' > 0) {
- qui levelsof dif1
- local ldif1 = r(levels)
- local diff1: word 1 of `ldif1'
- qui mat outmat[`k',colnumb(outmat,"real_dif_1")]=`diff1'
- if (`nbdif' > 1) {
- qui levelsof dif2
- local ldif2 = r(levels)
- local diff2: word 1 of `ldif2'
- qui mat outmat[`k',colnumb(outmat,"real_dif_2")]=`diff2'
- if (`nbdif' > 2) {
- qui levelsof dif3
- local ldif3 = r(levels)
- local diff3: word 1 of `ldif3'
- qui mat outmat[`k',colnumb(outmat,"real_dif_3")]=`diff3'
- }
- }
- }
- qui mat outmat[`k',colnumb(outmat,"beta")]=W[1,colnumb(W,"THETA:tt")]
- qui mat outmat[`k',colnumb(outmat,"se_beta")]=W[2,colnumb(W,"THETA:tt")]
- restore
- }
- putexcel set "`path_res'/`s'`scen'_`Nn'_original.xls", sheet("outmat") replace
- putexcel A1=matrix(outmat), colnames
-}
-}
-}
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
deleted file mode 100644
index e3dea9f..0000000
--- a/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S6.do
+++ /dev/null
@@ -1,378 +0,0 @@
-*=================================================================================================================================================
-* Date : 2024-01-23
-* Stata version : Stata 18 SE
-*
-* This program analyses simulated data accounting for DIF through a partial credit model
-*
-* ado-files needed : - pcm, rosali (version 5.5 October 25, 2023, available on gitea)
-*
-*
-*================================================================================================================================================
-adopath+"/home/corentin/Documents/These/Recherche/ROSALI-SIM/Modules/rosali_custom"
-
-
-local N = "50 100 200 300"
- local ss = "6"
- foreach s in `ss' {
- foreach Nnn in `N' {
- local Nn = `Nnn'
- local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N`Nn'"
- if (`s'<=4) {
- local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N`Nn'"
- }
- local path_res = "/home/corentin/Documents/These/Recherche/Simulations/Analysis/ROSALI-DIF/N`Nn'"
- local scenarios = "A B C D E F G"
- foreach scen in `scenarios' {
- clear
- import delim "`path_data'/scenario_`s'`scen'_`Nn'.csv", encoding(ISO-8859-2) case(preserve) clear
- rename TT tt
-
- if (`s'<=2) {
- local nbitems=4
- }
- else if (`s'<=4) {
- local nbitems=7
- }
- else if (`s'<=12) {
- local nbitems=4
- }
- else {
- local nbitems=7
- }
-
- if (mod(`s',2)==0) {
- local nbmoda=3
- }
- else {
- local nbmoda=1
- }
-
- if (`s'<=4) {
- local nbdif=0
- }
- else if (`s'<=8) {
- local nbdif=1
- }
- else if (`s'<=16) {
- local nbdif=2
- }
- else {
- local nbdif=3
- }
- * taillemat = Maximum J*M cases pour les items par et J*M cases pour les dif par + J cases pour les DIF detect + nbdif cases pour dif réel
- local taillemat=2*`nbitems'*`nbmoda'+`nbitems'+`nbdif'+2
- 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'
- }
- }
-
-
- * ROSALI
- qui rosali_original item1-item`nbitems' item1-item`nbitems', group(tt)
- qui mat resmat=r(difitems)
- local nbitems2 = 2*`nbitems'
-
- * Calculer le nbre d'items détectés
- local nbdetect = 0
- local stop = 0
- forvalues jj=1/`nbitems' {
- if (`stop'==0) {
- mat testm=J(1,1,.)
- if (resmat[1,`jj']==testm[1,1]) {
- local stop = 1
- local nbdetect = `jj'-1
- }
- }
- }
-
- * Stocker les items détectés +
- * Définition des contraintes
- local csrt=0
- mat testm=J(1,1,0)
- forvalues u=1/`nbdetect' {
- local difitems`u'=resmat[1,`u']
- local i=`difitems`u''
- if (`nbmoda_`i''==3 & resmat[1,`nbitems'+`i']!=testm[1,1]){
- local constrnt`u' = "constraint `u' 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))"
- qui `constrnt`u''
- local v=`u'+100
- local constrnt`u'_2 = "constraint `v' 3*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([3.item`i']_cons-([3.item`i']_cons+[3.item`i'] tt))"
- qui `constrnt`u'_2'
- }
- if (`nbmoda_`i''==2 & resmat[1,`nbitems'+`i']!=testm[1,1]){
- local constrnt`u' = "constraint `u' 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))"
- qui `constrnt`u''
- }
- }
-
- * Définition du modèle
- local mod "gsem "
- local conformula = ""
- forvalues i=1/`nbitems' {
- local mod = "`mod'"+"(1.item`i'<-THETA@1)"
- if (`nbmoda_`i''==3) {
- local mod = "`mod'"+"(2.item`i'<-THETA@2)(3.item`i'<-THETA@3)"
- }
- else if (`nbmoda_`i''==2) {
- local mod = "`mod'"+"(2.item`i'<-THETA@2)"
- }
- }
- forvalues u=1/`nbdetect' {
- local v=`difitems`u''
- local mod = "`mod'"+"(1.item`v'<-THETA@1 tt)"
- if (`nbmoda_`v''==3) {
- local mod = "`mod'"+"(2.item`v'<-THETA@2 tt)(3.item`v'<-THETA@3 tt)"
- }
- else if (`nbmoda_`v''==2) {
- local mod = "`mod'"+"(2.item`v'<-THETA@2 tt)"
- }
- local w= 100+`u'
- 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'
- 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
- }
- }
- }
diff --git a/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S7.do b/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S7.do
deleted file mode 100644
index abdbd90..0000000
--- a/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S7.do
+++ /dev/null
@@ -1,364 +0,0 @@
-*=================================================================================================================================================
-* Date : 2024-01-23
-* Stata version : Stata 18 SE
-*
-* This program analyses simulated data accounting for DIF through a partial credit model
-*
-* ado-files needed : - pcm, rosali (version 5.5 October 25, 2023, available on gitea)
-*
-*
-*================================================================================================================================================
-adopath+"/home/corentin/Documents/These/Recherche/ROSALI-SIM/Modules/rosali_custom"
-
-
-local N = "50 100 200 300"
- local ss = "7"
- foreach s in `ss' {
- foreach Nnn in `N' {
- local Nn = `Nnn'
- local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N`Nn'"
- if (`s'<=4) {
- local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N`Nn'"
- }
- local path_res = "/home/corentin/Documents/These/Recherche/Simulations/Analysis/ROSALI-DIF/N`Nn'"
- local scenarios = "A B C D E F G"
- foreach scen in `scenarios' {
- clear
- import delim "`path_data'/scenario_`s'`scen'_`Nn'.csv", encoding(ISO-8859-2) case(preserve) clear
- rename TT tt
-
- if (`s'<=2) {
- local nbitems=4
- }
- else if (`s'<=4) {
- local nbitems=7
- }
- else if (`s'<=12) {
- local nbitems=4
- }
- else {
- local nbitems=7
- }
-
-if (mod(`s',2)==0) {
- local nbmoda=3
-}
-else {
- local nbmoda=1
-}
-
- if (`s'<=4) {
- local nbdif=0
- }
- else if (`s'<=8) {
- local nbdif=1
- }
- else if (`s'<=16) {
- local nbdif=2
- }
- else {
- local nbdif=3
- }
- * taillemat = Maximum J*M cases pour les items par et J*M cases pour les dif par + J cases pour les DIF detect + nbdif cases pour dif réel
- local taillemat=2*`nbitems'*`nbmoda'+`nbitems'+`nbdif'+2
- local colna=""
- forvalues i=1/`nbitems' {
- forvalues z=1/`nbmoda' {
- local colna = "`colna'"+"item`i'_`z' "
- local colna = "`colna'"+"dif_`i'_`z' "
- }
- }
- forvalues i=1/`nbitems' {
- local colna = "`colna'"+"dif_detect_`i' "
- }
-
- forvalues i=1/`nbdif' {
- local colna = "`colna'"+"real_dif_`i' "
- }
-local colna = "`colna'" + "beta " + "se_beta"
-
-
- mat outmat = J(1000,`taillemat',.)
- mat colnames outmat= `colna'
- di "Scenario `s'`scen' / N=`Nnn'"
- forvalues k=1/1000 {
- if (mod(`k',100)==0) {
- di "`k'/1000"
- }
- preserve
- qui keep if replication==`k'
-
-
- * MERGE des modalités si non représentées
-
- if (`nbmoda'>1 & `Nn'==50) {
- local com_z = 0
- qui gen comz = 0
- forvalues j = 1 / `nbitems' {
- local recoda_`j' = 0
- qui tab item`j' if tt == 0, matrow(rect1_g0_`j') matcell(nbrt1_g0_`j')
- local maxm`j'_t1_g0 = rect1_g0_`j'[r(r),1]
- local minm`j'_t1_g0 = rect1_g0_`j'[1,1]
-
- qui tab item`j' if tt == 1, matrow(rect1_g1_`j') matcell(nbrt1_g1_`j')
- local minm`j'_t1_g1 = rect1_g1_`j'[1,1]
- local maxm`j'_t1_g1 = rect1_g1_`j'[r(r),1]
-
- local minm_`j' = min(`minm`j'_t1_g0',`minm`j'_t1_g1')
- local maxm_`j' = max(`maxm`j'_t1_g0',`maxm`j'_t1_g1')
- local nbm_`j' = `=`maxm_`j''-`minm_`j'''
-
- if `minm_`j'' != 0 & `com_z' == 0 {
- local com_z = 1
- }
-
- qui count if item`j' == 3 & tt == 0
- local mod3plac = r(N)
- qui count if item`j' == 3 & tt == 1
- local mod3tt = r(N)
- local nb_rn3 = min(`mod3plac',`mod3tt')
- if `nb_rn3'==0 {
- qui replace comz = 1
- }
-
- forvalues m = 0/`=`nbm_`j''-1' {
- qui count if item`j' == `m' & tt == 0
- local nb_rn1_g0 = r(N)
- qui count if item`j' == `m' & tt == 1
- local nb_rn1_g1 = r(N)
- local nb_rn = min(`nb_rn1_g0',`nb_rn1_g1')
- if `nb_rn' == 0 {
- qui replace comz = 1
- local recoda_`j' = 1
- if `m' == 0 | `m' < `minm`j'_t1_g0' | `m' < `minm`j'_t1_g1' {
- local stop = 1
- forvalues kk = 1/`=`nbm_`j''-`m'' {
- qui count if item`j' == `=`m' + `kk'' & tt == 0
- local v`kk'1_0 = r(N)
- qui count if item`j' == `=`m' + `kk'' & tt == 1
- local v`kk'1_1 = r(N)
- if (`v`kk'1_0' != 0 | `v`kk'1_1' != 0) & `stop' != 0 {
- qui replace item`j'= `=`m'+`kk'' if item`j'==`m'
- local zzz=`j'+`nbitems'
- *qui replace item`zzz'=`=`m'+`kk'' if item``=`j'+`nbitems'''==`m'
- *di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
- local stop = 0
- }
- }
- }
- else if `m' == `=`nbm_`j''-1' | `m' >= `maxm`j'_t1_g1' {
- local stop = 1
- forvalues kk = 1/`=`m'' {
- qui count if item`j' == `=`m' - `kk'' & tt == 0
- local v`kk'1_0 = r(N)
- qui count if item`j' == `=`m' - `kk'' & tt == 1
- local v`kk'1_1 = r(N)
- if (`v`kk'1_0' != 0 | `v`kk'1_1' != 0) & `stop' != 0 {
- qui replace item`j'= `=`m' - `kk'' if item`j'==`m'
- local zzz=`j'+`nbitems'
- *qui replace item`zzz'= `=`m' - `kk'' if item`zzz'==`m'
- *di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
- local stop = 0
- }
- }
- }
- else {
- if runiform()>0.5{
- local stop = 1
- forvalues kk = 1/`m' {
- qui count if item`j' == `=`m' - `kk'' & tt == 0
- local v`kk'1_0 = r(N)
- qui count if item`j' == `=`m' - `kk'' & tt == 1
- local v`kk'1_1 = r(N)
- if (`v`kk'1_0' != 0 | `v`kk'1_1' != 0) & `stop' != 0 {
- qui replace item`j'= `=`m'-`kk'' if item`j'==`m'
- local zzz=`j'+`nbitems'
- *qui replace item`zzz'=`=`m'-`kk'' if item``=`j'+`nbitems'''==`m'
- *di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
- local stop = 0
- }
- }
- }
- else {
- local stop = 1
- forvalues kk = 1/`=`nbm_`j''-`m'' {
- qui count if item`j' == `=`m' + `kk'' & tt == 0
- local v`kk'1_0 = r(N)
- qui count if item`j' == `=`m' + `kk'' & tt == 1
- local v`kk'1_1 = r(N)
- if (`v`kk'1_0' != 0 | `v`kk'1_1' != 0) & `stop' != 0{
- qui replace item`j'=`=`m' + `kk'' if item`j'==`m'
- local zzz=`j'+`nbitems'
- *qui replace item`zzz'=`=`m' + `kk'' if item``=`j'+`nbitems'''==`m'
- *di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
- local stop = 0
- }
- else {
- if `stop' != 0 {
- qui replace item`j'= `nbm_`j'' if item`j'==`m'
- local zzz=`j'+`nbitems'
- *qui replace item`zzz'= `nbm_`j'' if item``=`j'+`nbitems'''==`m'
- *di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
- local stop = 0
- }
- }
- }
- }
- }
- }
- }
- qui levelsof item`j'
- local val = r(levels)
- local checker: word 1 of `val'
- local checker2: word 2 of `val'
- local checker3: word 3 of `val'
- local nummoda=r(r)
- local nbmoda_`j'=`nummoda'
- if (`nummoda'==2) {
- qui recode item`j' (`checker'=0) (`checker2'=1)
- }
- if (`nummoda'==3) {
- if (`checker'!=0) {
- qui recode item`j' (`checker'=0) (`checker2'=1) (`checker3'=2)
- }
- else if (`checker2'!=1) {
- qui recode item`j' (`checker2'=1) (`checker3'=2)
- }
- else if (`checker3'!=2) {
- qui recode item`j' (`checker3'=2)
- }
- }
- }
-
- qui valuesof comz
- local val = r(values)
- local checker: word 1 of `val'
- }
- else {
- forvalues jj=1/`nbitems' {
- local nbmoda_`jj'=`nbmoda'
- }
- }
-
-
- * ROSALI
- qui rosali_original item1-item`nbitems' item1-item`nbitems', group(tt)
- qui mat resmat=r(difitems)
- local nbitems2 = 2*`nbitems'
-
- * Calculer le nbre d'items détectés
- local nbdetect = 0
- local stop = 0
- forvalues jj=1/`nbitems' {
- if (`stop'==0) {
- mat testm=J(1,1,.)
- if (resmat[1,`jj']==testm[1,1]) {
- local stop = 1
- local nbdetect = `jj'-1
- }
- }
- }
-
- * Stocker les items détectés +
- * Définition des contraintes
- local csrt=0
- mat testm=J(1,1,0)
- forvalues u=1/`nbdetect' {
- local difitems`u'=resmat[1,`u']
- local i=`difitems`u''
- if (`nbmoda_`i''==3 & resmat[1,`nbitems'+`i']!=testm[1,1]){
- local constrnt`u' = "constraint `u' 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))"
- qui `constrnt`u''
- local v=`u'+100
- local constrnt`u'_2 = "constraint `v' 3*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([3.item`i']_cons-([3.item`i']_cons+[3.item`i'] tt))"
- qui `constrnt`u'_2'
- }
- if (`nbmoda_`i''==2 & resmat[1,`nbitems'+`i']!=testm[1,1]){
- local constrnt`u' = "constraint `u' 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))"
- qui `constrnt`u''
- }
- }
-
- * Définition du modèle
- local mod "gsem "
- local conformula = ""
- forvalues i=1/`nbitems' {
- local mod = "`mod'"+"(1.item`i'<-THETA@1)"
- if (`nbmoda_`i''==3) {
- local mod = "`mod'"+"(2.item`i'<-THETA@2)(3.item`i'<-THETA@3)"
- }
- else if (`nbmoda_`i''==2) {
- local mod = "`mod'"+"(2.item`i'<-THETA@2)"
- }
- }
- forvalues u=1/`nbdetect' {
- local v=`difitems`u''
- local mod = "`mod'"+"(1.item`v'<-THETA@1 tt)"
- if (`nbmoda_`v''==3) {
- local mod = "`mod'"+"(2.item`v'<-THETA@2 tt)(3.item`v'<-THETA@3 tt)"
- }
- else if (`nbmoda_`v''==2) {
- local mod = "`mod'"+"(2.item`v'<-THETA@2 tt)"
- }
- local w= 100+`u'
- if (resmat[1,`nbitems'+`v']!=testm[1,1] & `nbmoda_`v''==3) {
- local conformula = "`conformula'" + "`u' " + "`w' "
- }
- else if (resmat[1,`nbitems'+`v']!=testm[1,1] & `nbmoda_`v''==2) {
- local conformula = "`conformula'" + "`u' "
- }
- }
- if ("`conformula'" != "") {
- local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent constraint(`conformula')"
- }
- else {
- local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent"
- }
- *calcul du modèle
- qui `mod'
- mat V=r(table)
- mat W=V[1..2,1...]
-
- * compilation
- forvalues j=1/`nbitems' {
- forvalues z=1/`nbmoda_`j'' {
- mat outmat[`k',colnumb(outmat,"item`j'_`z'")] = W[1,colnumb(W,"`z'.item`j':_cons")]
- }
- }
- * compilation DIF
- forvalues u=1/`nbdetect' {
- local j=`difitems`u''
- forvalues z=1/`nbmoda_`j'' {
- mat outmat[`k',colnumb(outmat,"dif_`u'_`z'")] = W[1,colnumb(W,"`z'.item`j':tt")]
- mat outmat[`k',colnumb(outmat,"dif_detect_`u'")] = `j'
- }
- }
-
- * Stocker les items de DIF originaux
- if (`nbdif' > 0) {
- qui levelsof dif1
- local ldif1 = r(levels)
- local diff1: word 1 of `ldif1'
- qui mat outmat[`k',colnumb(outmat,"real_dif_1")]=`diff1'
- if (`nbdif' > 1) {
- qui levelsof dif2
- local ldif2 = r(levels)
- local diff2: word 1 of `ldif2'
- qui mat outmat[`k',colnumb(outmat,"real_dif_2")]=`diff2'
- if (`nbdif' > 2) {
- qui levelsof dif3
- local ldif3 = r(levels)
- local diff3: word 1 of `ldif3'
- qui mat outmat[`k',colnumb(outmat,"real_dif_3")]=`diff3'
- }
- }
- }
- qui mat outmat[`k',colnumb(outmat,"beta")]=W[1,colnumb(W,"THETA:tt")]
- qui mat outmat[`k',colnumb(outmat,"se_beta")]=W[2,colnumb(W,"THETA:tt")]
- restore
- }
- putexcel set "`path_res'/`s'`scen'_`Nn'_original.xls", sheet("outmat") replace
- putexcel A1=matrix(outmat), colnames
-}
-}
-}
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
deleted file mode 100644
index 737d60a..0000000
--- a/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S8.do
+++ /dev/null
@@ -1,378 +0,0 @@
-*=================================================================================================================================================
-* Date : 2024-01-23
-* Stata version : Stata 18 SE
-*
-* This program analyses simulated data accounting for DIF through a partial credit model
-*
-* ado-files needed : - pcm, rosali (version 5.5 October 25, 2023, available on gitea)
-*
-*
-*================================================================================================================================================
-adopath+"/home/corentin/Documents/These/Recherche/ROSALI-SIM/Modules/rosali_custom"
-
-
-local N = "50 100 200 300"
- local ss = "8"
- foreach s in `ss' {
- foreach Nnn in `N' {
- local Nn = `Nnn'
- local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N`Nn'"
- if (`s'<=4) {
- local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N`Nn'"
- }
- local path_res = "/home/corentin/Documents/These/Recherche/Simulations/Analysis/ROSALI-DIF/N`Nn'"
- local scenarios = "A B C D E F G"
- foreach scen in `scenarios' {
- clear
- import delim "`path_data'/scenario_`s'`scen'_`Nn'.csv", encoding(ISO-8859-2) case(preserve) clear
- rename TT tt
-
- if (`s'<=2) {
- local nbitems=4
- }
- else if (`s'<=4) {
- local nbitems=7
- }
- else if (`s'<=12) {
- local nbitems=4
- }
- else {
- local nbitems=7
- }
-
- if (mod(`s',2)==0) {
- local nbmoda=3
- }
- else {
- local nbmoda=1
- }
-
- if (`s'<=4) {
- local nbdif=0
- }
- else if (`s'<=8) {
- local nbdif=1
- }
- else if (`s'<=16) {
- local nbdif=2
- }
- else {
- local nbdif=3
- }
- * taillemat = Maximum J*M cases pour les items par et J*M cases pour les dif par + J cases pour les DIF detect + nbdif cases pour dif réel
- local taillemat=2*`nbitems'*`nbmoda'+`nbitems'+`nbdif'+2
- 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'
- }
- }
-
-
- * ROSALI
- qui rosali_original item1-item`nbitems' item1-item`nbitems', group(tt)
- qui mat resmat=r(difitems)
- local nbitems2 = 2*`nbitems'
-
- * Calculer le nbre d'items détectés
- local nbdetect = 0
- local stop = 0
- forvalues jj=1/`nbitems' {
- if (`stop'==0) {
- mat testm=J(1,1,.)
- if (resmat[1,`jj']==testm[1,1]) {
- local stop = 1
- local nbdetect = `jj'-1
- }
- }
- }
-
- * Stocker les items détectés +
- * Définition des contraintes
- local csrt=0
- mat testm=J(1,1,0)
- forvalues u=1/`nbdetect' {
- local difitems`u'=resmat[1,`u']
- local i=`difitems`u''
- if (`nbmoda_`i''==3 & resmat[1,`nbitems'+`i']!=testm[1,1]){
- local constrnt`u' = "constraint `u' 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))"
- qui `constrnt`u''
- local v=`u'+100
- local constrnt`u'_2 = "constraint `v' 3*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([3.item`i']_cons-([3.item`i']_cons+[3.item`i'] tt))"
- qui `constrnt`u'_2'
- }
- if (`nbmoda_`i''==2 & resmat[1,`nbitems'+`i']!=testm[1,1]){
- local constrnt`u' = "constraint `u' 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))"
- qui `constrnt`u''
- }
- }
-
- * Définition du modèle
- local mod "gsem "
- local conformula = ""
- forvalues i=1/`nbitems' {
- local mod = "`mod'"+"(1.item`i'<-THETA@1)"
- if (`nbmoda_`i''==3) {
- local mod = "`mod'"+"(2.item`i'<-THETA@2)(3.item`i'<-THETA@3)"
- }
- else if (`nbmoda_`i''==2) {
- local mod = "`mod'"+"(2.item`i'<-THETA@2)"
- }
- }
- forvalues u=1/`nbdetect' {
- local v=`difitems`u''
- local mod = "`mod'"+"(1.item`v'<-THETA@1 tt)"
- if (`nbmoda_`v''==3) {
- local mod = "`mod'"+"(2.item`v'<-THETA@2 tt)(3.item`v'<-THETA@3 tt)"
- }
- else if (`nbmoda_`v''==2) {
- local mod = "`mod'"+"(2.item`v'<-THETA@2 tt)"
- }
- local w= 100+`u'
- 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'
- 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
- }
- }
- }
diff --git a/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S9.do b/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S9.do
deleted file mode 100644
index c1525e7..0000000
--- a/Scripts/Analysis/DIF-ROSALI/scénarios/pcm_dif_rosali_S9.do
+++ /dev/null
@@ -1,364 +0,0 @@
-*=================================================================================================================================================
-* Date : 2024-01-23
-* Stata version : Stata 18 SE
-*
-* This program analyses simulated data accounting for DIF through a partial credit model
-*
-* ado-files needed : - pcm, rosali (version 5.5 October 25, 2023, available on gitea)
-*
-*
-*================================================================================================================================================
-adopath+"/home/corentin/Documents/These/Recherche/ROSALI-SIM/Modules/rosali_custom"
-
-
-local N = "50 100 200 300"
- local ss = "9"
- foreach s in `ss' {
- foreach Nnn in `N' {
- local Nn = `Nnn'
- local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N`Nn'"
- if (`s'<=4) {
- local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N`Nn'"
- }
- local path_res = "/home/corentin/Documents/These/Recherche/Simulations/Analysis/ROSALI-DIF/N`Nn'"
- local scenarios = "A B C D E F G"
- foreach scen in `scenarios' {
- clear
- import delim "`path_data'/scenario_`s'`scen'_`Nn'.csv", encoding(ISO-8859-2) case(preserve) clear
- rename TT tt
-
- if (`s'<=2) {
- local nbitems=4
- }
- else if (`s'<=4) {
- local nbitems=7
- }
- else if (`s'<=12) {
- local nbitems=4
- }
- else {
- local nbitems=7
- }
-
-if (mod(`s',2)==0) {
- local nbmoda=3
-}
-else {
- local nbmoda=1
-}
-
- if (`s'<=4) {
- local nbdif=0
- }
- else if (`s'<=8) {
- local nbdif=1
- }
- else if (`s'<=16) {
- local nbdif=2
- }
- else {
- local nbdif=3
- }
- * taillemat = Maximum J*M cases pour les items par et J*M cases pour les dif par + J cases pour les DIF detect + nbdif cases pour dif réel
- local taillemat=2*`nbitems'*`nbmoda'+`nbitems'+`nbdif'+2
- local colna=""
- forvalues i=1/`nbitems' {
- forvalues z=1/`nbmoda' {
- local colna = "`colna'"+"item`i'_`z' "
- local colna = "`colna'"+"dif_`i'_`z' "
- }
- }
- forvalues i=1/`nbitems' {
- local colna = "`colna'"+"dif_detect_`i' "
- }
-
- forvalues i=1/`nbdif' {
- local colna = "`colna'"+"real_dif_`i' "
- }
-local colna = "`colna'" + "beta " + "se_beta"
-
-
- mat outmat = J(1000,`taillemat',.)
- mat colnames outmat= `colna'
- di "Scenario `s'`scen' / N=`Nnn'"
- forvalues k=1/1000 {
- if (mod(`k',100)==0) {
- di "`k'/1000"
- }
- preserve
- qui keep if replication==`k'
-
-
- * MERGE des modalités si non représentées
-
- if (`nbmoda'>1 & `Nn'==50) {
- local com_z = 0
- qui gen comz = 0
- forvalues j = 1 / `nbitems' {
- local recoda_`j' = 0
- qui tab item`j' if tt == 0, matrow(rect1_g0_`j') matcell(nbrt1_g0_`j')
- local maxm`j'_t1_g0 = rect1_g0_`j'[r(r),1]
- local minm`j'_t1_g0 = rect1_g0_`j'[1,1]
-
- qui tab item`j' if tt == 1, matrow(rect1_g1_`j') matcell(nbrt1_g1_`j')
- local minm`j'_t1_g1 = rect1_g1_`j'[1,1]
- local maxm`j'_t1_g1 = rect1_g1_`j'[r(r),1]
-
- local minm_`j' = min(`minm`j'_t1_g0',`minm`j'_t1_g1')
- local maxm_`j' = max(`maxm`j'_t1_g0',`maxm`j'_t1_g1')
- local nbm_`j' = `=`maxm_`j''-`minm_`j'''
-
- if `minm_`j'' != 0 & `com_z' == 0 {
- local com_z = 1
- }
-
- qui count if item`j' == 3 & tt == 0
- local mod3plac = r(N)
- qui count if item`j' == 3 & tt == 1
- local mod3tt = r(N)
- local nb_rn3 = min(`mod3plac',`mod3tt')
- if `nb_rn3'==0 {
- qui replace comz = 1
- }
-
- forvalues m = 0/`=`nbm_`j''-1' {
- qui count if item`j' == `m' & tt == 0
- local nb_rn1_g0 = r(N)
- qui count if item`j' == `m' & tt == 1
- local nb_rn1_g1 = r(N)
- local nb_rn = min(`nb_rn1_g0',`nb_rn1_g1')
- if `nb_rn' == 0 {
- qui replace comz = 1
- local recoda_`j' = 1
- if `m' == 0 | `m' < `minm`j'_t1_g0' | `m' < `minm`j'_t1_g1' {
- local stop = 1
- forvalues kk = 1/`=`nbm_`j''-`m'' {
- qui count if item`j' == `=`m' + `kk'' & tt == 0
- local v`kk'1_0 = r(N)
- qui count if item`j' == `=`m' + `kk'' & tt == 1
- local v`kk'1_1 = r(N)
- if (`v`kk'1_0' != 0 | `v`kk'1_1' != 0) & `stop' != 0 {
- qui replace item`j'= `=`m'+`kk'' if item`j'==`m'
- local zzz=`j'+`nbitems'
- *qui replace item`zzz'=`=`m'+`kk'' if item``=`j'+`nbitems'''==`m'
- *di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
- local stop = 0
- }
- }
- }
- else if `m' == `=`nbm_`j''-1' | `m' >= `maxm`j'_t1_g1' {
- local stop = 1
- forvalues kk = 1/`=`m'' {
- qui count if item`j' == `=`m' - `kk'' & tt == 0
- local v`kk'1_0 = r(N)
- qui count if item`j' == `=`m' - `kk'' & tt == 1
- local v`kk'1_1 = r(N)
- if (`v`kk'1_0' != 0 | `v`kk'1_1' != 0) & `stop' != 0 {
- qui replace item`j'= `=`m' - `kk'' if item`j'==`m'
- local zzz=`j'+`nbitems'
- *qui replace item`zzz'= `=`m' - `kk'' if item`zzz'==`m'
- *di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
- local stop = 0
- }
- }
- }
- else {
- if runiform()>0.5{
- local stop = 1
- forvalues kk = 1/`m' {
- qui count if item`j' == `=`m' - `kk'' & tt == 0
- local v`kk'1_0 = r(N)
- qui count if item`j' == `=`m' - `kk'' & tt == 1
- local v`kk'1_1 = r(N)
- if (`v`kk'1_0' != 0 | `v`kk'1_1' != 0) & `stop' != 0 {
- qui replace item`j'= `=`m'-`kk'' if item`j'==`m'
- local zzz=`j'+`nbitems'
- *qui replace item`zzz'=`=`m'-`kk'' if item``=`j'+`nbitems'''==`m'
- *di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
- local stop = 0
- }
- }
- }
- else {
- local stop = 1
- forvalues kk = 1/`=`nbm_`j''-`m'' {
- qui count if item`j' == `=`m' + `kk'' & tt == 0
- local v`kk'1_0 = r(N)
- qui count if item`j' == `=`m' + `kk'' & tt == 1
- local v`kk'1_1 = r(N)
- if (`v`kk'1_0' != 0 | `v`kk'1_1' != 0) & `stop' != 0{
- qui replace item`j'=`=`m' + `kk'' if item`j'==`m'
- local zzz=`j'+`nbitems'
- *qui replace item`zzz'=`=`m' + `kk'' if item``=`j'+`nbitems'''==`m'
- *di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
- local stop = 0
- }
- else {
- if `stop' != 0 {
- qui replace item`j'= `nbm_`j'' if item`j'==`m'
- local zzz=`j'+`nbitems'
- *qui replace item`zzz'= `nbm_`j'' if item``=`j'+`nbitems'''==`m'
- *di "WARNING SCENARIO `k': items `j': answers `m' and `=`m'+`kk'' merged"
- local stop = 0
- }
- }
- }
- }
- }
- }
- }
- qui levelsof item`j'
- local val = r(levels)
- local checker: word 1 of `val'
- local checker2: word 2 of `val'
- local checker3: word 3 of `val'
- local nummoda=r(r)
- local nbmoda_`j'=`nummoda'
- if (`nummoda'==2) {
- qui recode item`j' (`checker'=0) (`checker2'=1)
- }
- if (`nummoda'==3) {
- if (`checker'!=0) {
- qui recode item`j' (`checker'=0) (`checker2'=1) (`checker3'=2)
- }
- else if (`checker2'!=1) {
- qui recode item`j' (`checker2'=1) (`checker3'=2)
- }
- else if (`checker3'!=2) {
- qui recode item`j' (`checker3'=2)
- }
- }
- }
-
- qui valuesof comz
- local val = r(values)
- local checker: word 1 of `val'
- }
- else {
- forvalues jj=1/`nbitems' {
- local nbmoda_`jj'=`nbmoda'
- }
- }
-
-
- * ROSALI
- qui rosali_original item1-item`nbitems' item1-item`nbitems', group(tt)
- qui mat resmat=r(difitems)
- local nbitems2 = 2*`nbitems'
-
- * Calculer le nbre d'items détectés
- local nbdetect = 0
- local stop = 0
- forvalues jj=1/`nbitems' {
- if (`stop'==0) {
- mat testm=J(1,1,.)
- if (resmat[1,`jj']==testm[1,1]) {
- local stop = 1
- local nbdetect = `jj'-1
- }
- }
- }
-
- * Stocker les items détectés +
- * Définition des contraintes
- local csrt=0
- mat testm=J(1,1,0)
- forvalues u=1/`nbdetect' {
- local difitems`u'=resmat[1,`u']
- local i=`difitems`u''
- if (`nbmoda_`i''==3 & resmat[1,`nbitems'+`i']!=testm[1,1]){
- local constrnt`u' = "constraint `u' 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))"
- qui `constrnt`u''
- local v=`u'+100
- local constrnt`u'_2 = "constraint `v' 3*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([3.item`i']_cons-([3.item`i']_cons+[3.item`i'] tt))"
- qui `constrnt`u'_2'
- }
- if (`nbmoda_`i''==2 & resmat[1,`nbitems'+`i']!=testm[1,1]){
- local constrnt`u' = "constraint `u' 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))"
- qui `constrnt`u''
- }
- }
-
- * Définition du modèle
- local mod "gsem "
- local conformula = ""
- forvalues i=1/`nbitems' {
- local mod = "`mod'"+"(1.item`i'<-THETA@1)"
- if (`nbmoda_`i''==3) {
- local mod = "`mod'"+"(2.item`i'<-THETA@2)(3.item`i'<-THETA@3)"
- }
- else if (`nbmoda_`i''==2) {
- local mod = "`mod'"+"(2.item`i'<-THETA@2)"
- }
- }
- forvalues u=1/`nbdetect' {
- local v=`difitems`u''
- local mod = "`mod'"+"(1.item`v'<-THETA@1 tt)"
- if (`nbmoda_`v''==3) {
- local mod = "`mod'"+"(2.item`v'<-THETA@2 tt)(3.item`v'<-THETA@3 tt)"
- }
- else if (`nbmoda_`v''==2) {
- local mod = "`mod'"+"(2.item`v'<-THETA@2 tt)"
- }
- local w= 100+`u'
- if (resmat[1,`nbitems'+`v']!=testm[1,1] & `nbmoda_`v''==3) {
- local conformula = "`conformula'" + "`u' " + "`w' "
- }
- else if (resmat[1,`nbitems'+`v']!=testm[1,1] & `nbmoda_`v''==2) {
- local conformula = "`conformula'" + "`u' "
- }
- }
- if ("`conformula'" != "") {
- local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent constraint(`conformula')"
- }
- else {
- local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent"
- }
- *calcul du modèle
- qui `mod'
- mat V=r(table)
- mat W=V[1..2,1...]
-
- * compilation
- forvalues j=1/`nbitems' {
- forvalues z=1/`nbmoda_`j'' {
- mat outmat[`k',colnumb(outmat,"item`j'_`z'")] = W[1,colnumb(W,"`z'.item`j':_cons")]
- }
- }
- * compilation DIF
- forvalues u=1/`nbdetect' {
- local j=`difitems`u''
- forvalues z=1/`nbmoda_`j'' {
- mat outmat[`k',colnumb(outmat,"dif_`u'_`z'")] = W[1,colnumb(W,"`z'.item`j':tt")]
- mat outmat[`k',colnumb(outmat,"dif_detect_`u'")] = `j'
- }
- }
-
- * Stocker les items de DIF originaux
- if (`nbdif' > 0) {
- qui levelsof dif1
- local ldif1 = r(levels)
- local diff1: word 1 of `ldif1'
- qui mat outmat[`k',colnumb(outmat,"real_dif_1")]=`diff1'
- if (`nbdif' > 1) {
- qui levelsof dif2
- local ldif2 = r(levels)
- local diff2: word 1 of `ldif2'
- qui mat outmat[`k',colnumb(outmat,"real_dif_2")]=`diff2'
- if (`nbdif' > 2) {
- qui levelsof dif3
- local ldif3 = r(levels)
- local diff3: word 1 of `ldif3'
- qui mat outmat[`k',colnumb(outmat,"real_dif_3")]=`diff3'
- }
- }
- }
- qui mat outmat[`k',colnumb(outmat,"beta")]=W[1,colnumb(W,"THETA:tt")]
- qui mat outmat[`k',colnumb(outmat,"se_beta")]=W[2,colnumb(W,"THETA:tt")]
- restore
- }
- putexcel set "`path_res'/`s'`scen'_`Nn'_original.xls", sheet("outmat") replace
- putexcel A1=matrix(outmat), colnames
-}
-}
-}
diff --git a/Scripts/Scenarios/DIF/scenarios_DIF_J4_baseline_100.do b/Scripts/Data_generation/DIF/scenarios_DIF_J4_baseline_100.do
similarity index 100%
rename from Scripts/Scenarios/DIF/scenarios_DIF_J4_baseline_100.do
rename to Scripts/Data_generation/DIF/scenarios_DIF_J4_baseline_100.do
diff --git a/Scripts/Scenarios/DIF/scenarios_DIF_J4_baseline_200.do b/Scripts/Data_generation/DIF/scenarios_DIF_J4_baseline_200.do
similarity index 100%
rename from Scripts/Scenarios/DIF/scenarios_DIF_J4_baseline_200.do
rename to Scripts/Data_generation/DIF/scenarios_DIF_J4_baseline_200.do
diff --git a/Scripts/Scenarios/DIF/scenarios_DIF_J4_baseline_300.do b/Scripts/Data_generation/DIF/scenarios_DIF_J4_baseline_300.do
similarity index 100%
rename from Scripts/Scenarios/DIF/scenarios_DIF_J4_baseline_300.do
rename to Scripts/Data_generation/DIF/scenarios_DIF_J4_baseline_300.do
diff --git a/Scripts/Scenarios/DIF/scenarios_DIF_J4_baseline_50.do b/Scripts/Data_generation/DIF/scenarios_DIF_J4_baseline_50.do
similarity index 100%
rename from Scripts/Scenarios/DIF/scenarios_DIF_J4_baseline_50.do
rename to Scripts/Data_generation/DIF/scenarios_DIF_J4_baseline_50.do
diff --git a/Scripts/Scenarios/DIF/scenarios_DIF_J7_baseline_100.do b/Scripts/Data_generation/DIF/scenarios_DIF_J7_baseline_100.do
similarity index 100%
rename from Scripts/Scenarios/DIF/scenarios_DIF_J7_baseline_100.do
rename to Scripts/Data_generation/DIF/scenarios_DIF_J7_baseline_100.do
diff --git a/Scripts/Scenarios/DIF/scenarios_DIF_J7_baseline_200.do b/Scripts/Data_generation/DIF/scenarios_DIF_J7_baseline_200.do
similarity index 100%
rename from Scripts/Scenarios/DIF/scenarios_DIF_J7_baseline_200.do
rename to Scripts/Data_generation/DIF/scenarios_DIF_J7_baseline_200.do
diff --git a/Scripts/Scenarios/DIF/scenarios_DIF_J7_baseline_300.do b/Scripts/Data_generation/DIF/scenarios_DIF_J7_baseline_300.do
similarity index 100%
rename from Scripts/Scenarios/DIF/scenarios_DIF_J7_baseline_300.do
rename to Scripts/Data_generation/DIF/scenarios_DIF_J7_baseline_300.do
diff --git a/Scripts/Scenarios/DIF/scenarios_DIF_J7_baseline_50.do b/Scripts/Data_generation/DIF/scenarios_DIF_J7_baseline_50.do
similarity index 100%
rename from Scripts/Scenarios/DIF/scenarios_DIF_J7_baseline_50.do
rename to Scripts/Data_generation/DIF/scenarios_DIF_J7_baseline_50.do
diff --git a/Scripts/Scenarios/NoDIF/scenarios_noDIF_baseline.do b/Scripts/Data_generation/NoDIF/scenarios_noDIF_baseline.do
similarity index 100%
rename from Scripts/Scenarios/NoDIF/scenarios_noDIF_baseline.do
rename to Scripts/Data_generation/NoDIF/scenarios_noDIF_baseline.do
diff --git a/Scripts/Scenarios/NoDIF/scenarios_noDIF_baseline_100.do b/Scripts/Data_generation/NoDIF/scenarios_noDIF_baseline_100.do
similarity index 100%
rename from Scripts/Scenarios/NoDIF/scenarios_noDIF_baseline_100.do
rename to Scripts/Data_generation/NoDIF/scenarios_noDIF_baseline_100.do
diff --git a/Scripts/Scenarios/NoDIF/scenarios_noDIF_baseline_200.do b/Scripts/Data_generation/NoDIF/scenarios_noDIF_baseline_200.do
similarity index 100%
rename from Scripts/Scenarios/NoDIF/scenarios_noDIF_baseline_200.do
rename to Scripts/Data_generation/NoDIF/scenarios_noDIF_baseline_200.do
diff --git a/Scripts/Scenarios/NoDIF/scenarios_noDIF_baseline_300.do b/Scripts/Data_generation/NoDIF/scenarios_noDIF_baseline_300.do
similarity index 100%
rename from Scripts/Scenarios/NoDIF/scenarios_noDIF_baseline_300.do
rename to Scripts/Data_generation/NoDIF/scenarios_noDIF_baseline_300.do
diff --git a/Scripts/Scenarios/NoDIF/scenarios_noDIF_baseline_50.do b/Scripts/Data_generation/NoDIF/scenarios_noDIF_baseline_50.do
similarity index 100%
rename from Scripts/Scenarios/NoDIF/scenarios_noDIF_baseline_50.do
rename to Scripts/Data_generation/NoDIF/scenarios_noDIF_baseline_50.do
diff --git a/autorun.sh b/autorun.sh
new file mode 100644
index 0000000..a3fdd35
--- /dev/null
+++ b/autorun.sh
@@ -0,0 +1,178 @@
+echo "=================================================================================================="
+echo Initializing path to code for all script files, please run this script in the /Simulations/ folder
+echo "=================================================================================================="
+
+echo Initializing data generation scripts in /Scripts/Data_generation/
+echo "..."
+sed -i "s|/home/corentin/Documents/These/Recherche/Simulations|$PWD|g" /Scripts/Data_generation/DIF/*
+sed -i "s|/home/corentin/Documents/These/Recherche/Simulations|$PWD|g" /Scripts/Data_generation/NoDIF/*
+echo DONE
+
+echo Initializing analysis scripts in /Scripts/Analysis/
+echo "..."
+sed -i "s|/home/corentin/Documents/These/Recherche/Simulations|$PWD|g" /Scripts/Analysis/DIF/*
+sed -i "s|/home/corentin/Documents/These/Recherche/Simulations|$PWD|g" /Scripts/Analysis/DIF-RESIDUALS/*
+sed -i "s|/home/corentin/Documents/These/Recherche/Simulations|$PWD|g" /Scripts/Analysis/DIF-ROSALI/*
+echo DONE
+
+echo Initializing analysis scripts in /RProject/Scripts/
+echo "..."
+sed -i "s|/home/corentin/Documents/These/Recherche/Simulations|$PWD|g" /RProject/Scripts/*
+echo DONE
+
+echo Done initializing code path, running code
+
+
+echo "=================================================================================================="
+echo Installing R package dependencies
+echo "=================================================================================================="
+
+Rscript -e 'install.packages("TAM", repos="https://cloud.r-project.org")'
+Rscript -e 'install.packages("doMC", repos="https://cloud.r-project.org")'
+Rscript -e 'install.packages("parallel", repos="https://cloud.r-project.org")'
+Rscript -e 'install.packages("pbmcapply", repos="https://cloud.r-project.org")'
+Rscript -e 'install.packages("funprog", repos="https://cloud.r-project.org")'
+Rscript -e 'install.packages("parallel", repos="https://cloud.r-project.org")'
+Rscript -e 'install.packages("pbmcapply", repos="https://cloud.r-project.org")'
+Rscript -e 'install.packages("funprog", repos="https://cloud.r-project.org")'
+Rscript -e 'install.packages("plyr", repos="https://cloud.r-project.org")'
+Rscript -e 'install.packages("dplyr", repos="https://cloud.r-project.org")'
+Rscript -e 'install.packages("readxl", repos="https://cloud.r-project.org")'
+
+echo "=================================================================================================="
+echo Running data generation
+echo "=================================================================================================="
+
+echo "--- Generating no DIF data ---"
+echo "N=50"
+echo "..."
+stata -b run /Scripts/Data_generation/NoDIF/scenarios_noDIF_baseline_50.do
+echo DONE
+
+echo "N=100"
+echo "..."
+stata -b run /Scripts/Data_generation/NoDIF/scenarios_noDIF_baseline_100.do
+echo DONE
+
+echo "N=200"
+echo "..."
+stata -b run /Scripts/Data_generation/NoDIF/scenarios_noDIF_baseline_200.do
+echo DONE
+
+echo "N=300"
+echo "..."
+stata -b run /Scripts/Data_generation/NoDIF/scenarios_noDIF_baseline_300.do
+echo DONE
+
+echo "--- Generating DIF data ---"
+echo "N=50 / J=4"
+echo "..."
+stata -b run /Scripts/Data_generation/DIF/scenarios_DIF_J4_baseline_50.do
+echo DONE
+
+echo "N=100 / J=4"
+echo "..."
+stata -b run /Scripts/Data_generation/DIF/scenarios_DIF_J4_baseline_100.do
+echo DONE
+
+echo "N=200 / J=4"
+echo "..."
+stata -b run /Scripts/Data_generation/DIF/scenarios_DIF_J4_baseline_200.do
+echo DONE
+
+echo "N=300 / J=4"
+echo "..."
+stata -b run /Scripts/Data_generation/DIF/scenarios_DIF_J4_baseline_300.do
+echo DONE
+
+echo "N=50 / J=7"
+echo "..."
+stata -b run /Scripts/Data_generation/DIF/scenarios_DIF_J7_baseline_50.do
+echo DONE
+
+echo "N=100 / J=7"
+echo "..."
+stata -b run /Scripts/Data_generation/DIF/scenarios_DIF_J7_baseline_100.do
+echo DONE
+
+echo "N=200 / J=7"
+echo "..."
+stata -b run /Scripts/Data_generation/DIF/scenarios_DIF_J7_baseline_200.do
+echo DONE
+
+echo "N=300 / J=7"
+echo "..."
+stata -b run /Scripts/Data_generation/DIF/scenarios_DIF_J7_baseline_300.do
+echo DONE
+
+
+
+echo "=================================================================================================="
+echo Running no DIF PCM analysis
+echo "=================================================================================================="
+
+cd RProject/Scripts/Analysis
+
+echo "..."
+Rscript pcm_nodif.R
+echo DONE
+
+cd -
+
+
+echo "=================================================================================================="
+echo Running DIF PCM analysis
+echo "=================================================================================================="
+
+echo "N=50 / J=4"
+echo "..."
+stata -b run /Scripts/Analysis/DIF/pcm_dif_50_J4.do
+echo DONE
+
+echo "N=50 / J=7"
+echo "..."
+stata -b run /Scripts/Analysis/DIF/pcm_dif_50_J7.do
+echo DONE
+
+echo "All others"
+echo "WARNING: This will take a few hours."
+echo "..."
+stata -b run /Scripts/Analysis/DIF/pcm_dif.do
+echo DONE
+
+
+echo "=================================================================================================="
+echo Running ROSALI DIF PCM analysis
+echo "=================================================================================================="
+
+echo "WARNING: This will take a long time (multiple weeks). Please modify the code to run multiple simultaneous sessions of stata to compute faster if necessary."
+echo "..."
+stata -b run /Scripts/Analysis/DIF-ROSALI/pcm_dif_rosali.do
+echo DONE
+
+
+echo "=================================================================================================="
+echo Running RESIDUALS DIF PCM analysis
+echo "=================================================================================================="
+
+cd RProject/Scripts/Analysis
+
+echo "Performing DIF detection"
+echo "WARNING: This will take a few hours."
+echo "..."
+Rscript resali_analysis.R
+echo DONE
+
+cd -
+
+echo "Fitting PCM models"
+echo "WARNING: This will take a few hours."
+echo "..."
+stata -b run /Scripts/Analysis/DIF-RESIDUALS/pcm_dif_residus.do
+echo DONE
+
+echo "=================================================================================================="
+echo END OF SCRIPT
+echo "=================================================================================================="
+
+echo "Run /RProject/Scripts/Analysis/aggregation.R to aggregate and access results"
diff --git a/catalogue.md b/catalogue.md
index 7fe0a0a..310dbfc 100644
--- a/catalogue.md
+++ b/catalogue.md
@@ -1,6 +1,6 @@
-# Scenarios sans confusion
+# Scenario catalogue
-## Scenarios sans DIF
+## Scenarios without DIF
| | **J** | | **M** | |
| -------------- | ----- | ----- | ----- | ----- |
@@ -10,17 +10,17 @@
| **Scenario 3** | | X | X | |
| **Scenario 4** | | X | | X |
-Chaque scénario est séparé en 5 sous-scénarios:
+Each scenario has 5 subscenarios:
-- A - H0 vraie
-- B - H1 vraie, taille d'effet 0.2
-- C - H1 vraie, taille d'effet 0.4
-- D - H1 vraie, taille d'effet -0.2
-- E - H1 vraie, taille d'effet -0.4
+- A - H0 true
+- B - H1 true, effect size 0.2
+- C - H1 true, effect size 0.4
+- D - H1 true, effect size -0.2
+- E - H1 true, effect size -0.4
-## Scenarios avec DIF
+## Scenarios with DIF
-| | **J** | | **M** | | **Nb items DIF** | | | **Taille DIF** | |
+| | **J** | | **M** | | **Nb items DIF** | | | **DIF size** | |
| --------------- | ----- | ----- | ----- | ----- | ---------------- | ----- | ----- | -------------- | ------- |
| | **4** | **7** | **2** | **4** | **1** | **2** | **3** | **0.3** | **0.5** |
| **Scenario 5** | X | | X | | X | | | X | |
@@ -40,71 +40,19 @@ Chaque scénario est séparé en 5 sous-scénarios:
| **Scenario 19** | | X | X | | | | X | | X |
| **Scenario 20** | | X | | X | | | X | | X |
-Chaque scénario est séparé en 7 sous-scénarios:
-
-- A - H0 vraie, DIF -0.3/0.5 sur le groupe **traitement**
- - **Exemple MPR / réadaptation:**
-- B - H1 vraie, taille d'effet 0.2, DIF +0.3/0.5 sur le groupe traitement
- - **Exemple BDI**
-- C - H1 vraie, taille d'effet 0.2, DIF -0.3/0.5 sur le groupe traitement
- - **Exemple dentaire**
-- D - H1 vraie, taille d'effet 0.4, DIF +0.3/0.5 sur le groupe traitement
- - **Exemple BDI**
-- E - H1 vraie, taille d'effet 0.4, DIF -0.3/0.5 sur le groupe traitement
- - **Exemple dentaire**
-- F - H1 vraie, taille d'effet -0.2, DIF -0.3/0.5 sur le groupe traitement
- - **Exemple cancéro / effets secondaires**
-- G - H1 vraie, taille d'effet -0.4, DIF -0.3/0.5 sur le groupe traitement
- - **Exemple cancéro / effets secondaires**
-
-# Scenarios avec confusion sur 1 variable
-
-## Scenarios sans DIF
-
- | | **J** | | **M** | |
- | -------------- | ----- | ----- | ----- | ----- |
- | | **4** | **7** | **2** | **4** |
- | **Scenario 101** | X | | X | |
- | **Scenario 102** | X | | | X |
- | **Scenario 103** | | X | X | |
- | **Scenario 104** | | X | | X |
-
- Chaque scénario est séparé en 5 sous-scénarios:
-
- - A - H0 vraie
- - B - H1 vraie, taille d'effet 0.2
- - C - H1 vraie, taille d'effet 0.4
- - D - H1 vraie, taille d'effet -0.2
- - E - H1 vraie, taille d'effet -0.4
-
-## Scenarios avec DIF
-
- | | **J** | | **M** | | **Nb items DIF** | | | **Taille DIF** | |
- | --------------- | ----- | ----- | ----- | ----- | ---------------- | ----- | ----- | -------------- | ------- |
- | | **4** | **7** | **2** | **4** | **1** | **2** | **3** | **0.3** | **0.5** |
- | **Scenario 105** | X | | X | | X | | | X | |
- | **Scenario 106** | X | | | X | X | | | X | |
- | **Scenario 107** | X | | X | | X | | | | X |
- | **Scenario 108** | X | | | X | X | | | | X |
- | **Scenario 109** | X | | X | | | X | | X | |
- | **Scenario 110** | X | | | X | | X | | X | |
- | **Scenario 111** | X | | X | | | X | | | X |
- | **Scenario 112** | X | | | X | | X | | | X |
- | **Scenario 113** | | X | X | | | X | | X | |
- | **Scenario 114** | | X | | X | | X | | X | |
- | **Scenario 115** | | X | X | | | X | | | X |
- | **Scenario 116** | | X | | X | | X | | | X |
- | **Scenario 117** | | X | X | | | | X | X | |
- | **Scenario 118** | | X | | X | | | X | X | |
- | **Scenario 119** | | X | X | | | | X | | X |
- | **Scenario 120** | | X | | X | | | X | | X |
-
- Chaque scénario est séparé en 7 sous-scénarios:
-
- - A - H0 vraie, DIF -0.3/0.5 sur le groupe **traitement**
- - B - H1 vraie, taille d'effet 0.2, DIF +0.3/0.5 sur le groupe traitement
- - C - H1 vraie, taille d'effet 0.2, DIF -0.3/0.5 sur le groupe traitement
- - D - H1 vraie, taille d'effet 0.4, DIF +0.3/0.5 sur le groupe traitement
- - E - H1 vraie, taille d'effet 0.4, DIF -0.3/0.5 sur le groupe traitement
- - F - H1 vraie, taille d'effet -0.2, DIF -0.3/0.5 sur le groupe traitement
- - G - H1 vraie, taille d'effet -0.4, DIF -0.3/0.5 sur le groupe traitement
+Each scenario has 7 subscenarios:
+
+- A - H0 true, DIF -0.3/0.5 on traitement group
+ - **MPR example**
+- B - H1 true, effect size 0.2, DIF +0.3/0.5 on traitement group
+ - **BDI example**
+- C - H1 true, effect size 0.2, DIF -0.3/0.5 on traitement group
+ - **Dentistry example**
+- D - H1 true, effect size 0.4, DIF +0.3/0.5 on traitement group
+ - **BDI example**
+- E - H1 true, effect size 0.4, DIF -0.3/0.5 on traitement group
+ - **Dentistry example**
+- F - H1 true, effect size -0.2, DIF -0.3/0.5 on traitement group
+ - **Adverse effects example**
+- G - H1 true, effect size -0.4, DIF -0.3/0.5 on traitement group
+ - **Adverse effects example**