From 047b6bb04a4d932402fd016eddbfc75de2946c32 Mon Sep 17 00:00:00 2001 From: corentinchoisy Date: Thu, 25 Apr 2024 18:32:02 +0200 Subject: [PATCH] Corrected code for getting logs --- Modules/rosali_custom/rosali_original.ado | 122 ++++++++++++++++-- Scripts/Analysis/DIF-ROSALI/pcm_dif_rosali.do | 35 +++-- 2 files changed, 130 insertions(+), 27 deletions(-) diff --git a/Modules/rosali_custom/rosali_original.ado b/Modules/rosali_custom/rosali_original.ado index a864920..4ac0b30 100644 --- a/Modules/rosali_custom/rosali_original.ado +++ b/Modules/rosali_custom/rosali_original.ado @@ -760,6 +760,113 @@ if "`group'"!="" & "`nodif'"=="" { // PARTIE 1 = Slmt si option group & pas de " //Variance et se mA 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************* ********************************* @@ -787,15 +894,12 @@ if "`group'"!="" & "`nodif'"=="" { // PARTIE 1 = Slmt si option group & pas de " local nbsig=0 local minpval=1 local itemdif=0 - if "`detail'" != ""{ - di as text "Loop `boucle'" di as text _col(5) "Adjusted alpha: " %6.4f `pajust' di 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) "{hline 65}" - } /*boucle de test*/ forvalues j=1/`nbitems'{ //if `nbdif_`j'' > 2 { @@ -856,40 +960,32 @@ if "`group'"!="" & "`nodif'"=="" { // PARTIE 1 = Slmt si option group & pas de " 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] - } + } } /*si nb de tests significatifs=0, on arrête*/ if `nbsig'==0{ local stop=1 if `boucle' == 1 { - if "`detail'" != "" { di as text _col(10) "{hline 65}" di di as result "No significant test: no difference between groups detected, no DIF detected" di - } } else { - if "`detail'" != ""{ di as text _col(10) "{hline 65}" di di as result "No other significant tests" di - } } } else{/*si nb de tests significatifs>0, mise à jour de la matrice de résultats*/ matrix dif_rc[`itemdif',1]=`boucle' - if "`detail'" != ""{ di as text _col(10) "{hline 65}" di di as result "Difference between groups on ``itemdif'' at time 1" - } if `nbmoda_`itemdif'' > 2 { - if "`detail'" != "" { di 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 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}" - } + if test_difu_`boucle'[`itemdif',3]<0.05{ /*DIF NU détectée*/ matrix dif_rc[`itemdif',2]=0 di diff --git a/Scripts/Analysis/DIF-ROSALI/pcm_dif_rosali.do b/Scripts/Analysis/DIF-ROSALI/pcm_dif_rosali.do index 3e52f18..e40cc48 100644 --- a/Scripts/Analysis/DIF-ROSALI/pcm_dif_rosali.do +++ b/Scripts/Analysis/DIF-ROSALI/pcm_dif_rosali.do @@ -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 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 Nnn in `N' { 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_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" if (`s' <= 4) { local scenarios = "A B C D E" @@ -29,7 +30,7 @@ local N = "50 100 200 300" clear import delim "`path_data'/scenario_`s'`scen'_`Nn'.csv", encoding(ISO-8859-2) case(preserve) clear rename TT tt - + log using "`path_log'/log_`s'`scen'_`Nn'.log", replace if (`s'<=2) { local nbitems=4 } @@ -63,9 +64,9 @@ local N = "50 100 200 300" 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 taillemat=2*`nbitems'*`nbmoda'+`nbitems'+`nbdif'+2+1 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="" forvalues i=1/`nbitems' { @@ -86,16 +87,20 @@ local N = "50 100 200 300" forvalues i=1/`nbdif' { 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 colnames outmat= `colna' di "Scenario `s'`scen' / N=`Nnn'" - forvalues k=1/1000 { - if (mod(`k',100)==0) { - di "`k'/1000" - } + forvalues k=1/10 { + di "###################################################################################" + di "###################################################################################" + di "###################################################################################" + di "Scenario `s'`scen' N=`Nn' ########## `k'/1000" + di "###################################################################################" + di "###################################################################################" + di "###################################################################################" + preserve qui keep if replication==`k' @@ -253,10 +258,10 @@ local N = "50 100 200 300" * 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) local nbitems2 = 2*`nbitems' - + mat lrt_passed = resmat[1,`nbitems2'+1] * Calculer le nbre d'items détectés local nbdetect = 0 local stop = 0 @@ -329,7 +334,7 @@ local N = "50 100 200 300" local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent" } *calcul du modèle - qui `mod' + `mod' mat V=r(table) 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,"se_beta")]=W[2,colnumb(W,"THETA:tt")] + qui mat outmat[`k',colnumb(outmat,"lrt_passed")]=lrt_passed[1,1] restore } + log close putexcel set "`path_res'/`s'`scen'_`Nn'_original.xls", sheet("outmat") replace putexcel A1=matrix(outmat), colnames }