RESALI script ready

main
Corentin Choisy 8 months ago
parent 1efe30e6e3
commit 2d778f2362

@ -16,7 +16,7 @@ results <- c(results,results2)
## Importer l'analyse resali pour chaque scenario ## Importer l'analyse resali pour chaque scenario
for (r in results[21:length(results)]) { for (r in results) {
cat('--------------------------------------------------------------------------\n') cat('--------------------------------------------------------------------------\n')
cat(paste0(r,"\n")) cat(paste0(r,"\n"))
cat('--------------------------------------------------------------------------\n') cat('--------------------------------------------------------------------------\n')
@ -82,3 +82,67 @@ for (r in results[21:length(results)]) {
} }
write.csv(datt,paste0("/home/corentin/Documents/These/Recherche/Simulations/Analysis/RESALI/Detection_data/",r,".csv")) write.csv(datt,paste0("/home/corentin/Documents/These/Recherche/Simulations/Analysis/RESALI/Detection_data/",r,".csv"))
} }
for (r in results) {
cat('--------------------------------------------------------------------------\n')
cat(paste0(r,"\n"))
cat('--------------------------------------------------------------------------\n')
#### Importer les datas
scen <- as.numeric(gsub("[A,B,C,D,E,F,G,_]","",substr(r,0,3)))
if (substr(r,start=nchar(r)-1,stop=nchar(r))=="50") {
N <- 50
}
if (substr(r,start=nchar(r)-2,stop=nchar(r))=="100") {
N <- 100
}
if (substr(r,start=nchar(r)-2,stop=nchar(r))=="200") {
N <- 200
}
if (substr(r,start=nchar(r)-2,stop=nchar(r))=="300") {
N <- 300
}
#### Importer l'analyse
analyse <- read.csv(paste0("/home/corentin/Documents/These/Recherche/Simulations/Analysis/RESALI/Detection_data/",r,".csv"))
analyse[is.na(analyse)] <- ""
names(analyse)[names(analyse)=="dif.detect.1"] <- "dif_detect_1"
names(analyse)[names(analyse)=="dif.detect.2"] <- "dif_detect_2"
names(analyse)[names(analyse)=="dif.detect.3"] <- "dif_detect_3"
names(analyse)[names(analyse)=="dif.detect.4"] <- "dif_detect_4"
names(analyse)[names(analyse)=="dif.detect.unif.1"] <- "dif_detect_unif_1"
names(analyse)[names(analyse)=="dif.detect.unif.2"] <- "dif_detect_unif_2"
names(analyse)[names(analyse)=="dif.detect.unif.3"] <- "dif_detect_unif_3"
names(analyse)[names(analyse)=="dif.detect.unif.4"] <- "dif_detect_unif_4"
analyse[analyse$dif_detect_1==999,"dif_detect_1"] <- ""
analyse[analyse$dif_detect_2==999,"dif_detect_2"] <- ""
analyse[analyse$dif_detect_3==999,"dif_detect_3"] <- ""
analyse[analyse$dif_detect_4==999,"dif_detect_4"] <- ""
analyse[analyse$dif_detect_unif_1==999,"dif_detect_unif_1"] <- ""
analyse[analyse$dif_detect_unif_2==999,"dif_detect_unif_2"] <- ""
analyse[analyse$dif_detect_unif_3==999,"dif_detect_unif_3"] <- ""
analyse[analyse$dif_detect_unif_4==999,"dif_detect_unif_4"] <- ""
if (scen==3 | scen==4 | scen>=13) {
names(analyse)[names(analyse)=="dif.detect.5"] <- "dif_detect_5"
names(analyse)[names(analyse)=="dif.detect.6"] <- "dif_detect_6"
names(analyse)[names(analyse)=="dif.detect.7"] <- "dif_detect_7"
names(analyse)[names(analyse)=="dif.detect.unif.5"] <- "dif_detect_unif_5"
names(analyse)[names(analyse)=="dif.detect.unif.6"] <- "dif_detect_unif_6"
names(analyse)[names(analyse)=="dif.detect.unif.7"] <- "dif_detect_unif_7"
analyse[analyse$dif_detect_5==999,"dif_detect_5"] <- ""
analyse[analyse$dif_detect_6==999,"dif_detect_6"] <- ""
analyse[analyse$dif_detect_7==999,"dif_detect_7"] <- ""
analyse[analyse$dif_detect_unif_5==999,"dif_detect_unif_5"] <- ""
analyse[analyse$dif_detect_unif_6==999,"dif_detect_unif_6"] <- ""
analyse[analyse$dif_detect_unif_7==999,"dif_detect_unif_7"] <- ""
}
analyse <- analyse[,!names(analyse) %in% c("X","X.1","X.2")]
write.csv(analyse,paste0("/home/corentin/Documents/These/Recherche/Simulations/Analysis/RESALI/Detection_data/",r,".csv"))
}

