Corrected pcmdif.do error

main
Corentin Choisy 11 months ago
parent ef1fbfbd4f
commit d5baf77bc1

2
.gitignore vendored

@ -1,3 +1,5 @@
*.csv *.csv
*.xls *.xls
.Rproj.user .Rproj.user
*.RData
*.Rhistory

Binary file not shown.

@ -1,262 +1,149 @@
res.null0 <- res.dat[res.dat$eff.size==0 & res.dat$dif.size==0,] muB=10
points(y=res.null0$h0.rejected.p,x=rep(1,nrow(res.null0)),col='gray',pch=3) kappa=1
res.null3 <- res.dat[res.dat$eff.size==0 & res.dat$dif.size==0.3,] sd=10
points(y=res.null3$h0.rejected.p,x=rep(2,nrow(res.null3)),col='#590b0c',pch=3) alpha=0.05
res.null5 <- res.dat[res.dat$eff.size==0 & res.dat$dif.size==0.5,] beta=0.20
points(y=res.null5$h0.rejected.p,x=rep(3,nrow(res.null5)),col='#053305',pch=3) (nB=(1+1/kappa)*(sd*(qnorm(1-alpha/2)+qnorm(1-beta))/(muA-muB))^2)
## Proportion of rejected h0 per dif value in h0 scenarios (A) by DIF size (1 item) ceiling(nB) # 63
par(mfrow=c(2,2)) z=(muA-muB)/(sd*sqrt((1+1/kappa)/nB))
# 0 item (Power=pnorm(z-qnorm(1-alpha/2))+pnorm(-z-qnorm(1-alpha/2)))
res.null <- res.dat[res.dat$eff.size==0 & res.dat$nb.dif==0,] muA=5
boxplot(h0.rejected.p~dif.size,data=res.null,col=c(2),xlab='DIF size', muB=10
ylab='H0 rejection proportion in target scenario',main='No DIF',ylim=c(0,1)) kappa=1
points(y=res.null$h0.rejected.p,x=rep(1,nrow(res.null)),col='#590b0c',pch=3) sd=10
# 1 item alpha=0.05
res.null <- res.dat[res.dat$eff.size==0 & res.dat$nb.dif==1,] beta=0.20
boxplot(h0.rejected.p~dif.size,data=res.null,col=c(2,3),xlab='DIF size', (nB=(1+1/kappa)*(sd*(qnorm(1-alpha/2)+qnorm(1-beta))/(muA-muB))^2)
ylab='H0 rejection proportion in target scenario',main='DIF on 1 item',ylim=c(0,1)) ceiling(nB) # 63
res.null3 <- res.null[res.null$dif.size==0.3,] z=(muA-muB)/(sd*sqrt((1+1/kappa)/nB))
points(y=res.null3$h0.rejected.p,x=rep(1,nrow(res.null3)),col='#590b0c',pch=3) (Power=pnorm(z-qnorm(1-alpha/2))+pnorm(-z-qnorm(1-alpha/2)))
res.null5 <- res.null[res.null$dif.size==0.5,] -1*(-0.49-0.47)
points(y=res.null5$h0.rejected.p,x=rep(2,nrow(res.null5)),col='#053305',pch=3) -1*(-1.69-0.95)+(-0.49-0.47)
# 2 items -1*(-0.49-0.47)-0.49
res.null <- res.dat[res.dat$eff.size==0 & res.dat$nb.dif==2,] -1*(-0.49-0.47)-1.69
boxplot(h0.rejected.p~dif.size,data=res.null,col=c(2,3),xlab='DIF size', -1*(-0.49-0.47)-(1.69-0.49)
ylab='H0 rejection proportion in target scenario',main='DIF on 2 items',ylim=c(0,1)) 3.35-1.69
res.null3 <- res.null[res.null$dif.size==0.3,] library(TAM)
points(y=res.null3$h0.rejected.p,x=rep(1,nrow(res.null3)),col='#590b0c',pch=3) library(doMC)
res.null5 <- res.null[res.null$dif.size==0.5,] library(parallel)
points(y=res.null5$h0.rejected.p,x=rep(2,nrow(res.null5)),col='#053305',pch=3) library(pbmcapply)
# 3 items library(funprog)
res.null <- res.dat[res.dat$eff.size==0 & res.dat$nb.dif==3,] library(dplyr)
boxplot(h0.rejected.p~dif.size,data=res.null,col=c(2,3),xlab='DIF size', lastChar <- function(str){
ylab='H0 rejection proportion in target scenario',main='DIF on 3 items',ylim=c(0,1)) substr(str, nchar(str)-2, nchar(str))
res.null3 <- res.null[res.null$dif.size==0.3,]
points(y=res.null3$h0.rejected.p,x=rep(1,nrow(res.null3)),col='#590b0c',pch=3)
res.null5 <- res.null[res.null$dif.size==0.5,]
points(y=res.null5$h0.rejected.p,x=rep(2,nrow(res.null5)),col='#053305',pch=3)
par(mfrow=c(1,1))
par(mfrow=c(2,2))
# 0 item
res.null <- res.dat[res.dat$eff.size==0 & res.dat$nb.dif==0 & res.dat$J==4,]
boxplot(h0.rejected.p~dif.size,data=res.null,col=c(2),xlab='DIF size',
ylab='H0 rejection proportion in target scenario',main='No DIF',ylim=c(0,1))
points(y=res.null$h0.rejected.p,x=rep(1,nrow(res.null)),col='#590b0c',pch=3)
# 1 item
res.null <- res.dat[res.dat$eff.size==0 & res.dat$nb.dif==1 & res.dat$J==4,]
boxplot(h0.rejected.p~dif.size,data=res.null,col=c(2,3),xlab='DIF size',
ylab='H0 rejection proportion in target scenario',main='DIF on 1 item',ylim=c(0,1))
res.null3 <- res.null[res.null$dif.size==0.3,]
points(y=res.null3$h0.rejected.p,x=rep(1,nrow(res.null3)),col='#590b0c',pch=3)
res.null5 <- res.null[res.null$dif.size==0.5,]
points(y=res.null5$h0.rejected.p,x=rep(2,nrow(res.null5)),col='#053305',pch=3)
# 2 items
res.null <- res.dat[res.dat$eff.size==0 & res.dat$nb.dif==2 & res.dat$J==4,]
boxplot(h0.rejected.p~dif.size,data=res.null,col=c(2,3),xlab='DIF size',
ylab='H0 rejection proportion in target scenario',main='DIF on 2 items',ylim=c(0,1))
res.null3 <- res.null[res.null$dif.size==0.3,]
points(y=res.null3$h0.rejected.p,x=rep(1,nrow(res.null3)),col='#590b0c',pch=3)
res.null5 <- res.null[res.null$dif.size==0.5,]
points(y=res.null5$h0.rejected.p,x=rep(2,nrow(res.null5)),col='#053305',pch=3)
par(mfrow=c(1,1))
par(mfrow=c(2,2))
# 0 item
res.null <- res.dat[res.dat$eff.size==0 & res.dat$nb.dif==0 & res.dat$J==7,]
nrow(res.null)
boxplot(h0.rejected.p~dif.size,data=res.null,col=c(2),xlab='DIF size',
ylab='H0 rejection proportion in target scenario',main='No DIF',ylim=c(0,1))
points(y=res.null$h0.rejected.p,x=rep(1,nrow(res.null)),col='#590b0c',pch=3)
# 2 items
res.null <- res.dat[res.dat$eff.size==0 & res.dat$nb.dif==2 & res.dat$J==7,]
boxplot(h0.rejected.p~dif.size,data=res.null,col=c(2,3),xlab='DIF size',
ylab='H0 rejection proportion in target scenario',main='DIF on 2 items',ylim=c(0,1))
res.null3 <- res.null[res.null$dif.size==0.3,]
points(y=res.null3$h0.rejected.p,x=rep(1,nrow(res.null3)),col='#590b0c',pch=3)
res.null5 <- res.null[res.null$dif.size==0.5,]
points(y=res.null5$h0.rejected.p,x=rep(2,nrow(res.null5)),col='#053305',pch=3)
# 3 items
res.null <- res.dat[res.dat$eff.size==0 & res.dat$nb.dif==3 & res.dat$J==7,]
boxplot(h0.rejected.p~dif.size,data=res.null,col=c(2,3),xlab='DIF size',
ylab='H0 rejection proportion in target scenario',main='DIF on 3 items',ylim=c(0,1))
res.null3 <- res.null[res.null$dif.size==0.3,]
points(y=res.null3$h0.rejected.p,x=rep(1,nrow(res.null3)),col='#590b0c',pch=3)
res.null5 <- res.null[res.null$dif.size==0.5,]
points(y=res.null5$h0.rejected.p,x=rep(2,nrow(res.null5)),col='#053305',pch=3)
par(mfrow=c(1,1))
par(mfrow=c(2,2))
# 0 item
res.null <- res.dat[res.dat$eff.size==0 & res.dat$nb.dif==0 & res.dat$J==7,]
nrow(res.null)
boxplot(h0.rejected.p~dif.size,data=res.null,col=c(2),xlab='DIF size',
ylab='H0 rejection proportion in target scenario',main='No DIF',ylim=c(0,1))
points(y=res.null$h0.rejected.p,x=rep(1,nrow(res.null)),col='#590b0c',pch=3)
# 2 items
res.null <- res.dat[res.dat$eff.size==0 & res.dat$nb.dif==2 & res.dat$J==7,]
boxplot(h0.rejected.p~dif.size,data=res.null,col=c(2,3),xlab='DIF size',
ylab='H0 rejection proportion in target scenario',main='DIF on 2 items',ylim=c(0,1))
res.null3 <- res.null[res.null$dif.size==0.3,]
points(y=res.null3$h0.rejected.p,x=rep(1,nrow(res.null3)),col='#590b0c',pch=3)
res.null5 <- res.null[res.null$dif.size==0.5,]
points(y=res.null5$h0.rejected.p,x=rep(2,nrow(res.null5)),col='#053305',pch=3)
# 3 items
res.null <- res.dat[res.dat$eff.size==0 & res.dat$nb.dif==3 & res.dat$J==7,]
boxplot(h0.rejected.p~dif.size,data=res.null,col=c(2,3),xlab='DIF size',
ylab='H0 rejection proportion in target scenario',main='DIF on 3 items',ylim=c(0,1))
res.null3 <- res.null[res.null$dif.size==0.3,]
points(y=res.null3$h0.rejected.p,x=rep(1,nrow(res.null3)),col='#590b0c',pch=3)
res.null5 <- res.null[res.null$dif.size==0.5,]
points(y=res.null5$h0.rejected.p,x=rep(2,nrow(res.null5)),col='#053305',pch=3)
par(mfrow=c(1,1))
par(mfrow=c(2,2))
# 0 item
res.null <- res.dat[res.dat$eff.size==0 & res.dat$nb.dif==0 & res.dat$J==4,]
boxplot(h0.rejected.p~dif.size,data=res.null,col=c(2),xlab='DIF size',
ylab='H0 rejection proportion in target scenario',main='No DIF',ylim=c(0,1))
points(y=res.null$h0.rejected.p,x=rep(1,nrow(res.null)),col='#590b0c',pch=3)
# 1 item
res.null <- res.dat[res.dat$eff.size==0 & res.dat$nb.dif==1 & res.dat$J==4,]
boxplot(h0.rejected.p~dif.size,data=res.null,col=c(2,3),xlab='DIF size',
ylab='H0 rejection proportion in target scenario',main='DIF on 1 item',ylim=c(0,1))
res.null3 <- res.null[res.null$dif.size==0.3,]
points(y=res.null3$h0.rejected.p,x=rep(1,nrow(res.null3)),col='#590b0c',pch=3)
res.null5 <- res.null[res.null$dif.size==0.5,]
points(y=res.null5$h0.rejected.p,x=rep(2,nrow(res.null5)),col='#053305',pch=3)
# 2 items
res.null <- res.dat[res.dat$eff.size==0 & res.dat$nb.dif==2 & res.dat$J==4,]
boxplot(h0.rejected.p~dif.size,data=res.null,col=c(2,3),xlab='DIF size',
ylab='H0 rejection proportion in target scenario',main='DIF on 2 items',ylim=c(0,1))
res.null3 <- res.null[res.null$dif.size==0.3,]
points(y=res.null3$h0.rejected.p,x=rep(1,nrow(res.null3)),col='#590b0c',pch=3)
res.null5 <- res.null[res.null$dif.size==0.5,]
points(y=res.null5$h0.rejected.p,x=rep(2,nrow(res.null5)),col='#053305',pch=3)
par(mfrow=c(1,1))
par(mfrow=c(2,2))
# 0 item
res.null <- res.dat[res.dat$eff.size==0 & res.dat$nb.dif==0 & res.dat$J==7,]
nrow(res.null)
boxplot(h0.rejected.p~dif.size,data=res.null,col=c(2),xlab='DIF size',
ylab='H0 rejection proportion in target scenario',main='No DIF',ylim=c(0,1))
points(y=res.null$h0.rejected.p,x=rep(1,nrow(res.null)),col='#590b0c',pch=3)
# 2 items
res.null <- res.dat[res.dat$eff.size==0 & res.dat$nb.dif==2 & res.dat$J==7,]
boxplot(h0.rejected.p~dif.size,data=res.null,col=c(2,3),xlab='DIF size',
ylab='H0 rejection proportion in target scenario',main='DIF on 2 items',ylim=c(0,1))
res.null3 <- res.null[res.null$dif.size==0.3,]
points(y=res.null3$h0.rejected.p,x=rep(1,nrow(res.null3)),col='#590b0c',pch=3)
res.null5 <- res.null[res.null$dif.size==0.5,]
points(y=res.null5$h0.rejected.p,x=rep(2,nrow(res.null5)),col='#053305',pch=3)
# 3 items
res.null <- res.dat[res.dat$eff.size==0 & res.dat$nb.dif==3 & res.dat$J==7,]
boxplot(h0.rejected.p~dif.size,data=res.null,col=c(2,3),xlab='DIF size',
ylab='H0 rejection proportion in target scenario',main='DIF on 3 items',ylim=c(0,1))
res.null3 <- res.null[res.null$dif.size==0.3,]
points(y=res.null3$h0.rejected.p,x=rep(1,nrow(res.null3)),col='#590b0c',pch=3)
res.null5 <- res.null[res.null$dif.size==0.5,]
points(y=res.null5$h0.rejected.p,x=rep(2,nrow(res.null5)),col='#053305',pch=3)
par(mfrow=c(1,1))
# Overall
boxplot(beta.same.sign.truebeta.p~dif.size,data=res.dat,col=c(2,3),xlab='DIF size',
ylab='Proportion of estimates with same sign as true value in target scenario',main='DIF on 3 items',ylim=c(0,1))
res.null3 <- res.dat[res.dat$dif.size==-0.5,]
points(y=res.null3$beta.same.sign.truebeta.p,x=rep(1,nrow(res.null3)),col='#590b0c',pch=3)
res.null3 <- res.dat[res.dat$dif.size==0.5,]
points(y=res.null3$beta.same.sign.truebeta.p,x=rep(5,nrow(res.null3)),col='#590b0c',pch=3)
res.null3 <- res.dat[res.dat$dif.size==-0.3,]
points(y=res.null3$beta.same.sign.truebeta.p,x=rep(2,nrow(res.null3)),col='#053305',pch=3)
res.null3 <- res.dat[res.dat$dif.size==0.3,]
points(y=res.null3$beta.same.sign.truebeta.p,x=rep(4,nrow(res.null3)),col='#053305',pch=3)
res.null3 <- res.dat[res.dat$dif.size==0,]
points(y=res.null3$beta.same.sign.truebeta.p,x=rep(3,nrow(res.null3)),col='gray',pch=3)
#### Create data.frame
results <- c(sapply(1:4,function(x) paste0(x,c('A','B','C','D','E'))),sapply(5:9,function(x) paste0(x,c('A','B','C','D','E','F','G'))))
results2 <- c(sapply(10:20,function(x) paste0(x,c('A','B','C','D','E','F','G'))))
results <- c(sapply(c(100,200,300),function(x) paste0(results,'_',x)))
results2 <- c(sapply(c(100,200,300),function(x) paste0(results2,'_',x)))
results <- sort(results)
results2 <- sort(results2)
results <- c(results,results2)
#### Compiler function
compile_simulation <- function(scenario) {
name <- as.numeric(gsub("[^0-9.-]", "", substr(scenario,start=0,stop=2)))
if (substr(scenario,start=nchar(scenario)-2,stop=nchar(scenario))=="100" & name<=4) {
s <- read.csv(paste0('/home/corentin/Documents/These/Recherche/Simulations/Analysis/NoDIF/N100/scenario_',scenario,'.csv'))
} }
if (substr(scenario,start=nchar(scenario)-2,stop=nchar(scenario))=="100" & name>4) { pcm_analysis <- function(df=NULL,treatment='TT',irtmodel='PCM2',method='MML') {
s <- read.csv(paste0('/home/corentin/Documents/These/Recherche/Simulations/Analysis/NoDIF/N100/scenario_',scenario,'_nodif.csv')) 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 (substr(scenario,start=nchar(scenario)-2,stop=nchar(scenario))=="200" & name<=4) { if (method=='JML') {
s <- read.csv(paste0('/home/corentin/Documents/These/Recherche/Simulations/Analysis/NoDIF/N200/scenario_',scenario,'.csv')) tam1 <- tam.jml(resp=resp,group=1+df[,treatment])
} }
if (substr(scenario,start=nchar(scenario)-2,stop=nchar(scenario))=="200" & name>4) { if (method!='MML' & method!='JML') {
s <- read.csv(paste0('/home/corentin/Documents/These/Recherche/Simulations/Analysis/NoDIF/N200/scenario_',scenario,'_nodif.csv')) stop('Invalid method. Please choose among MML or JML')
} }
if (substr(scenario,start=nchar(scenario)-2,stop=nchar(scenario))=="300" & name<=4) { return(tam1)
s <- read.csv(paste0('/home/corentin/Documents/These/Recherche/Simulations/Analysis/NoDIF/N300/scenario_',scenario,'.csv'))
} }
if (substr(scenario,start=nchar(scenario)-2,stop=nchar(scenario))=="300" & name>4) { replicate_pcm_analysis_m4 <- function(df=NULL,treatment='TT',irtmodel='PCM2',method='MML',sequence='replication',eff.size=0,difsize=NA,nbdif=0) {
s <- read.csv(paste0('/home/corentin/Documents/These/Recherche/Simulations/Analysis/NoDIF/N300/scenario_',scenario,'_nodif.csv')) nbitems <- sum(sapply(1:20,function(x) paste0('item',x)) %in% colnames(df))
resp <- df[,sapply(seq(1,nbitems),function(x) paste0('item',x))]
truebeta <- eff.size
if (method=='MML') {
n <- max(df[,sequence])
print(n)
tam1 <- lapply(seq(1,n),
function(x) pcm_analysis(df=df[df[,sequence]==x,],treatment=treatment,irtmodel=irtmodel)
)
} }
if (unique(s$J)==4) { listitems <- c(sapply(c('_1','_2','_3'),function(x) paste0(sapply(seq(1,nbitems),function(x) paste0('item',x)),x)))
if (unique(s$M)==2) { returndat <- data.frame(matrix(nrow=max(df[,sequence]),ncol=length(listitems)))
a <- data.frame(m.item1=mean(s$item1),m.item2=mean(s$item2),m.item3=mean(s$item3),m.item4=mean(s$item4)) colnames(returndat) <- listitems
for (s in seq(1,max(df[,sequence]))) {
for (k in seq(1,nbitems)) {
returndat[s,paste0('item',k,'_1')] <- tam1[[s]]$item[k,'AXsi_.Cat1']
returndat[s,paste0('item',k,'_2')] <- tam1[[s]]$item[k,'AXsi_.Cat2']-tam1[[s]]$item[k,'AXsi_.Cat1']
returndat[s,paste0('item',k,'_3')] <- tam1[[s]]$item[k,'AXsi_.Cat3']-tam1[[s]]$item[k,'AXsi_.Cat2']
}
}
returndat <- returndat[,sort_by(listitems, lastChar)]
returndat$beta <- sapply(seq(1,max(df[,sequence])),function(k) tam1[[k]]$beta[2])
returndat$se.beta <- 1.413612*sapply(seq(1,max(df[,sequence])),function(k) tam.se(tam1[[k]])$beta$se.Dim1[2] )
returndat$low.ci.beta <- returndat$beta-1.96*returndat$se.beta
returndat$high.ci.beta <- returndat$beta+1.96*returndat$se.beta
returndat$true.value.in.ci <- 1*(truebeta>returndat$low.ci.beta & truebeta<returndat$high.ci.beta)
returndat$h0.rejected <- 1*(0<returndat$low.ci.beta | 0>returndat$high.ci.beta)
if (truebeta==0) {
returndat$beta.same.sign.truebeta <- NA
} else { } else {
a <- data.frame(m.item1_1=mean(s$item1_1),m.item1_2=mean(s$item1_2),m.item1_3=mean(s$item1_3), returndat$beta.same.sign.truebeta <- 1*(sign(truebeta)==sign(returndat$beta))
m.item2_1=mean(s$item2_1),m.item2_2=mean(s$item2_2),m.item2_3=mean(s$item2_3), }
m.item3_1=mean(s$item3_1),m.item3_2=mean(s$item3_2),m.item3_3=mean(s$item3_3), returndat2 <- data.frame(J=rep(nbitems,max(df[,sequence])),
m.item4_1=mean(s$item4_1),m.item4_2=mean(s$item4_2),m.item4_3=mean(s$item4_3) M=1+max(df$item1),
N=nrow(df[df$replication==1,])/2,
eff.size=truebeta,
dif.size= difsize,
nb.dif= nbdif
) )
returndat <- cbind(returndat2,returndat)
return(returndat)
} }
} else { replicate_pcm_analysis_m2 <- function(df=NULL,treatment='TT',irtmodel='PCM2',method='MML',sequence='replication',eff.size=0,difsize=NA,nbdif=0) {
if (unique(s$M)==2) { truebeta <- eff.size
a <- data.frame(m.item1=mean(s$item1),m.item2=mean(s$item2),m.item3=mean(s$item3),m.item4=mean(s$item4), nbitems <- sum(sapply(1:20,function(x) paste0('item',x)) %in% colnames(df))
m.item5=mean(s$item5),m.item6=mean(s$item6),m.item7=mean(s$item7)) resp <- df[,sapply(seq(1,nbitems),function(x) paste0('item',x))]
} else { if (method=='MML') {
a <- data.frame(m.item1_1=mean(s$item1_1),m.item1_2=mean(s$item1_2),m.item1_3=mean(s$item1_3), n <- max(df[,sequence])
m.item2_1=mean(s$item2_1),m.item2_2=mean(s$item2_2),m.item2_3=mean(s$item2_3), print(n)
m.item3_1=mean(s$item3_1),m.item3_2=mean(s$item3_2),m.item3_3=mean(s$item3_3), tam1 <- lapply(seq(1,n),
m.item4_1=mean(s$item4_1),m.item4_2=mean(s$item4_2),m.item4_3=mean(s$item4_3), function(x) pcm_analysis(df=df[df[,sequence]==x,],treatment=treatment,irtmodel=irtmodel)
m.item5_1=mean(s$item5_1),m.item5_2=mean(s$item5_2),m.item5_3=mean(s$item5_3),
m.item6_1=mean(s$item6_1),m.item6_2=mean(s$item6_2),m.item6_3=mean(s$item6_3),
m.item7_1=mean(s$item7_1),m.item7_2=mean(s$item7_2),m.item7_3=mean(s$item7_3)
) )
} }
listitems <- sapply(seq(1,nbitems),function(x) paste0('item',x))
returndat <- data.frame(matrix(nrow=max(df[,sequence]),ncol=length(listitems)))
colnames(returndat) <- listitems
for (s in seq(1,max(df[,sequence]))) {
for (k in seq(1,nbitems)) {
returndat[s,paste0('item',k)] <- tam1[[s]]$xsi$xsi[k]
} }
zz <- substr(scenario,start=0,stop=nchar(scenario)-4) }
b <- data.frame(scenario=zz, returndat$beta <- sapply(seq(1,max(df[,sequence])),function(k) tam1[[k]]$beta[2])
scenario.type=substr(zz,start=nchar(zz),stop=nchar(zz)), returndat$se.beta <- 1.413612*sapply(seq(1,max(df[,sequence])),function(k) tam.se(tam1[[k]])$beta$se.Dim1[2] )
N=substr(scenario,start=nchar(scenario)-2,stop=nchar(scenario)), returndat$low.ci.beta <- returndat$beta-1.96*returndat$se.beta
J=unique(s$J), returndat$high.ci.beta <- returndat$beta+1.96*returndat$se.beta
M=unique(s$M), returndat$true.value.in.ci <- 1*(truebeta>returndat$low.ci.beta & truebeta<returndat$high.ci.beta)
eff.size=unique(s$eff.size), returndat$h0.rejected <- 1*(0<returndat$low.ci.beta | 0>returndat$high.ci.beta)
nb.dif=unique(s$nb.dif), if (truebeta==0) {
dif.size=unique(s$dif.size) returndat$beta.same.sign.truebeta <- NA
} else {
returndat$beta.same.sign.truebeta <- 1*(sign(truebeta)==sign(returndat$beta))
}
returndat2 <- data.frame(J=rep(nbitems,max(df[,sequence])),
M=1+max(df$item1),
N=nrow(df[df$replication==1,])/2,
eff.size=truebeta,
dif.size= difsize,
nb.dif= nbdif
) )
z <- data.frame(m.beta=mean(s$beta), returndat <- cbind(returndat2,returndat)
se.empirical.beta=sd(s$beta), return(returndat)
se.analytical.beta=mean(s$se.beta),
m.low.ci.beta=mean(s$low.ci.beta),
m.high.ci.beta=mean(s$high.ci.beta),
true.value.in.ci.p=mean(s$true.value.in.ci),
h0.rejected.p=mean(s$h0.rejected),
beta.same.sign.truebeta.p=mean(s$beta.same.sign.truebeta,na.rm=T),
beta.same.sign.truebeta.signif.p=mean(s[s$h0.rejected==1,]$beta.same.sign.truebeta,na.rm=T))
d <- cbind(b,a,z)
d$prop.
return(d)
} }
#### Compiled results replicate_pcm_analysis<- function(df=NULL,treatment='TT',irtmodel='PCM2',method='MML',sequence='replication',eff.size=0,difsize=NA,nbdif=0) {
res.dat <- compile_simulation('1A_100') j <- max(df$item1)
for (x in results[seq(2,length(results))]) { if(j==1) {
y <- compile_simulation(x) return(replicate_pcm_analysis_m2(df=df,treatment=treatment,irtmodel=irtmodel,method=method,sequence=sequence,eff.size=eff.size,difsize=difsize,nbdif=nbdif))
res.dat <- bind_rows(res.dat,y) } else {
return(replicate_pcm_analysis_m4(df=df,treatment=treatment,irtmodel=irtmodel,method=method,sequence=sequence,eff.size=eff.size,difsize=difsize,nbdif=nbdif))
} }
library(TAM) }
library(doMC) registerDoMC(4)
library(parallel) dat1 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N100/scenario_20A_100.csv')
library(pbmcapply) res_nodif <- pbmclapply(c('dat1'),function(x) replicate_pcm_analysis(get(x),nbdif = 1,difsize = 0.5))
library(funprog) write.csv(res_nodif[[1]],'/home/corentin/Documents/These/Recherche/Simulation/Analysis/DIF/N100/scenario_20A_100_nodif.csv')
library(dplyr) res_nodif[[1]]
#### Create data.frame write.csv(res_nodif[[1]],'/home/corentin/Documents/These/Recherche/Simulationss/Analysis/NoDIF/N100/scenario_20A_100_nodif.csv')
write.csv(res_nodif[[1]],'/home/corentin/Documents/These/Recherche/Simulations/Analysis/NoDIF/N100/scenario_20A_100_nodif.csv')
results <- c(sapply(1:4,function(x) paste0(x,c('A','B','C','D','E'))),sapply(5:9,function(x) paste0(x,c('A','B','C','D','E','F','G')))) results <- c(sapply(1:4,function(x) paste0(x,c('A','B','C','D','E'))),sapply(5:9,function(x) paste0(x,c('A','B','C','D','E','F','G'))))
results2 <- c(sapply(10:20,function(x) paste0(x,c('A','B','C','D','E','F','G')))) results2 <- c(sapply(10:20,function(x) paste0(x,c('A','B','C','D','E','F','G'))))
results <- c(sapply(c(100,200,300),function(x) paste0(results,'_',x))) results <- c(sapply(c(100,200,300),function(x) paste0(results,'_',x)))
@ -346,63 +233,188 @@ res.dat[300:396,'nb.dif'] <- 3
res.dat.simple <- res.dat[,c(1:8,13,16:18)] res.dat.simple <- res.dat[,c(1:8,13,16:18)]
res.dat.simple$m.beta <- round(res.dat.simple$m.beta,3) res.dat.simple$m.beta <- round(res.dat.simple$m.beta,3)
res.dat.simple res.dat.simple
boxplot(beta.same.sign.truebeta.signif.p~dif.size,data=res.dat,col=c(2,3),xlab='DIF size',
ylab='Proportion of estimates with same sign as true value in target scenario',main='DIF on 3 items',ylim=c(0,1))
res.null3 <- res.dat[res.dat$dif.size==-0.5,]
points(y=res.null3$beta.same.sign.truebeta.p,x=rep(1,nrow(res.null3)),col='#590b0c',pch=3)
res.null3 <- res.dat[res.dat$dif.size==0.5,]
points(y=res.null3$beta.same.sign.truebeta.p,x=rep(5,nrow(res.null3)),col='#590b0c',pch=3)
res.null3 <- res.dat[res.dat$dif.size==-0.3,]
points(y=res.null3$beta.same.sign.truebeta.p,x=rep(2,nrow(res.null3)),col='#053305',pch=3)
res.null3 <- res.dat[res.dat$dif.size==0.3,]
points(y=res.null3$beta.same.sign.truebeta.p,x=rep(4,nrow(res.null3)),col='#053305',pch=3)
res.null3 <- res.dat[res.dat$dif.size==0,]
points(y=res.null3$beta.same.sign.truebeta.p,x=rep(3,nrow(res.null3)),col='gray',pch=3)
boxplot(beta.same.sign.truebeta.signif.p~dif.size,data=res.dat,col=c(2,3),xlab='DIF size',
ylab='Proportion of estimates with same sign as true value in target scenario',main='DIF on 3 items',ylim=c(0,1))
res.null3 <- res.dat[res.dat$dif.size==-0.5,]
points(y=res.null3$beta.same.sign.truebeta.signif.p,x=rep(1,nrow(res.null3)),col='#590b0c',pch=3)
res.null3 <- res.dat[res.dat$dif.size==0.5,]
points(y=res.null3$beta.same.sign.truebeta.signif.p,x=rep(5,nrow(res.null3)),col='#590b0c',pch=3)
res.null3 <- res.dat[res.dat$dif.size==-0.3,]
points(y=res.null3$beta.same.sign.truebeta.signif.p,x=rep(2,nrow(res.null3)),col='#053305',pch=3)
res.null3 <- res.dat[res.dat$dif.size==0.3,]
points(y=res.null3$beta.same.sign.truebeta.signif.p,x=rep(4,nrow(res.null3)),col='#053305',pch=3)
res.null3 <- res.dat[res.dat$dif.size==0,]
points(y=res.null3$beta.same.sign.truebeta.signif.p,x=rep(3,nrow(res.null3)),col='gray',pch=3)
## Proportion of rejected h0 per dif value in h0 scenarios (A) by DIF size ## Proportion of rejected h0 per dif value in h0 scenarios (A) by DIF size
res.null <- res.dat[res.dat$eff.size!=0,] res.null <- res.dat[res.dat$eff.size==0,]
boxplot(h0.rejected.p~dif.size,data=res.null,col=c(3,2,1),xlab='DIF size',ylab='H0 rejection proportion in target scenario') boxplot(h0.rejected.p~dif.size,data=res.null,col=c(3,2,1),xlab='DIF size',ylab='H0 rejection proportion in target scenario')
res.null0 <- res.dat[res.dat$eff.size!=0 & res.dat$dif.size==0,] res.null0 <- res.dat[res.dat$eff.size==0 & res.dat$dif.size==0,]
points(y=res.null0$h0.rejected.p,x=rep(3,nrow(res.null0)),col='gray',pch=3) points(y=res.null0$h0.rejected.p,x=rep(3,nrow(res.null0)),col='gray',pch=3)
res.null3 <- res.dat[res.dat$eff.size!=0 & res.dat$dif.size==-0.3,] res.null3 <- res.dat[res.dat$eff.size==0 & res.dat$dif.size==-0.3,]
points(y=res.null3$h0.rejected.p,x=rep(2,nrow(res.null3)),col='#590b0c',pch=3) points(y=res.null3$h0.rejected.p,x=rep(2,nrow(res.null3)),col='#590b0c',pch=3)
res.null5 <- res.dat[res.dat$eff.size!=0 & res.dat$dif.size==-0.5,] res.null5 <- res.dat[res.dat$eff.size==0 & res.dat$dif.size==-0.5,]
points(y=res.null5$h0.rejected.p,x=rep(1,nrow(res.null5)),col='#053305',pch=3) points(y=res.null5$h0.rejected.p,x=rep(1,nrow(res.null5)),col='#053305',pch=3)
res.null <- res.dat[res.dat$eff.size>0,] par(mfrow=c(2,2))
boxplot(h0.rejected.p~dif.size,data=res.null,col=c(3,2,1),xlab='DIF size',ylab='H0 rejection proportion in target scenario') # 0 item
res.null0 <- res.dat[res.dat$eff.size>0 & res.dat$dif.size==0,] res.null <- res.dat[res.dat$eff.size==0 & res.dat$nb.dif==0,]
points(y=res.null0$h0.rejected.p,x=rep(3,nrow(res.null0)),col='gray',pch=3) boxplot(h0.rejected.p~dif.size,data=res.null,col=c(2),xlab='DIF size',
res.null3 <- res.dat[res.dat$eff.size>0 & res.dat$dif.size==-0.3,] ylab='H0 rejection proportion in target scenario',main='No DIF',ylim=c(0,1))
points(y=res.null$h0.rejected.p,x=rep(1,nrow(res.null)),col='#590b0c',pch=3)
# 1 item
res.null <- res.dat[res.dat$eff.size==0 & res.dat$nb.dif==1,]
boxplot(h0.rejected.p~dif.size,data=res.null,col=c(3,2),xlab='DIF size',
ylab='H0 rejection proportion in target scenario',main='DIF on 1 item',ylim=c(0,1))
res.null3 <- res.null[res.null$dif.size==-0.3,]
points(y=res.null3$h0.rejected.p,x=rep(2,nrow(res.null3)),col='#590b0c',pch=3) points(y=res.null3$h0.rejected.p,x=rep(2,nrow(res.null3)),col='#590b0c',pch=3)
res.null5 <- res.dat[res.dat$eff.size>0 & res.dat$dif.size==-0.5,] res.null5 <- res.null[res.null$dif.size==-0.5,]
points(y=res.null5$h0.rejected.p,x=rep(1,nrow(res.null5)),col='#053305',pch=3) points(y=res.null5$h0.rejected.p,x=rep(1,nrow(res.null5)),col='#053305',pch=3)
res.null <- res.dat[res.dat$eff.size>0,] # 2 items
boxplot(h0.rejected.p~dif.size,data=res.null,col=c(3,2,4,2,3),xlab='DIF size',ylab='H0 rejection proportion in target scenario') res.null <- res.dat[res.dat$eff.size==0 & res.dat$nb.dif==2,]
res.null0 <- res.dat[res.dat$eff.size>0 & res.dat$dif.size==0,] boxplot(h0.rejected.p~dif.size,data=res.null,col=c(3,2),xlab='DIF size',
points(y=res.null0$h0.rejected.p,x=rep(3,nrow(res.null0)),col='gray',pch=3) ylab='H0 rejection proportion in target scenario',main='DIF on 2 items',ylim=c(0,1))
res.null3 <- res.dat[res.dat$eff.size>0 & res.dat$dif.size==-0.3,] res.null3 <- res.null[res.null$dif.size==-0.3,]
points(y=res.null3$h0.rejected.p,x=rep(2,nrow(res.null3)),col='#590b0c',pch=3) points(y=res.null3$h0.rejected.p,x=rep(2,nrow(res.null3)),col='#590b0c',pch=3)
res.null5 <- res.dat[res.dat$eff.size>0 & res.dat$dif.size==-0.5,] res.null5 <- res.null[res.null$dif.size==-0.5,]
points(y=res.null5$h0.rejected.p,x=rep(1,nrow(res.null5)),col='#053305',pch=3) points(y=res.null5$h0.rejected.p,x=rep(1,nrow(res.null5)),col='#053305',pch=3)
res.null <- res.dat[res.dat$eff.size>0,] # 3 items
boxplot(h0.rejected.p~dif.size,data=res.null,col=c(3,2,4,2,3),xlab='DIF size',ylab='H0 rejection proportion in target scenario') res.null <- res.dat[res.dat$eff.size==0 & res.dat$nb.dif==3,]
res.null0 <- res.dat[res.dat$eff.size>0 & res.dat$dif.size==0,] boxplot(h0.rejected.p~dif.size,data=res.null,col=c(3,2),xlab='DIF size',
points(y=res.null0$h0.rejected.p,x=rep(3,nrow(res.null0)),col='darkblue',pch=3) ylab='H0 rejection proportion in target scenario',main='DIF on 3 items',ylim=c(0,1))
res.null3 <- res.dat[res.dat$eff.size>0 & res.dat$dif.size==-0.3,] res.null3 <- res.null[res.null$dif.size==-0.3,]
points(y=res.null3$h0.rejected.p,x=rep(2,nrow(res.null3)),col='#590b0c',pch=3) points(y=res.null3$h0.rejected.p,x=rep(2,nrow(res.null3)),col='#590b0c',pch=3)
res.null5 <- res.dat[res.dat$eff.size>0 & res.dat$dif.size==-0.5,] res.null5 <- res.null[res.null$dif.size==-0.5,]
points(y=res.null5$h0.rejected.p,x=rep(1,nrow(res.null5)),col='#053305',pch=3)
par(mfrow=c(1,1))
par(mfrow=c(2,2))
# 0 item
res.null <- res.dat[res.dat$eff.size==0 & res.dat$nb.dif==0 & res.dat$J==4,]
boxplot(h0.rejected.p~dif.size,data=res.null,col=c(2),xlab='DIF size',
ylab='H0 rejection proportion in target scenario',main='No DIF',ylim=c(0,1))
points(y=res.null$h0.rejected.p,x=rep(1,nrow(res.null)),col='#590b0c',pch=3)
# 1 item
res.null <- res.dat[res.dat$eff.size==0 & res.dat$nb.dif==1 & res.dat$J==4,]
boxplot(h0.rejected.p~dif.size,data=res.null,col=c(3,2),xlab='DIF size',
ylab='H0 rejection proportion in target scenario',main='DIF on 1 item',ylim=c(0,1))
res.null3 <- res.null[res.null$dif.size==-0.3,]
points(y=res.null3$h0.rejected.p,x=rep(2,nrow(res.null3)),col='#590b0c',pch=3)
res.null5 <- res.null[res.null$dif.size==-0.5,]
points(y=res.null5$h0.rejected.p,x=rep(1,nrow(res.null5)),col='#053305',pch=3)
# 2 items
res.null <- res.dat[res.dat$eff.size==0 & res.dat$nb.dif==2 & res.dat$J==4,]
boxplot(h0.rejected.p~dif.size,data=res.null,col=c(3,2),xlab='DIF size',
ylab='H0 rejection proportion in target scenario',main='DIF on 2 items',ylim=c(0,1))
res.null3 <- res.null[res.null$dif.size==-0.3,]
points(y=res.null3$h0.rejected.p,x=rep(2,nrow(res.null3)),col='#590b0c',pch=3)
res.null5 <- res.null[res.null$dif.size==-0.5,]
points(y=res.null5$h0.rejected.p,x=rep(1,nrow(res.null5)),col='#053305',pch=3)
par(mfrow=c(1,1))
par(mfrow=c(2,2))
# 0 item
res.null <- res.dat[res.dat$eff.size==0 & res.dat$nb.dif==0 & res.dat$J==7,]
nrow(res.null)
boxplot(h0.rejected.p~dif.size,data=res.null,col=c(2),xlab='DIF size',
ylab='H0 rejection proportion in target scenario',main='No DIF',ylim=c(0,1))
points(y=res.null$h0.rejected.p,x=rep(1,nrow(res.null)),col='#590b0c',pch=3)
# 2 items
res.null <- res.dat[res.dat$eff.size==0 & res.dat$nb.dif==2 & res.dat$J==7,]
boxplot(h0.rejected.p~dif.size,data=res.null,col=c(3,2),xlab='DIF size',
ylab='H0 rejection proportion in target scenario',main='DIF on 2 items',ylim=c(0,1))
res.null3 <- res.null[res.null$dif.size==-0.3,]
points(y=res.null3$h0.rejected.p,x=rep(2,nrow(res.null3)),col='#590b0c',pch=3)
res.null5 <- res.null[res.null$dif.size==-0.5,]
points(y=res.null5$h0.rejected.p,x=rep(1,nrow(res.null5)),col='#053305',pch=3)
# 3 items
res.null <- res.dat[res.dat$eff.size==0 & res.dat$nb.dif==3 & res.dat$J==7,]
boxplot(h0.rejected.p~dif.size,data=res.null,col=c(3,2),xlab='DIF size',
ylab='H0 rejection proportion in target scenario',main='DIF on 3 items',ylim=c(0,1))
res.null3 <- res.null[res.null$dif.size==-0.3,]
points(y=res.null3$h0.rejected.p,x=rep(2,nrow(res.null3)),col='#590b0c',pch=3)
res.null5 <- res.null[res.null$dif.size==-0.5,]
points(y=res.null5$h0.rejected.p,x=rep(1,nrow(res.null5)),col='#053305',pch=3)
par(mfrow=c(1,1))
par(mfrow=c(2,2))
# 0 item
res.null <- res.dat[res.dat$eff.size==0 & res.dat$nb.dif==0 & res.dat$N==100,]
boxplot(h0.rejected.p~dif.size,data=res.null,col=c(2),xlab='DIF size',
ylab='H0 rejection proportion in target scenario',main='No DIF',ylim=c(0,1))
points(y=res.null$h0.rejected.p,x=rep(1,nrow(res.null)),col='#590b0c',pch=3)
# 1 item
res.null <- res.dat[res.dat$eff.size==0 & res.dat$nb.dif==1 & res.dat$N==100,]
boxplot(h0.rejected.p~dif.size,data=res.null,col=c(3,2),xlab='DIF size',
ylab='H0 rejection proportion in target scenario',main='DIF on 1 item',ylim=c(0,1))
res.null3 <- res.null[res.null$dif.size==-0.3,]
points(y=res.null3$h0.rejected.p,x=rep(2,nrow(res.null3)),col='#590b0c',pch=3)
res.null5 <- res.null[res.null$dif.size==-0.5,]
points(y=res.null5$h0.rejected.p,x=rep(1,nrow(res.null5)),col='#053305',pch=3)
# 2 items
res.null <- res.dat[res.dat$eff.size==0 & res.dat$nb.dif==2 & res.dat$N==100,]
boxplot(h0.rejected.p~dif.size,data=res.null,col=c(3,2),xlab='DIF size',
ylab='H0 rejection proportion in target scenario',main='DIF on 2 items',ylim=c(0,1))
res.null3 <- res.null[res.null$dif.size==-0.3,]
points(y=res.null3$h0.rejected.p,x=rep(2,nrow(res.null3)),col='#590b0c',pch=3)
res.null5 <- res.null[res.null$dif.size==-0.5,]
points(y=res.null5$h0.rejected.p,x=rep(1,nrow(res.null5)),col='#053305',pch=3)
# 3 items
res.null <- res.dat[res.dat$eff.size==0 & res.dat$nb.dif==3 & res.dat$N==100,]
boxplot(h0.rejected.p~dif.size,data=res.null,col=c(3,2),xlab='DIF size',
ylab='H0 rejection proportion in target scenario',main='DIF on 3 items',ylim=c(0,1))
res.null3 <- res.null[res.null$dif.size==-0.3,]
points(y=res.null3$h0.rejected.p,x=rep(2,nrow(res.null3)),col='#590b0c',pch=3)
res.null5 <- res.null[res.null$dif.size==-0.5,]
points(y=res.null5$h0.rejected.p,x=rep(1,nrow(res.null5)),col='#053305',pch=3)
par(mfrow=c(1,1))
####### N=200
par(mfrow=c(2,2))
# 0 item
res.null <- res.dat[res.dat$eff.size==0 & res.dat$nb.dif==0 & res.dat$N==200,]
boxplot(h0.rejected.p~dif.size,data=res.null,col=c(2),xlab='DIF size',
ylab='H0 rejection proportion in target scenario',main='No DIF',ylim=c(0,1))
points(y=res.null$h0.rejected.p,x=rep(1,nrow(res.null)),col='#590b0c',pch=3)
# 1 item
res.null <- res.dat[res.dat$eff.size==0 & res.dat$nb.dif==1 & res.dat$N==200,]
boxplot(h0.rejected.p~dif.size,data=res.null,col=c(3,2),xlab='DIF size',
ylab='H0 rejection proportion in target scenario',main='DIF on 1 item',ylim=c(0,1))
res.null3 <- res.null[res.null$dif.size==-0.3,]
points(y=res.null3$h0.rejected.p,x=rep(2,nrow(res.null3)),col='#590b0c',pch=3)
res.null5 <- res.null[res.null$dif.size==-0.5,]
points(y=res.null5$h0.rejected.p,x=rep(1,nrow(res.null5)),col='#053305',pch=3)
# 2 items
res.null <- res.dat[res.dat$eff.size==0 & res.dat$nb.dif==2 & res.dat$N==200,]
boxplot(h0.rejected.p~dif.size,data=res.null,col=c(3,2),xlab='DIF size',
ylab='H0 rejection proportion in target scenario',main='DIF on 2 items',ylim=c(0,1))
res.null3 <- res.null[res.null$dif.size==-0.3,]
points(y=res.null3$h0.rejected.p,x=rep(2,nrow(res.null3)),col='#590b0c',pch=3)
res.null5 <- res.null[res.null$dif.size==-0.5,]
points(y=res.null5$h0.rejected.p,x=rep(1,nrow(res.null5)),col='#053305',pch=3)
# 3 items
res.null <- res.dat[res.dat$eff.size==0 & res.dat$nb.dif==3 & res.dat$N==200,]
boxplot(h0.rejected.p~dif.size,data=res.null,col=c(3,2),xlab='DIF size',
ylab='H0 rejection proportion in target scenario',main='DIF on 3 items',ylim=c(0,1))
res.null3 <- res.null[res.null$dif.size==-0.3,]
points(y=res.null3$h0.rejected.p,x=rep(2,nrow(res.null3)),col='#590b0c',pch=3)
res.null5 <- res.null[res.null$dif.size==-0.5,]
points(y=res.null5$h0.rejected.p,x=rep(1,nrow(res.null5)),col='#053305',pch=3)
par(mfrow=c(1,1))
####### N=300
par(mfrow=c(2,2))
# 0 item
res.null <- res.dat[res.dat$eff.size==0 & res.dat$nb.dif==0 & res.dat$N==300,]
boxplot(h0.rejected.p~dif.size,data=res.null,col=c(2),xlab='DIF size',
ylab='H0 rejection proportion in target scenario',main='No DIF',ylim=c(0,1))
points(y=res.null$h0.rejected.p,x=rep(1,nrow(res.null)),col='#590b0c',pch=3)
# 1 item
res.null <- res.dat[res.dat$eff.size==0 & res.dat$nb.dif==1 & res.dat$N==300,]
boxplot(h0.rejected.p~dif.size,data=res.null,col=c(3,2),xlab='DIF size',
ylab='H0 rejection proportion in target scenario',main='DIF on 1 item',ylim=c(0,1))
res.null3 <- res.null[res.null$dif.size==-0.3,]
points(y=res.null3$h0.rejected.p,x=rep(2,nrow(res.null3)),col='#590b0c',pch=3)
res.null5 <- res.null[res.null$dif.size==-0.5,]
points(y=res.null5$h0.rejected.p,x=rep(1,nrow(res.null5)),col='#053305',pch=3)
# 2 items
res.null <- res.dat[res.dat$eff.size==0 & res.dat$nb.dif==2 & res.dat$N==300,]
boxplot(h0.rejected.p~dif.size,data=res.null,col=c(3,2),xlab='DIF size',
ylab='H0 rejection proportion in target scenario',main='DIF on 2 items',ylim=c(0,1))
res.null3 <- res.null[res.null$dif.size==-0.3,]
points(y=res.null3$h0.rejected.p,x=rep(2,nrow(res.null3)),col='#590b0c',pch=3)
res.null5 <- res.null[res.null$dif.size==-0.5,]
points(y=res.null5$h0.rejected.p,x=rep(1,nrow(res.null5)),col='#053305',pch=3)
# 3 items
res.null <- res.dat[res.dat$eff.size==0 & res.dat$nb.dif==3 & res.dat$N==300,]
boxplot(h0.rejected.p~dif.size,data=res.null,col=c(3,2),xlab='DIF size',
ylab='H0 rejection proportion in target scenario',main='DIF on 3 items',ylim=c(0,1))
res.null3 <- res.null[res.null$dif.size==-0.3,]
points(y=res.null3$h0.rejected.p,x=rep(2,nrow(res.null3)),col='#590b0c',pch=3)
res.null5 <- res.null[res.null$dif.size==-0.5,]
points(y=res.null5$h0.rejected.p,x=rep(1,nrow(res.null5)),col='#053305',pch=3) points(y=res.null5$h0.rejected.p,x=rep(1,nrow(res.null5)),col='#053305',pch=3)
par(mfrow=c(1,1))
res.null <- res.dat[res.dat$eff.size>0,] res.null <- res.dat[res.dat$eff.size>0,]
boxplot(h0.rejected.p~dif.size,data=res.null,col=c(3,2,4,2,3),xlab='DIF size',ylab='H0 rejection proportion in target scenario') boxplot(h0.rejected.p~dif.size,data=res.null,col=c(3,2,4,2,3),xlab='DIF size',ylab='H0 rejection proportion in target scenario')
res.null0 <- res.dat[res.dat$eff.size>0 & res.dat$dif.size==0,] res.null0 <- res.dat[res.dat$eff.size>0 & res.dat$dif.size==0,]
@ -415,6 +427,7 @@ res.null3 <- res.dat[res.dat$eff.size>0 & res.dat$dif.size==0.3,]
points(y=res.null3$h0.rejected.p,x=rep(4,nrow(res.null3)),col='#590b0c',pch=3) points(y=res.null3$h0.rejected.p,x=rep(4,nrow(res.null3)),col='#590b0c',pch=3)
res.null5 <- res.dat[res.dat$eff.size>0 & res.dat$dif.size==0.5,] res.null5 <- res.dat[res.dat$eff.size>0 & res.dat$dif.size==0.5,]
points(y=res.null5$h0.rejected.p,x=rep(5,nrow(res.null5)),col='#053305',pch=3) points(y=res.null5$h0.rejected.p,x=rep(5,nrow(res.null5)),col='#053305',pch=3)
####### N=100
res.null <- res.dat[res.dat$eff.size>0 & res.dat$N==100,] res.null <- res.dat[res.dat$eff.size>0 & res.dat$N==100,]
boxplot(h0.rejected.p~dif.size,data=res.null,col=c(3,2,4,2,3),xlab='DIF size',ylab='H0 rejection proportion in target scenario') boxplot(h0.rejected.p~dif.size,data=res.null,col=c(3,2,4,2,3),xlab='DIF size',ylab='H0 rejection proportion in target scenario')
res.null0 <- res.dat[res.dat$eff.size>0 & res.dat$dif.size==0 & res.dat$N==100,] res.null0 <- res.dat[res.dat$eff.size>0 & res.dat$dif.size==0 & res.dat$N==100,]
@ -427,6 +440,7 @@ res.null3 <- res.dat[res.dat$eff.size>0 & res.dat$dif.size==0.3 & res.dat$N==100
points(y=res.null3$h0.rejected.p,x=rep(4,nrow(res.null3)),col='#590b0c',pch=3) points(y=res.null3$h0.rejected.p,x=rep(4,nrow(res.null3)),col='#590b0c',pch=3)
res.null5 <- res.dat[res.dat$eff.size>0 & res.dat$dif.size==0.5 & res.dat$N==100,] res.null5 <- res.dat[res.dat$eff.size>0 & res.dat$dif.size==0.5 & res.dat$N==100,]
points(y=res.null5$h0.rejected.p,x=rep(5,nrow(res.null5)),col='#053305',pch=3) points(y=res.null5$h0.rejected.p,x=rep(5,nrow(res.null5)),col='#053305',pch=3)
####### N=300 // DIF à 0.5 - QUELS SONT LES SCENARIOS EN HAUT
res.null <- res.dat[res.dat$eff.size>0 & res.dat$N==300,] res.null <- res.dat[res.dat$eff.size>0 & res.dat$N==300,]
boxplot(h0.rejected.p~dif.size,data=res.null,col=c(3,2,4,2,3),xlab='DIF size',ylab='H0 rejection proportion in target scenario') boxplot(h0.rejected.p~dif.size,data=res.null,col=c(3,2,4,2,3),xlab='DIF size',ylab='H0 rejection proportion in target scenario')
res.null0 <- res.dat[res.dat$eff.size>0 & res.dat$dif.size==0 & res.dat$N==300,] res.null0 <- res.dat[res.dat$eff.size>0 & res.dat$dif.size==0 & res.dat$N==300,]
@ -449,10 +463,6 @@ res.null3 <- res.dat[res.dat$eff.size<0 & res.dat$dif.size==-0.3 & res.dat$N==10
points(y=res.null3$h0.rejected.p,x=rep(2,nrow(res.null3)),col='#590b0c',pch=3) points(y=res.null3$h0.rejected.p,x=rep(2,nrow(res.null3)),col='#590b0c',pch=3)
res.null5 <- res.dat[res.dat$eff.size<0 & res.dat$dif.size==-0.5 & res.dat$N==100,] res.null5 <- res.dat[res.dat$eff.size<0 & res.dat$dif.size==-0.5 & res.dat$N==100,]
points(y=res.null5$h0.rejected.p,x=rep(1,nrow(res.null5)),col='#053305',pch=3) points(y=res.null5$h0.rejected.p,x=rep(1,nrow(res.null5)),col='#053305',pch=3)
res.null3 <- res.dat[res.dat$eff.size<0 & res.dat$dif.size==0.3 & res.dat$N==100,]
points(y=res.null3$h0.rejected.p,x=rep(4,nrow(res.null3)),col='#590b0c',pch=3)
res.null5 <- res.dat[res.dat$eff.size<0 & res.dat$dif.size==0.5 & res.dat$N==100,]
points(y=res.null5$h0.rejected.p,x=rep(5,nrow(res.null5)),col='#053305',pch=3)
####### N=300 // DIF à 0.5 - QUELS SONT LES SCENARIOS EN HAUT ####### N=300 // DIF à 0.5 - QUELS SONT LES SCENARIOS EN HAUT
res.null <- res.dat[res.dat$eff.size<0 & res.dat$N==300,] res.null <- res.dat[res.dat$eff.size<0 & res.dat$N==300,]
boxplot(h0.rejected.p~dif.size,data=res.null,col=c(3,2,4,2,3),xlab='DIF size',ylab='H0 rejection proportion in target scenario') boxplot(h0.rejected.p~dif.size,data=res.null,col=c(3,2,4,2,3),xlab='DIF size',ylab='H0 rejection proportion in target scenario')
@ -462,51 +472,41 @@ res.null3 <- res.dat[res.dat$eff.size<0 & res.dat$dif.size==-0.3 & res.dat$N==30
points(y=res.null3$h0.rejected.p,x=rep(2,nrow(res.null3)),col='#590b0c',pch=3) points(y=res.null3$h0.rejected.p,x=rep(2,nrow(res.null3)),col='#590b0c',pch=3)
res.null5 <- res.dat[res.dat$eff.size<0 & res.dat$dif.size==-0.5 & res.dat$N==300,] res.null5 <- res.dat[res.dat$eff.size<0 & res.dat$dif.size==-0.5 & res.dat$N==300,]
points(y=res.null5$h0.rejected.p,x=rep(1,nrow(res.null5)),col='#053305',pch=3) points(y=res.null5$h0.rejected.p,x=rep(1,nrow(res.null5)),col='#053305',pch=3)
res.null3 <- res.dat[res.dat$eff.size<0 & res.dat$dif.size==0.3 & res.dat$N==300,] boxplot(true.value.in.ci.p~dif.size,data=res.dat,col=c(2,3),xlab='DIF size',
points(y=res.null3$h0.rejected.p,x=rep(4,nrow(res.null3)),col='#590b0c',pch=3) ylab='Proportion of true beta value in CI in target scenario',main='DIF on 3 items',ylim=c(0,1))
res.null5 <- res.dat[res.dat$eff.size<0 & res.dat$dif.size==0.5 & res.dat$N==300,] res.null3 <- res.dat[res.dat$dif.size==-0.5,]
points(y=res.null5$h0.rejected.p,x=rep(5,nrow(res.null5)),col='#053305',pch=3) points(y=res.null3$true.value.in.ci.p,x=rep(1,nrow(res.null3)),col='#590b0c',pch=3)
res.null <- res.dat[res.dat$eff.size<0 & res.dat$N==100,] res.null3 <- res.dat[res.dat$dif.size==0.5,]
boxplot(h0.rejected.p~dif.size,data=res.null,col=c(3,2,4,2,3),xlab='DIF size',ylab='H0 rejection proportion in target scenario') points(y=res.null3$true.value.in.ci.p,x=rep(5,nrow(res.null3)),col='#590b0c',pch=3)
res.null0 <- res.dat[res.dat$eff.size<0 & res.dat$dif.size==0 & res.dat$N==100,] res.null3 <- res.dat[res.dat$dif.size==-0.3,]
points(y=res.null0$h0.rejected.p,x=rep(3,nrow(res.null0)),col='darkblue',pch=3) points(y=res.null3$true.value.in.ci.p,x=rep(2,nrow(res.null3)),col='#053305',pch=3)
res.null3 <- res.dat[res.dat$eff.size<0 & res.dat$dif.size==-0.3 & res.dat$N==100,] res.null3 <- res.dat[res.dat$dif.size==0.3,]
points(y=res.null3$h0.rejected.p,x=rep(2,nrow(res.null3)),col='#590b0c',pch=3) points(y=res.null3$true.value.in.ci.p,x=rep(4,nrow(res.null3)),col='#053305',pch=3)
res.null5 <- res.dat[res.dat$eff.size<0 & res.dat$dif.size==-0.5 & res.dat$N==100,] res.null3 <- res.dat[res.dat$dif.size==0,]
points(y=res.null5$h0.rejected.p,x=rep(1,nrow(res.null5)),col='#053305',pch=3) points(y=res.null3$true.value.in.ci.p,x=rep(3,nrow(res.null3)),col='gray',pch=3)
res.null <- res.dat[res.dat$eff.size<0 & res.dat$N==300,] # Overall
boxplot(h0.rejected.p~dif.size,data=res.null,col=c(3,2,4,2,3),xlab='DIF size',ylab='H0 rejection proportion in target scenario') boxplot(beta.same.sign.truebeta.p~dif.size,data=res.dat,col=c(2,3),xlab='DIF size',
res.null0 <- res.dat[res.dat$eff.size<0 & res.dat$dif.size==0 & res.dat$N==300,] ylab='Proportion of estimates with same sign as true value in target scenario',main='DIF on 3 items',ylim=c(0,1))
points(y=res.null0$h0.rejected.p,x=rep(3,nrow(res.null0)),col='darkblue',pch=3) res.null3 <- res.dat[res.dat$dif.size==-0.5,]
res.null3 <- res.dat[res.dat$eff.size<0 & res.dat$dif.size==-0.3 & res.dat$N==300,] points(y=res.null3$beta.same.sign.truebeta.p,x=rep(1,nrow(res.null3)),col='#590b0c',pch=3)
points(y=res.null3$h0.rejected.p,x=rep(2,nrow(res.null3)),col='#590b0c',pch=3) res.null3 <- res.dat[res.dat$dif.size==0.5,]
res.null5 <- res.dat[res.dat$eff.size<0 & res.dat$dif.size==-0.5 & res.dat$N==300,] points(y=res.null3$beta.same.sign.truebeta.p,x=rep(5,nrow(res.null3)),col='#590b0c',pch=3)
points(y=res.null5$h0.rejected.p,x=rep(1,nrow(res.null5)),col='#053305',pch=3) res.null3 <- res.dat[res.dat$dif.size==-0.3,]
res.null <- res.dat[res.dat$eff.size<0 & res.dat$N==100,] points(y=res.null3$beta.same.sign.truebeta.p,x=rep(2,nrow(res.null3)),col='#053305',pch=3)
boxplot(h0.rejected.p~dif.size,data=res.null,col=c(3,2,4,2,3),xlab='DIF size',ylab='H0 rejection proportion in target scenario') res.null3 <- res.dat[res.dat$dif.size==0.3,]
res.null0 <- res.dat[res.dat$eff.size<0 & res.dat$dif.size==0 & res.dat$N==100,] points(y=res.null3$beta.same.sign.truebeta.p,x=rep(4,nrow(res.null3)),col='#053305',pch=3)
points(y=res.null0$h0.rejected.p,x=rep(3,nrow(res.null0)),col='darkblue',pch=3) res.null3 <- res.dat[res.dat$dif.size==0,]
res.null3 <- res.dat[res.dat$eff.size<0 & res.dat$dif.size==-0.3 & res.dat$N==100,] points(y=res.null3$beta.same.sign.truebeta.p,x=rep(3,nrow(res.null3)),col='gray',pch=3)
points(y=res.null3$h0.rejected.p,x=rep(2,nrow(res.null3)),col='#590b0c',pch=3) # Overall // H0 rejected
res.null5 <- res.dat[res.dat$eff.size<0 & res.dat$dif.size==-0.5 & res.dat$N==100,] boxplot(beta.same.sign.truebeta.signif.p~dif.size,data=res.dat,col=c(2,3),xlab='DIF size',
points(y=res.null5$h0.rejected.p,x=rep(1,nrow(res.null5)),col='#053305',pch=3) ylab='Proportion of estimates with same sign as true value in target scenario',main='When H0 rejected',ylim=c(0,1))
muA=5 res.null3 <- res.dat[res.dat$dif.size==-0.5,]
muB=10 points(y=res.null3$beta.same.sign.truebeta.signif.p,x=rep(1,nrow(res.null3)),col='#590b0c',pch=3)
kappa=1 res.null3 <- res.dat[res.dat$dif.size==0.5,]
sd=10 points(y=res.null3$beta.same.sign.truebeta.signif.p,x=rep(5,nrow(res.null3)),col='#590b0c',pch=3)
alpha=0.05 res.null3 <- res.dat[res.dat$dif.size==-0.3,]
beta=0.20 points(y=res.null3$beta.same.sign.truebeta.signif.p,x=rep(2,nrow(res.null3)),col='#053305',pch=3)
(nB=(1+1/kappa)*(sd*(qnorm(1-alpha/2)+qnorm(1-beta))/(muA-muB))^2) res.null3 <- res.dat[res.dat$dif.size==0.3,]
ceiling(nB) # 63 points(y=res.null3$beta.same.sign.truebeta.signif.p,x=rep(4,nrow(res.null3)),col='#053305',pch=3)
z=(muA-muB)/(sd*sqrt((1+1/kappa)/nB)) res.null3 <- res.dat[res.dat$dif.size==0,]
(Power=pnorm(z-qnorm(1-alpha/2))+pnorm(-z-qnorm(1-alpha/2))) points(y=res.null3$beta.same.sign.truebeta.signif.p,x=rep(3,nrow(res.null3)),col='gray',pch=3)
muA=5
muB=10
kappa=1
sd=10
alpha=0.05
beta=0.20
(nB=(1+1/kappa)*(sd*(qnorm(1-alpha/2)+qnorm(1-beta))/(muA-muB))^2)
ceiling(nB) # 63
z=(muA-muB)/(sd*sqrt((1+1/kappa)/nB))
(Power=pnorm(z-qnorm(1-alpha/2))+pnorm(-z-qnorm(1-alpha/2)))

File diff suppressed because it is too large Load Diff

@ -296,6 +296,8 @@ putexcel A1=matrix(outmat), colnames
****** Scenarios with DIF on 2 items ****** Scenarios with DIF on 2 items
* Load pcm.ado
adopath+"/home/corentin/Documents/These/Recherche/Simulations/Modules/"
** Scenario 9: J = 4 items / M = 2 modalities / DIF size 0.3 x2 ** Scenario 9: J = 4 items / M = 2 modalities / DIF size 0.3 x2
local N = "100 200 300" local N = "100 200 300"
@ -427,7 +429,7 @@ forvalues k=1/1000 {
local mod = "`mod'"+"(1.item`i'<-THETA@1)(2.item`i'<-THETA@2)(3.item`i'<-THETA@3)" local mod = "`mod'"+"(1.item`i'<-THETA@1)(2.item`i'<-THETA@2)(3.item`i'<-THETA@3)"
} }
} }
local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent constraint(1 2)" local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent constraint(1 2 3 4)"
qui `constrnt' qui `constrnt'
qui `constrnt2' qui `constrnt2'
qui `constrnt3' qui `constrnt3'
@ -611,7 +613,7 @@ forvalues k=1/1000 {
local mod = "`mod'"+"(1.item`i'<-THETA@1)(2.item`i'<-THETA@2)(3.item`i'<-THETA@3)" local mod = "`mod'"+"(1.item`i'<-THETA@1)(2.item`i'<-THETA@2)(3.item`i'<-THETA@3)"
} }
} }
local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent constraint(1 2)" local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent constraint(1 2 3 4)"
qui `constrnt' qui `constrnt'
qui `constrnt2' qui `constrnt2'
qui `constrnt3' qui `constrnt3'
@ -666,12 +668,14 @@ putexcel A1=matrix(outmat), colnames
*========================== *==========================
* Scenarios with : J=4 * Scenarios with : J=7
*========================== *==========================
****** Scenarios with DIF on 2 items ****** Scenarios with DIF on 2 items
* Load pcm.ado
adopath+"/home/corentin/Documents/These/Recherche/Simulations/Modules/"
** Scenario 13: J = 7 items / M = 2 modalities / DIF size 0.3 x2 ** Scenario 13: J = 7 items / M = 2 modalities / DIF size 0.3 x2
local N = "100 200 300" local N = "100 200 300"
@ -803,7 +807,7 @@ forvalues k=1/1000 {
local mod = "`mod'"+"(1.item`i'<-THETA@1)(2.item`i'<-THETA@2)(3.item`i'<-THETA@3)" local mod = "`mod'"+"(1.item`i'<-THETA@1)(2.item`i'<-THETA@2)(3.item`i'<-THETA@3)"
} }
} }
local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent constraint(1 2)" local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent constraint(1 2 3 4)"
qui `constrnt' qui `constrnt'
qui `constrnt2' qui `constrnt2'
qui `constrnt3' qui `constrnt3'
@ -987,7 +991,7 @@ forvalues k=1/1000 {
local mod = "`mod'"+"(1.item`i'<-THETA@1)(2.item`i'<-THETA@2)(3.item`i'<-THETA@3)" local mod = "`mod'"+"(1.item`i'<-THETA@1)(2.item`i'<-THETA@2)(3.item`i'<-THETA@3)"
} }
} }
local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent constraint(1 2)" local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent constraint(1 2 3 4)"
qui `constrnt' qui `constrnt'
qui `constrnt2' qui `constrnt2'
qui `constrnt3' qui `constrnt3'
@ -1041,6 +1045,8 @@ putexcel A1=matrix(outmat), colnames
***** Scenarios with DIF on 3 items ***** Scenarios with DIF on 3 items
* Load pcm.ado
adopath+"/home/corentin/Documents/These/Recherche/Simulations/Modules/"
** Scenario 17: J = 7 items / M = 2 modalities / DIF size 0.3 x3 ** Scenario 17: J = 7 items / M = 2 modalities / DIF size 0.3 x3
local N = "100 200 300" local N = "100 200 300"
@ -1207,7 +1213,7 @@ forvalues k=1/1000 {
local mod = "`mod'"+"(1.item`i'<-THETA@1)(2.item`i'<-THETA@2)(3.item`i'<-THETA@3)" local mod = "`mod'"+"(1.item`i'<-THETA@1)(2.item`i'<-THETA@2)(3.item`i'<-THETA@3)"
} }
} }
local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent constraint(1 2)" local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent constraint(1 2 3 4 5 6)"
qui `constrnt' qui `constrnt'
qui `constrnt2' qui `constrnt2'
qui `constrnt3' qui `constrnt3'
@ -1440,7 +1446,7 @@ forvalues k=1/1000 {
local mod = "`mod'"+"(1.item`i'<-THETA@1)(2.item`i'<-THETA@2)(3.item`i'<-THETA@3)" local mod = "`mod'"+"(1.item`i'<-THETA@1)(2.item`i'<-THETA@2)(3.item`i'<-THETA@3)"
} }
} }
local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent constraint(1 2)" local mod = "`mod'" + "(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent constraint(1 2 3 4 5 6)"
qui `constrnt' qui `constrnt'
qui `constrnt2' qui `constrnt2'
qui `constrnt3' qui `constrnt3'

Loading…
Cancel
Save