Corrected code for getting logs

main
Corentin Choisy 8 months ago
parent 65f2a62ba8
commit 047b6bb04a

@ -760,6 +760,113 @@ if "`group'"!="" & "`nodif'"=="" { // PARTIE 1 = Slmt si option group & pas de "
//Variance et se mA //Variance et se mA
matrix var_mA = (val_mA[1,"/var(THETA)#0bn.`gp'"]\val_mA[2,"/var(THETA)#0bn.`gp'"]) matrix var_mA = (val_mA[1,"/var(THETA)#0bn.`gp'"]\val_mA[2,"/var(THETA)#0bn.`gp'"])
*************************************************************
***********************AFFICHAGE*****************************
*************************************************************
//Affichage modèle A
di
di as input "PROCESSING STEP A"
di
if "`detail'" != "" {
/* Affichage des estimations des difficultés modèle A */
di _col(5) as text "{ul:MODEL A:} Overall measurement non-invariance between groups"
di
di %~85s as text "Item difficulties: estimates (s.e.)"
di _col(10) "{hline 65}"
di _col(31) as text abbrev("`gp'",20) "=0" _col(57) abbrev("`gp'",20) "=1"
di _col(10) "{hline 65}"
forvalues j=1/`nbitems' {
di as text _col(10) abbrev("``j''", 18)
forvalues p=1/`nbdif_`j'' {
di as text _col(10) "`p'" as result _col(30) %6.2f `delta`j'_`p'g0mA' %6.2f " (" %3.2f `delta`j'_`p'g0mA_se' ")" _col(56) %6.2f `delta`j'_`p'g1mA' " (" %3.2f `delta`j'_`p'g1mA_se' ")"
}
}
di as text _col(10) "{hline 65}"
/* Affichage des estimations sur le trait latent du modèle A */
di
di %~85s as text "Latent trait distribution"
di _col(10) "{hline 65}"
di _col(31) "Estimate" _col(57) "Standard error"
di _col(10) "{hline 65}"
di _col(10) "Variance" as result _col(31) %6.2f `=var_mA[1,1]' _col(55) %6.2f `=var_mA[2,1]'
di _col(10) as text "Group effect" as result _col(31) "0 (constrained)"
di _col(10) as text "{hline 65}"
di
di _col(10) as text "No group effect: equality of the latent trait means between groups"
di _col(10) as text "All item difficulties are freely estimated in both groups"
di
}
//*Affichage modèle B
di
di as input "PROCESSING STEP B"
di
/* Affichage des estimations des difficultés modèle B */
if "`detail'" != "" {
di _col(5) as text "{ul:MODEL B:} Overall measurement invariance between groups"
di
di %~85s as text "Item difficulties: estimates (s.e.)"
di _col(10) "{hline 65}"
di _col(31) abbrev("`gp'",20) "=0" _col(57) abbrev("`gp'",20) "=1"
di _col(10) "{hline 65}"
forvalues j=1/`nbitems' {
di _col(10) as text "``j''"
forvalues p=1/`nbdif_`j'' {
di as text _col(10) "`p'" as result _col(30) %6.2f `delta`j'_`p'g0mB' " (" %3.2f `delta`j'_`p'g0mB_se' ")" _col(56) %6.2f `delta`j'_`p'g1mB' " (" %3.2f `delta`j'_`p'g1mB_se' ")"
}
}
di _col(10) as text "{hline 65}"
/* Affichage des estimations sur le trait latent du modèle B */
di
di %~85s as text "Latent trait distribution"
di _col(10) "{hline 65}"
di _col(28) "Estimate" _col(42) "Standard error" _col(62) "P-value"
di _col(10) "{hline 65}"
di _col(10) "Variance" as result _col(28) %6.2f `=var_mB[1,1]' _col(40) %6.2f `=var_mB[2,1]'
di _col(10) as text "Group effect" as result _col(28) %6.2f `geffmB' _col(40) %6.2f `segeffmB' _col(62) %6.4f `gcmBp'
di _col(10) as text "{hline 65}"
di
di _col(10) as text "Group effect estimated: mean of the latent trait of group 1 freely estimated"
di _col(10) "Equality of the item difficulties between groups"
di
}
*****************************************************
* Modèle A vs Modèle B *
*****************************************************
qui lrtest modeldifA modeldifB
local diftestp=r(p)
local diftestchi=r(chi2)
local diftestdf=r(df)
//affichage lrtest
di as input "LIKELIHOOD-RATIO TEST"
di
di %~60s "Model A vs Model B"
di _col(10) "{hline 40}"
di _col(10) as text "Chi-square" _col(28) "DF" _col(40) "P-value"
di _col(10) as result %6.2f `diftestchi' _col(28) %2.0f `diftestdf' _col(40) %6.4f `diftestp'
di _col(10) as text "{hline 40}"
di
if `diftestp'<0.05{
di as result "DIFFERENCE IN ITEM DIFFICULTIES BETWEEN GROUPS LIKELY"
}
else{
di as result "NO DIFFERENCE BETWEEN GROUPS DETECTED"
}
********************************* *********************************
*************MODEL C************* *************MODEL C*************
********************************* *********************************
@ -787,15 +894,12 @@ if "`group'"!="" & "`nodif'"=="" { // PARTIE 1 = Slmt si option group & pas de "
local nbsig=0 local nbsig=0
local minpval=1 local minpval=1
local itemdif=0 local itemdif=0
if "`detail'" != ""{
di as text "Loop `boucle'" di as text "Loop `boucle'"
di as text _col(5) "Adjusted alpha: " %6.4f `pajust' di as text _col(5) "Adjusted alpha: " %6.4f `pajust'
di di
di as text _col(10) "{hline 65}" di as text _col(10) "{hline 65}"
di as text _col(10) "Freed item" _col(31) "Chi-Square" _col(48) "DF" _col(57) "P-Value" di as text _col(10) "Freed item" _col(31) "Chi-Square" _col(48) "DF" _col(57) "P-Value"
di as text _col(10) "{hline 65}" di as text _col(10) "{hline 65}"
}
/*boucle de test*/ /*boucle de test*/
forvalues j=1/`nbitems'{ forvalues j=1/`nbitems'{
//if `nbdif_`j'' > 2 { //if `nbdif_`j'' > 2 {
@ -856,40 +960,32 @@ if "`group'"!="" & "`nodif'"=="" { // PARTIE 1 = Slmt si option group & pas de "
local itemdif=`j' local itemdif=`j'
} }
} }
if "`detail'" != "" {
di as text _col(10) abbrev("``j''",15) as result _col(31) %6.3f test_dif_`boucle'[`j',1] _col(48) test_dif_`boucle'[`j',2] _col(57) %6.4f test_dif_`boucle'[`j',3] di as text _col(10) abbrev("``j''",15) as result _col(31) %6.3f test_dif_`boucle'[`j',1] _col(48) test_dif_`boucle'[`j',2] _col(57) %6.4f test_dif_`boucle'[`j',3]
}
} }
} }
/*si nb de tests significatifs=0, on arrête*/ /*si nb de tests significatifs=0, on arrête*/
if `nbsig'==0{ if `nbsig'==0{
local stop=1 local stop=1
if `boucle' == 1 { if `boucle' == 1 {
if "`detail'" != "" {
di as text _col(10) "{hline 65}" di as text _col(10) "{hline 65}"
di di
di as result "No significant test: no difference between groups detected, no DIF detected" di as result "No significant test: no difference between groups detected, no DIF detected"
di di
}
} }
else { else {
if "`detail'" != ""{
di as text _col(10) "{hline 65}" di as text _col(10) "{hline 65}"
di di
di as result "No other significant tests" di as result "No other significant tests"
di di
}
} }
} }
else{/*si nb de tests significatifs>0, mise à jour de la matrice de résultats*/ else{/*si nb de tests significatifs>0, mise à jour de la matrice de résultats*/
matrix dif_rc[`itemdif',1]=`boucle' matrix dif_rc[`itemdif',1]=`boucle'
if "`detail'" != ""{
di as text _col(10) "{hline 65}" di as text _col(10) "{hline 65}"
di di
di as result "Difference between groups on ``itemdif'' at time 1" di as result "Difference between groups on ``itemdif'' at time 1"
}
if `nbmoda_`itemdif'' > 2 { if `nbmoda_`itemdif'' > 2 {
if "`detail'" != "" {
di di
di %~60s as text "Test of uniform difference" di %~60s as text "Test of uniform difference"
@ -897,7 +993,7 @@ if "`group'"!="" & "`nodif'"=="" { // PARTIE 1 = Slmt si option group & pas de "
di _col(10) as text "Chi-square" _col(28) "DF" _col(40) "P-value" di _col(10) as text "Chi-square" _col(28) "DF" _col(40) "P-value"
di _col(10) as result %4.2f `=test_difu_`boucle'[`itemdif',1]' _col(28) `=test_difu_`boucle'[`itemdif',2]' _col(40) %4.2f `=test_difu_`boucle'[`itemdif',3]' di _col(10) as result %4.2f `=test_difu_`boucle'[`itemdif',1]' _col(28) `=test_difu_`boucle'[`itemdif',2]' _col(40) %4.2f `=test_difu_`boucle'[`itemdif',3]'
di _col(10) as text "{hline 40}" di _col(10) as text "{hline 40}"
}
if test_difu_`boucle'[`itemdif',3]<0.05{ /*DIF NU détectée*/ if test_difu_`boucle'[`itemdif',3]<0.05{ /*DIF NU détectée*/
matrix dif_rc[`itemdif',2]=0 matrix dif_rc[`itemdif',2]=0
di di

@ -8,11 +8,11 @@
* *
* *
*================================================================================================================================================ *================================================================================================================================================
adopath+"/home/corentin/Documents/These/Recherche/ROSALI-SIM/Modules/rosali_custom" adopath+"/home/corentin/Documents/These/Recherche/Simulations/Modules/rosali_custom"
local N = "50 100 200 300" local N = "50 100 200 300"
local ss = "1 2 3 4 5 6 7 8 9 10 11 1 13 14 15 16 17 18 19 20" local ss = "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20"
foreach s in `ss' { foreach s in `ss' {
foreach Nnn in `N' { foreach Nnn in `N' {
local Nn = `Nnn' local Nn = `Nnn'
@ -21,6 +21,7 @@ local N = "50 100 200 300"
local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N`Nn'" 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 path_res = "/home/corentin/Documents/These/Recherche/Simulations/Analysis/ROSALI-DIF/N`Nn'"
local path_log = "/home/corentin/Documents/These/Recherche/Simulations/Analysis/ROSALI-DIF/log/"
local scenarios = "A B C D E F G" local scenarios = "A B C D E F G"
if (`s' <= 4) { if (`s' <= 4) {
local scenarios = "A B C D E" local scenarios = "A B C D E"
@ -29,7 +30,7 @@ local N = "50 100 200 300"
clear clear
import delim "`path_data'/scenario_`s'`scen'_`Nn'.csv", encoding(ISO-8859-2) case(preserve) clear import delim "`path_data'/scenario_`s'`scen'_`Nn'.csv", encoding(ISO-8859-2) case(preserve) clear
rename TT tt rename TT tt
log using "`path_log'/log_`s'`scen'_`Nn'.log", replace
if (`s'<=2) { if (`s'<=2) {
local nbitems=4 local nbitems=4
} }
@ -63,9 +64,9 @@ local N = "50 100 200 300"
local nbdif=3 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 * 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+1
if (mod(`s',2)==0) { if (mod(`s',2)==0) {
local taillemat=2*`nbitems'*`nbmoda'+`nbitems'+`nbitems'+`nbdif'+2 local taillemat=2*`nbitems'*`nbmoda'+`nbitems'+`nbitems'+`nbdif'+2+1
} }
local colna="" local colna=""
forvalues i=1/`nbitems' { forvalues i=1/`nbitems' {
@ -86,16 +87,20 @@ local N = "50 100 200 300"
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 " + "lrt_passed"
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'"
forvalues k=1/1000 { forvalues k=1/10 {
if (mod(`k',100)==0) { di "###################################################################################"
di "`k'/1000" di "###################################################################################"
} di "###################################################################################"
di "Scenario `s'`scen' N=`Nn' ########## `k'/1000"
di "###################################################################################"
di "###################################################################################"
di "###################################################################################"
preserve preserve
qui keep if replication==`k' qui keep if replication==`k'
@ -253,10 +258,10 @@ local N = "50 100 200 300"
* ROSALI * ROSALI
qui rosali_original item1-item`nbitems' item1-item`nbitems', group(tt) rosali_original item1-item`nbitems' item1-item`nbitems', group(tt)
qui mat resmat=r(difitems) qui mat resmat=r(difitems)
local nbitems2 = 2*`nbitems' local nbitems2 = 2*`nbitems'
mat lrt_passed = resmat[1,`nbitems2'+1]
* 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
@ -329,7 +334,7 @@ local N = "50 100 200 300"
local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent" local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent"
} }
*calcul du modèle *calcul du modèle
qui `mod' `mod'
mat V=r(table) mat V=r(table)
mat W=V[1..2,1...] mat W=V[1..2,1...]
@ -372,8 +377,10 @@ local N = "50 100 200 300"
} }
qui mat outmat[`k',colnumb(outmat,"beta")]=W[1,colnumb(W,"THETA:tt")] qui mat outmat[`k',colnumb(outmat,"beta")]=W[1,colnumb(W,"THETA:tt")]
qui mat outmat[`k',colnumb(outmat,"se_beta")]=W[2,colnumb(W,"THETA:tt")] qui mat outmat[`k',colnumb(outmat,"se_beta")]=W[2,colnumb(W,"THETA:tt")]
qui mat outmat[`k',colnumb(outmat,"lrt_passed")]=lrt_passed[1,1]
restore restore
} }
log close
putexcel set "`path_res'/`s'`scen'_`Nn'_original.xls", sheet("outmat") replace putexcel set "`path_res'/`s'`scen'_`Nn'_original.xls", sheet("outmat") replace
putexcel A1=matrix(outmat), colnames putexcel A1=matrix(outmat), colnames
} }

Loading…
Cancel
Save