@ -24,7 +24,7 @@ local N = "50 100 200 300"
} }
foreach scen in `scenarios' { foreach scen in `scenarios' {
clear clear
import delim "`path_data'/scenario_`s'`scen'_`Nn'.csv", encoding(ISO-8859-2) case(preserve) clear import delim "`path_data'/`s'`scen'_`Nn'.csv", encoding(ISO-8859-2) case(preserve) clear
rename TT tt rename TT tt
if (`s'<=2) { if (`s'<=2) {
@ -61,6 +61,9 @@ local N = "50 100 200 300"
} }
* 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 * 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 taillemat=2*`nbitems'*`nbmoda'+`nbitems'+`nbdif'+2
if (mod(`s',2)==0) {
local taillemat=2*`nbitems'*`nbmoda'+`nbitems'+`nbitems'+`nbdif'+2
}
local colna="" local colna=""
forvalues i=1/`nbitems' { forvalues i=1/`nbitems' {
forvalues z=1/`nbmoda' { forvalues z=1/`nbmoda' {
@ -69,15 +72,18 @@ local N = "50 100 200 300"
} }
} }
forvalues i=1/`nbitems' { forvalues i=1/`nbitems' {
local colna = "`colna'"+"dif_detect_`i' " 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' { forvalues i=1/`nbdif' {
local colna = "`colna'"+"real_dif_`i' " local colna = "`colna'"+"real_dif_`i' "
} }
local colna = "`colna'" + "beta " + "se_beta" local colna = "`colna'" + "beta " + "se_beta"
mat outmat = J(1000,`taillemat',.) mat outmat = J(1000,`taillemat',.)
mat colnames outmat= `colna' mat colnames outmat= `colna'
di "Scenario `s'`scen' / N=`Nnn'" di "Scenario `s'`scen' / N=`Nnn'"
@ -213,7 +219,7 @@ local N = "50 100 200 300"
local checker2: word 2 of `val' local checker2: word 2 of `val'
local checker3: word 3 of `val' local checker3: word 3 of `val'
local nummoda=r(r) local nummoda=r(r)
local nbmoda_`j'=`nummoda' local nbmoda_`j'=`nummoda'-1
if (`nummoda'==2) { if (`nummoda'==2) {
qui recode item`j' (`checker'=0) (`checker2'=1) qui recode item`j' (`checker'=0) (`checker2'=1)
} }
@ -239,46 +245,45 @@ local N = "50 100 200 300"
local nbmoda_`jj'=`nbmoda' 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' local nbitems2 = 2*`nbitems'
* Calculer le nbre d'items détectés * Calculer le nbre d'items détectés
local nbdetect = 0 local nbdetect = 0
local stop = 0 local stop = 0
forvalues jj=1/`nbitems' { forvalues jj=1/`nbitems' {
qui levelsof dif_detect_`jj'
local detected=r(levels)
if (`stop'==0) { if (`stop'==0) {
mat testm=J(1,1,.) mat testm=J(1,1,.)
if (resmat[1,`jj']==testm[1,1]) { if (`detected'==testm[1,1]) {
local stop = 1 local stop = 1
local nbdetect = `jj'-1 local nbdetect = `jj'-1
} }
} }
} }
* Stocker les items détectés + * Stocker les items détectés +
* Définition des contraintes * Définition des contraintes
local csrt=0 local csrt=0
mat testm=J(1,1,0) mat testm=J(1,1,0)
forvalues u=1/`nbdetect' { forvalues u=1/`nbdetect' {
local difitems`u'=resmat[1,`u'] qui levelsof dif_detect_`u'
local detected=r(levels)
local difitems`u'=`detected'
local i=`difitems`u'' local i=`difitems`u''
if (`nbmoda_`i''==3 & resmat[1,`nbitems'+`i']!=testm[1,1]){ qui levelsof dif_detect_unif_`u'
local detected_unif=r(levels)
if (`nbmoda_`i''==3 & `detected_unif'!=testm[1,1]){
local constrnt`u' = "constraint `u' 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))" 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'' qui `constrnt`u''
local v=`u'+100 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))" 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' qui `constrnt`u'_2'
} }
if (`nbmoda_`i''==2 & resmat[1,`nbitems'+`i']!=testm[1,1]){ if (`nbmoda_`i''==2 & `detected_unif'!=testm[1,1]){
local constrnt`u' = "constraint `u' 2*([1.item`i']_cons-([1.item`i']_cons+[1.item`i'] tt))=([2.item`i']_cons-([2.item`i']_cons+[2.item`i'] tt))" 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'' qui `constrnt`u''
} }
} }
* Définition du modèle * Définition du modèle
local mod "gsem " local mod "gsem "
local conformula = "" local conformula = ""
@ -301,10 +306,13 @@ local N = "50 100 200 300"
local mod = "`mod'"+"(2.item`v'<-THETA@2 tt)" local mod = "`mod'"+"(2.item`v'<-THETA@2 tt)"
} }
local w= 100+`u' local w= 100+`u'
if (resmat[1,`nbitems'+`v']!=testm[1,1] & `nbmoda_`v''==3) { qui levelsof dif_detect_unif_`u'
local detected=r(levels)
local unif_`u'=r(levels)
if (`detected'!=testm[1,1] & `nbmoda_`v''==3) {
local conformula = "`conformula'" + "`u' " + "`w' " local conformula = "`conformula'" + "`u' " + "`w' "
} }
else if (resmat[1,`nbitems'+`v']!=testm[1,1] & `nbmoda_`v''==2) { else if (`detected'!=testm[1,1] & `nbmoda_`v''==2) {
local conformula = "`conformula'" + "`u' " local conformula = "`conformula'" + "`u' "
} }
} }
@ -325,15 +333,18 @@ local N = "50 100 200 300"
mat outmat[`k',colnumb(outmat,"item`j'_`z'")] = W[1,colnumb(W,"`z'.item`j':_cons")] mat outmat[`k',colnumb(outmat,"item`j'_`z'")] = W[1,colnumb(W,"`z'.item`j':_cons")]
} }
} }
* compilation DIF * compilation DIF
forvalues u=1/`nbdetect' { forvalues u=1/`nbdetect' {
local j=`difitems`u'' local j=`difitems`u''
forvalues z=1/`nbmoda_`j'' { 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_`u'_`z'")] = W[1,colnumb(W,"`z'.item`j':tt")]
mat outmat[`k',colnumb(outmat,"dif_detect_`u'")] = `j' }
mat outmat[`k',colnumb(outmat,"dif_detect_`u'")] = `j'
if (mod(`s',2)==0) {
mat outmat[`k',colnumb(outmat,"dif_detect_unif_`u'")] = `unif_`j''
} }
} }
* Stocker les items de DIF originaux * Stocker les items de DIF originaux
if (`nbdif' > 0) { if (`nbdif' > 0) {
qui levelsof dif1 qui levelsof dif1

Loading…
Cancel
Save