Added DIF scenarios up to 16

main
Corentin Choisy 11 months ago
parent 91e57f1563
commit be102c243d

1
.gitignore vendored

@ -1,2 +1,3 @@
*.csv *.csv
*.xls
.Rproj.user .Rproj.user

@ -19,7 +19,6 @@ lastChar <- function(str){
############################# ANALYSIS FUNCTIONS ############################# ############################# ANALYSIS FUNCTIONS #############################
#----------------------------------------------------------------------------# #----------------------------------------------------------------------------#
############################################################################## ##############################################################################
pcm_analysis <- function(df=NULL,treatment='TT',irtmodel='PCM2',method='MML') { pcm_analysis <- function(df=NULL,treatment='TT',irtmodel='PCM2',method='MML') {
nbitems <- sum(sapply(1:20,function(x) paste0('item',x)) %in% colnames(df)) nbitems <- sum(sapply(1:20,function(x) paste0('item',x)) %in% colnames(df))
resp <- df[,sapply(seq(1,nbitems),function(x) paste0('item',x))] resp <- df[,sapply(seq(1,nbitems),function(x) paste0('item',x))]
@ -43,7 +42,7 @@ replicate_pcm_analysis_m4 <- function(df=NULL,treatment='TT',irtmodel='PCM2',met
if (method=='MML') { if (method=='MML') {
n <- max(df[,sequence]) n <- max(df[,sequence])
print(n) print(n)
tam1 <- pbmclapply(seq(1,n), tam1 <- lapply(seq(1,n),
function(x) pcm_analysis(df=df[df[,sequence]==x,],treatment=treatment,irtmodel=irtmodel) function(x) pcm_analysis(df=df[df[,sequence]==x,],treatment=treatment,irtmodel=irtmodel)
) )
} }
@ -91,7 +90,7 @@ replicate_pcm_analysis_m2 <- function(df=NULL,treatment='TT',irtmodel='PCM2',met
if (method=='MML') { if (method=='MML') {
n <- max(df[,sequence]) n <- max(df[,sequence])
print(n) print(n)
tam1 <- pbmclapply(seq(1,n), tam1 <- lapply(seq(1,n),
function(x) pcm_analysis(df=df[df[,sequence]==x,],treatment=treatment,irtmodel=irtmodel) function(x) pcm_analysis(df=df[df[,sequence]==x,],treatment=treatment,irtmodel=irtmodel)
) )
} }
@ -126,12 +125,12 @@ replicate_pcm_analysis_m2 <- function(df=NULL,treatment='TT',irtmodel='PCM2',met
} }
replicate_pcm_analysis<- function(df=NULL,treatment='TT',irtmodel='PCM2',method='MML',sequence='replication',truebeta=0,eff.size=0,difsize=NA,nbdif=0) { replicate_pcm_analysis<- function(df=NULL,treatment='TT',irtmodel='PCM2',method='MML',sequence='replication',eff.size=0,difsize=NA,nbdif=0) {
j <- max(df$item1) j <- max(df$item1)
if(j==1) { if(j==1) {
return(replicate_pcm_analysis_m2(df=NULL,treatment='TT',irtmodel='PCM2',method='MML',sequence='replication',truebeta=0,eff.size=0,difsize=NA,nbdif=0)) return(replicate_pcm_analysis_m2(df=df,treatment=treatment,irtmodel=irtmodel,method=method,sequence=sequence,eff.size=eff.size,difsize=difsize,nbdif=nbdif))
} else { } else {
return(replicate_pcm_analysis_m4(df=NULL,treatment='TT',irtmodel='PCM2',method='MML',sequence='replication',truebeta=0,eff.size=0,difsize=NA,nbdif=0)) return(replicate_pcm_analysis_m4(df=df,treatment=treatment,irtmodel=irtmodel,method=method,sequence=sequence,eff.size=eff.size,difsize=difsize,nbdif=nbdif))
} }
} }

File diff suppressed because it is too large Load Diff

@ -1,148 +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 (version 5.5 October 25, 2023, available on gitea)
*
* outputs : for N=100
*
*
*================================================================================================================================================
* Load pcm.ado
adopath+"/home/corentin/Documents/These/Recherche/Simulations/Modules/"
*==========================
* Scenarios with : J=4
*==========================
** Scenario 5: J = 4 items / M = 2 modalities / DIF size 0.3
local N = "100 200 300"
foreach Nnn in `N' {
local Nn = `Nnn'
local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N`Nn'"
local path_res = "/home/corentin/Documents/These/Recherche/Simulations/Analysis/DIF/N`Nn'"
local scenarios = "A B C D E F G"
foreach scen in `scenarios' {
clear
import delim "`path_data'/scenario_5`scen'_`Nn'.csv", encoding(ISO-8859-2) case(preserve) clear
rename TT tt
* Matrice de taille 1000 * 4 items + 1 DIF + beta + std beta + 1 dif
local nbitems = 4
local nbdif = 1
local taillemat = `nbitems'+`nbdif'+3
mat outmat = J(1000,`taillemat',.)
mat colnames outmat = "item1" "item2" "item3" "item4" "dif1" "beta" "se_beta" "dif_item_1"
di "Scenario 5`scen' / N=`Nnn'"
forvalues k=1/1000 {
if (mod(`k',100)==0) {
di "`k'/1000"
}
preserve
qui keep if replication==`k'
local difitems1=dif1
local mod "gsem "
forvalues i=1/`nbitems' {
if (`i'==`difitems1') {
local mod = "`mod'"+"(1.item`i'<-THETA@1 tt)"
}
else {
local mod = "`mod'"+"(1.item`i'<-THETA@1)"
}
}
local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent"
qui `mod'
mat V=r(table)
mat W=V[1..2,1...]
forvalues j=1/`nbitems' {
if (`j'<`difitems1') {
mat outmat[`k',`j'] = W[1,3*`j'] // items avant le premier dif
}
else {
mat outmat[`k',`j'] = W[1,1+3*`j'] // items après le premier dif
}
}
mat outmat[`k',`nbitems'+1] = W[1,3*`difitems1'-1] // coef de dif
mat outmat[`k',`nbitems'+2] = W[1,3*`nbitems'+2] // beta
mat outmat[`k',`nbitems'+3] = W[2,3*`nbitems'+2] // se beta
mat outmat[`k',`nbitems'+4] = `difitems1' // numéro item de dif
restore
}
putexcel set "`path_res'/out/5`scen'_`Nn'.xls", sheet("outmat") replace
putexcel A1=matrix(outmat), colnames
}
}
** Scenario 6: J = 4 items / M = 4 modalities / DIF size 0.3
local N = "100 200 300"
foreach Nnn in `N' {
local Nn = `Nnn'
local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N`Nn'"
local path_res = "/home/corentin/Documents/These/Recherche/Simulations/Analysis/DIF/N`Nn'"
local scenarios = "A B C D E F G"
foreach scen in `scenarios' {
clear
import delim "`path_data'/scenario_6`scen'_`Nn'.csv", encoding(ISO-8859-2) case(preserve) clear
rename TT tt
* Matrice de taille 1000 * 4 items + 1 DIF + beta + std beta + 1 dif
local nbitems = 4
local nbdif = 1
local taillemat = 3*`nbitems'+`nbdif'+3+2
mat outmat = J(1000,`taillemat',.)
mat colnames outmat = "item1_1" "item1_2" "item1_3" "item2_1" "item2_2" "item2_3" "item3_1" "item3_2" "item3_3" "item4_1" "item4_2" "item4_3" "dif1_1" "dif1_2" "dif1_3" "beta" "se_beta" "dif_item_1"
di "Scenario 6`scen' / N=`Nnn'"
forvalues k=1/1000 {
if (mod(`k',100)==0) {
di "`k'/1000"
}
preserve
qui keep if replication==`k'
local difitems1=dif1
local mod "gsem "
forvalues i=1/`nbitems' {
if (`i'==`difitems1') {
local mod = "`mod'"+"(1.item`i'<-THETA@1 tt)(2.item`i'<-THETA@2 tt)(3.item`i'<-THETA@3 tt)"
}
else {
local mod = "`mod'"+"(1.item`i'<-THETA@1)(2.item`i'<-THETA@2)(2.item`i'<-THETA@2)"
}
}
local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent"
qui `mod'
mat V=r(table)
mat W=V[1..2,1...]
forvalues j=1/`nbitems' {
if (`j'<`difitems1') {
mat outmat[`k',3*`j'-2] = W[1,6*`j'-3] // items avant le premier dif
mat outmat[`k',3*`j'-1] = W[1,6*`j'-1] // items avant le premier dif
mat outmat[`k',3*`j'] = W[1,6*`j'] // items avant le premier dif
}
else if (`j'==`difitems1') {
mat outmat[`k',3*`j'-2] = W[1,6*`j'-2] // items du le premier dif
mat outmat[`k',3*`j'-1] = W[1,6*`j'+1] // items du le premier dif
mat outmat[`k',3*`j'] = W[1,6*`j'+4] // items du le premier dif }
}
else {
mat outmat[`k',3*`j'-2] = W[1,6*`j'+1] // items apres le premier dif
mat outmat[`k',3*`j'-1] = W[1,6*`j'+3] // items apres le premier dif
mat outmat[`k',3*`j'] = W[1,6*`j'+4] // items apres le premier dif }
}
}
mat outmat[`k',3*`nbitems'+1] = W[1,6*`difitems1'-4] // coef de dif
mat outmat[`k',3*`nbitems'+2] = W[1,6*`difitems1'-1] // coef de dif
mat outmat[`k',3*`nbitems'+3] = W[1,6*`difitems1'+2] // coef de dif
mat outmat[`k',3*`nbitems'+4] = W[1,6*`nbitems'+5] // beta
mat outmat[`k',3*`nbitems'+5] = W[2,6*`nbitems'+5] // se beta
mat outmat[`k',3*`nbitems'+6] = `difitems1' // numéro item de dif
restore
}
putexcel set "`path_res'/out/6`scen'_`Nn'.xls", sheet("outmat") replace
putexcel A1=matrix(outmat), colnames
}
}

@ -0,0 +1,12 @@
local path_data = "/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N100"
import delim "`path_data'/scenario_4A_100.csv", encoding(ISO-8859-2) case(preserve) clear
keep if replication==1
rename TT tt
gsem (1.item1 <- THETA@1)(2.item1 <- THETA@2)(3.item1 <- THETA@3)///
(1.item2 <- THETA@1)(2.item2 <- THETA@2)(3.item2 <- THETA@3)///
(1.item3 <- THETA@1)(2.item3 <- THETA@2)(3.item3 <- THETA@3)///
(1.item4 <- THETA@1)(2.item4 <- THETA@2)(3.item4 <- THETA@3)///
(THETA <- tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent
pcm item1 item2 item3 item4 item5 item6 item7, categorical(tt)
Loading…
Cancel
Save