You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
513 lines
24 KiB
R
513 lines
24 KiB
R
zz <- substr(scenario,start=0,stop=nchar(scenario)-4)
|
|
N <- substr(scenario,start=nchar(scenario)-2,stop=nchar(scenario))
|
|
eff.size <- unique(res.dat[res.dat$scenario==zz & res.dat$N==N,'eff.size'])
|
|
dif.size <- unique(res.dat[res.dat$scenario==zz & res.dat$N==N,'dif.size'])
|
|
b <- data.frame(scenario=zz,
|
|
scenario.type=substr(zz,start=nchar(zz),stop=nchar(zz)),
|
|
N=N,
|
|
J=J,
|
|
M=M,
|
|
eff.size=eff.size,
|
|
nb.dif=nb.dif,
|
|
dif.size=dif.size
|
|
)
|
|
true.value.in.ci <- eff.size > s$beta+1.96*s$se_beta | eff.size < s$beta-1.96*s$se_beta
|
|
z <- data.frame(m.beta=mean(s$beta),
|
|
se.empirical.beta=sd(s$beta),
|
|
se.analytical.beta=mean(s$se_beta),
|
|
m.low.ci.beta=mean(s$beta-1.96*s$se_beta),
|
|
m.high.ci.beta=mean(s$beta+1.96*s$se_beta),
|
|
true.value.in.ci=mean(true.value.in.ci),
|
|
h0.rejected.p=mean( (s$beta-1.96*s$se_beta)>0 | (s$beta+1.96*s$se_beta)<0 ))
|
|
d <- cbind(b,a,z)
|
|
d$prop.
|
|
return(d)
|
|
}
|
|
#### Compiled results
|
|
res.dat.dif <- compile_simulation2('5A_100')
|
|
for (x in results[seq(2,length(results))]) {
|
|
y <- compile_simulation2(x)
|
|
res.dat.dif <- bind_rows(res.dat.dif,y)
|
|
}
|
|
res.dat.dif
|
|
#### 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)[61:396]
|
|
#### Compiler function
|
|
compile_simulation2 <- 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_excel(paste0('/home/corentin/Documents/These/Recherche/Simulations/Analysis/DIF/N100/',scenario,'.xls'))
|
|
}
|
|
if (substr(scenario,start=nchar(scenario)-2,stop=nchar(scenario))=="200" & name>4) {
|
|
s <- read_excel(paste0('/home/corentin/Documents/These/Recherche/Simulations/Analysis/DIF/N200/',scenario,'.xls'))
|
|
}
|
|
if (substr(scenario,start=nchar(scenario)-2,stop=nchar(scenario))=="300" & name>4) {
|
|
s <- read_excel(paste0('/home/corentin/Documents/These/Recherche/Simulations/Analysis/DIF/N300/',scenario,'.xls'))
|
|
}
|
|
J <- max(which(sapply(1:7,function(x) paste0('item',x) %in% colnames(s) | paste0('item',x,'_1') %in% colnames(s))))
|
|
M <- 1+sum(sapply(1:3,function(x) paste0('item1_',x) %in% colnames(s) ))
|
|
if (M==1) {M <- 2}
|
|
nb.dif <- max(which(sapply(1:3,function(x) paste0('dif',x) %in% colnames(s) | paste0('dif',x,'_1') %in% colnames(s))))
|
|
if (J==4) {
|
|
if (M==2) {
|
|
a <- data.frame(m.item1=mean(s$item1),m.item2=mean(s$item2),m.item3=mean(s$item3),m.item4=mean(s$item4))
|
|
} 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),
|
|
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),
|
|
m.item4_1=mean(s$item4_1),m.item4_2=mean(s$item4_2),m.item4_3=mean(s$item4_3)
|
|
)
|
|
}
|
|
} else {
|
|
if (M==2) {
|
|
a <- data.frame(m.item1=mean(s$item1),m.item2=mean(s$item2),m.item3=mean(s$item3),m.item4=mean(s$item4),
|
|
m.item5=mean(s$item5),m.item6=mean(s$item6),m.item7=mean(s$item7))
|
|
} 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),
|
|
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),
|
|
m.item4_1=mean(s$item4_1),m.item4_2=mean(s$item4_2),m.item4_3=mean(s$item4_3),
|
|
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)
|
|
)
|
|
}
|
|
}
|
|
zz <- substr(scenario,start=0,stop=nchar(scenario)-4)
|
|
N <- substr(scenario,start=nchar(scenario)-2,stop=nchar(scenario))
|
|
eff.size <- unique(res.dat[res.dat$scenario==zz & res.dat$N==N,'eff.size'])
|
|
dif.size <- unique(res.dat[res.dat$scenario==zz & res.dat$N==N,'dif.size'])
|
|
b <- data.frame(scenario=zz,
|
|
scenario.type=substr(zz,start=nchar(zz),stop=nchar(zz)),
|
|
N=N,
|
|
J=J,
|
|
M=M,
|
|
eff.size=eff.size,
|
|
nb.dif=nb.dif,
|
|
dif.size=dif.size
|
|
)
|
|
true.value.in.ci <- eff.size <= s$beta+1.96*s$se_beta & eff.size >= s$beta-1.96*s$se_beta
|
|
z <- data.frame(m.beta=mean(s$beta),
|
|
se.empirical.beta=sd(s$beta),
|
|
se.analytical.beta=mean(s$se_beta),
|
|
m.low.ci.beta=mean(s$beta-1.96*s$se_beta),
|
|
m.high.ci.beta=mean(s$beta+1.96*s$se_beta),
|
|
true.value.in.ci=mean(true.value.in.ci),
|
|
h0.rejected.p=mean( (s$beta-1.96*s$se_beta)>0 | (s$beta+1.96*s$se_beta)<0 ))
|
|
d <- cbind(b,a,z)
|
|
d$prop.
|
|
return(d)
|
|
}
|
|
#### Compiled results
|
|
res.dat.dif <- compile_simulation2('5A_100')
|
|
for (x in results[seq(2,length(results))]) {
|
|
y <- compile_simulation2(x)
|
|
res.dat.dif <- bind_rows(res.dat.dif,y)
|
|
}
|
|
res.dat.dif
|
|
which((s$beta-1.96*s$se_beta)>0 | (s$beta+1.96*s$se_beta)<0)
|
|
#### 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)[61:396]
|
|
#### Compiler function
|
|
compile_simulation2 <- 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_excel(paste0('/home/corentin/Documents/These/Recherche/Simulations/Analysis/DIF/N100/',scenario,'.xls'))
|
|
}
|
|
if (substr(scenario,start=nchar(scenario)-2,stop=nchar(scenario))=="200" & name>4) {
|
|
s <- read_excel(paste0('/home/corentin/Documents/These/Recherche/Simulations/Analysis/DIF/N200/',scenario,'.xls'))
|
|
}
|
|
if (substr(scenario,start=nchar(scenario)-2,stop=nchar(scenario))=="300" & name>4) {
|
|
s <- read_excel(paste0('/home/corentin/Documents/These/Recherche/Simulations/Analysis/DIF/N300/',scenario,'.xls'))
|
|
}
|
|
J <- max(which(sapply(1:7,function(x) paste0('item',x) %in% colnames(s) | paste0('item',x,'_1') %in% colnames(s))))
|
|
M <- 1+sum(sapply(1:3,function(x) paste0('item1_',x) %in% colnames(s) ))
|
|
if (M==1) {M <- 2}
|
|
nb.dif <- max(which(sapply(1:3,function(x) paste0('dif',x) %in% colnames(s) | paste0('dif',x,'_1') %in% colnames(s))))
|
|
if (J==4) {
|
|
if (M==2) {
|
|
a <- data.frame(m.item1=mean(s$item1),m.item2=mean(s$item2),m.item3=mean(s$item3),m.item4=mean(s$item4))
|
|
} 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),
|
|
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),
|
|
m.item4_1=mean(s$item4_1),m.item4_2=mean(s$item4_2),m.item4_3=mean(s$item4_3)
|
|
)
|
|
}
|
|
} else {
|
|
if (M==2) {
|
|
a <- data.frame(m.item1=mean(s$item1),m.item2=mean(s$item2),m.item3=mean(s$item3),m.item4=mean(s$item4),
|
|
m.item5=mean(s$item5),m.item6=mean(s$item6),m.item7=mean(s$item7))
|
|
} 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),
|
|
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),
|
|
m.item4_1=mean(s$item4_1),m.item4_2=mean(s$item4_2),m.item4_3=mean(s$item4_3),
|
|
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)
|
|
)
|
|
}
|
|
}
|
|
zz <- substr(scenario,start=0,stop=nchar(scenario)-4)
|
|
N <- substr(scenario,start=nchar(scenario)-2,stop=nchar(scenario))
|
|
eff.size <- unique(res.dat[res.dat$scenario==zz & res.dat$N==N,'eff.size'])
|
|
dif.size <- unique(res.dat[res.dat$scenario==zz & res.dat$N==N,'dif.size'])
|
|
b <- data.frame(scenario=zz,
|
|
scenario.type=substr(zz,start=nchar(zz),stop=nchar(zz)),
|
|
N=N,
|
|
J=J,
|
|
M=M,
|
|
eff.size=eff.size,
|
|
nb.dif=nb.dif,
|
|
dif.size=dif.size
|
|
)
|
|
true.value.in.ci <- eff.size <= s$beta+1.96*s$se_beta & eff.size >= s$beta-1.96*s$se_beta
|
|
beta.same.sign.truebeta.p <- ifelse(eff.size==0,NA,eff.size/s$beta>0)
|
|
num.reject <- which((s$beta-1.96*s$se_beta)>0 | (s$beta+1.96*s$se_beta)<0)
|
|
z <- data.frame(m.beta=mean(s$beta),
|
|
se.empirical.beta=sd(s$beta),
|
|
se.analytical.beta=mean(s$se_beta),
|
|
m.low.ci.beta=mean(s$beta-1.96*s$se_beta),
|
|
m.high.ci.beta=mean(s$beta+1.96*s$se_beta),
|
|
true.value.in.ci.p=mean(true.value.in.ci),
|
|
h0.rejected.p=mean( (s$beta-1.96*s$se_beta)>0 | (s$beta+1.96*s$se_beta)<0 ),
|
|
beta.same.sign.truebeta.p=mean(beta.same.sign.truebeta.p),
|
|
beta.same.sign.truebeta.signif.p=mean(beta.same.sign.truebeta.p[num.reject])
|
|
)
|
|
d <- cbind(b,a,z)
|
|
d$prop.
|
|
return(d)
|
|
}
|
|
#### Compiled results
|
|
res.dat.dif <- compile_simulation2('5A_100')
|
|
for (x in results[seq(2,length(results))]) {
|
|
y <- compile_simulation2(x)
|
|
res.dat.dif <- bind_rows(res.dat.dif,y)
|
|
}
|
|
res.dat.dif
|
|
ifelse(eff.size==0,NA,eff.size/s$beta>0)
|
|
ifelse(0==0,NA,0/s$beta>0)
|
|
s <- read.csv(paste0('/home/corentin/Documents/These/Recherche/Simulations/Analysis/DIF/N100/',"5C_100",'.xls'))
|
|
s <- read_excel(paste0('/home/corentin/Documents/These/Recherche/Simulations/Analysis/DIF/N100/',"5C_100",'.xls'))
|
|
s$beta
|
|
0.2/s$beta
|
|
0.2/s$beta>0
|
|
mean(0.2/s$beta>0)
|
|
#### 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)[61:396]
|
|
#### Compiler function
|
|
compile_simulation2 <- 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_excel(paste0('/home/corentin/Documents/These/Recherche/Simulations/Analysis/DIF/N100/',scenario,'.xls'))
|
|
}
|
|
if (substr(scenario,start=nchar(scenario)-2,stop=nchar(scenario))=="200" & name>4) {
|
|
s <- read_excel(paste0('/home/corentin/Documents/These/Recherche/Simulations/Analysis/DIF/N200/',scenario,'.xls'))
|
|
}
|
|
if (substr(scenario,start=nchar(scenario)-2,stop=nchar(scenario))=="300" & name>4) {
|
|
s <- read_excel(paste0('/home/corentin/Documents/These/Recherche/Simulations/Analysis/DIF/N300/',scenario,'.xls'))
|
|
}
|
|
J <- max(which(sapply(1:7,function(x) paste0('item',x) %in% colnames(s) | paste0('item',x,'_1') %in% colnames(s))))
|
|
M <- 1+sum(sapply(1:3,function(x) paste0('item1_',x) %in% colnames(s) ))
|
|
if (M==1) {M <- 2}
|
|
nb.dif <- max(which(sapply(1:3,function(x) paste0('dif',x) %in% colnames(s) | paste0('dif',x,'_1') %in% colnames(s))))
|
|
if (J==4) {
|
|
if (M==2) {
|
|
a <- data.frame(m.item1=mean(s$item1),m.item2=mean(s$item2),m.item3=mean(s$item3),m.item4=mean(s$item4))
|
|
} 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),
|
|
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),
|
|
m.item4_1=mean(s$item4_1),m.item4_2=mean(s$item4_2),m.item4_3=mean(s$item4_3)
|
|
)
|
|
}
|
|
} else {
|
|
if (M==2) {
|
|
a <- data.frame(m.item1=mean(s$item1),m.item2=mean(s$item2),m.item3=mean(s$item3),m.item4=mean(s$item4),
|
|
m.item5=mean(s$item5),m.item6=mean(s$item6),m.item7=mean(s$item7))
|
|
} 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),
|
|
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),
|
|
m.item4_1=mean(s$item4_1),m.item4_2=mean(s$item4_2),m.item4_3=mean(s$item4_3),
|
|
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)
|
|
)
|
|
}
|
|
}
|
|
zz <- substr(scenario,start=0,stop=nchar(scenario)-4)
|
|
N <- substr(scenario,start=nchar(scenario)-2,stop=nchar(scenario))
|
|
eff.size <- unique(res.dat[res.dat$scenario==zz & res.dat$N==N,'eff.size'])
|
|
dif.size <- unique(res.dat[res.dat$scenario==zz & res.dat$N==N,'dif.size'])
|
|
b <- data.frame(scenario=zz,
|
|
scenario.type=substr(zz,start=nchar(zz),stop=nchar(zz)),
|
|
N=N,
|
|
J=J,
|
|
M=M,
|
|
eff.size=eff.size,
|
|
nb.dif=nb.dif,
|
|
dif.size=dif.size
|
|
)
|
|
true.value.in.ci <- eff.size <= s$beta+1.96*s$se_beta & eff.size >= s$beta-1.96*s$se_beta
|
|
beta.same.sign.truebeta.p <- ifelse(eff.size==0,NA,(eff.size/s$beta)>0)
|
|
num.reject <- which((s$beta-1.96*s$se_beta)>0 | (s$beta+1.96*s$se_beta)<0)
|
|
z <- data.frame(m.beta=mean(s$beta),
|
|
se.empirical.beta=sd(s$beta),
|
|
se.analytical.beta=mean(s$se_beta),
|
|
m.low.ci.beta=mean(s$beta-1.96*s$se_beta),
|
|
m.high.ci.beta=mean(s$beta+1.96*s$se_beta),
|
|
true.value.in.ci.p=mean(true.value.in.ci),
|
|
h0.rejected.p=mean( (s$beta-1.96*s$se_beta)>0 | (s$beta+1.96*s$se_beta)<0 ),
|
|
beta.same.sign.truebeta.p=mean(beta.same.sign.truebeta.p),
|
|
beta.same.sign.truebeta.signif.p=mean(beta.same.sign.truebeta.p[num.reject])
|
|
)
|
|
d <- cbind(b,a,z)
|
|
d$prop.
|
|
return(d)
|
|
}
|
|
#### Compiled results
|
|
res.dat.dif <- compile_simulation2('5A_100')
|
|
for (x in results[seq(2,length(results))]) {
|
|
y <- compile_simulation2(x)
|
|
res.dat.dif <- bind_rows(res.dat.dif,y)
|
|
}
|
|
res.dat.dif
|
|
#### 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)[61:396]
|
|
#### Compiler function
|
|
compile_simulation2 <- 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_excel(paste0('/home/corentin/Documents/These/Recherche/Simulations/Analysis/DIF/N100/',scenario,'.xls'))
|
|
}
|
|
if (substr(scenario,start=nchar(scenario)-2,stop=nchar(scenario))=="200" & name>4) {
|
|
s <- read_excel(paste0('/home/corentin/Documents/These/Recherche/Simulations/Analysis/DIF/N200/',scenario,'.xls'))
|
|
}
|
|
if (substr(scenario,start=nchar(scenario)-2,stop=nchar(scenario))=="300" & name>4) {
|
|
s <- read_excel(paste0('/home/corentin/Documents/These/Recherche/Simulations/Analysis/DIF/N300/',scenario,'.xls'))
|
|
}
|
|
J <- max(which(sapply(1:7,function(x) paste0('item',x) %in% colnames(s) | paste0('item',x,'_1') %in% colnames(s))))
|
|
M <- 1+sum(sapply(1:3,function(x) paste0('item1_',x) %in% colnames(s) ))
|
|
if (M==1) {M <- 2}
|
|
nb.dif <- max(which(sapply(1:3,function(x) paste0('dif',x) %in% colnames(s) | paste0('dif',x,'_1') %in% colnames(s))))
|
|
if (J==4) {
|
|
if (M==2) {
|
|
a <- data.frame(m.item1=mean(s$item1),m.item2=mean(s$item2),m.item3=mean(s$item3),m.item4=mean(s$item4))
|
|
} 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),
|
|
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),
|
|
m.item4_1=mean(s$item4_1),m.item4_2=mean(s$item4_2),m.item4_3=mean(s$item4_3)
|
|
)
|
|
}
|
|
} else {
|
|
if (M==2) {
|
|
a <- data.frame(m.item1=mean(s$item1),m.item2=mean(s$item2),m.item3=mean(s$item3),m.item4=mean(s$item4),
|
|
m.item5=mean(s$item5),m.item6=mean(s$item6),m.item7=mean(s$item7))
|
|
} 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),
|
|
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),
|
|
m.item4_1=mean(s$item4_1),m.item4_2=mean(s$item4_2),m.item4_3=mean(s$item4_3),
|
|
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)
|
|
)
|
|
}
|
|
}
|
|
zz <- substr(scenario,start=0,stop=nchar(scenario)-4)
|
|
N <- substr(scenario,start=nchar(scenario)-2,stop=nchar(scenario))
|
|
eff.size <- unique(res.dat[res.dat$scenario==zz & res.dat$N==N,'eff.size'])
|
|
dif.size <- unique(res.dat[res.dat$scenario==zz & res.dat$N==N,'dif.size'])
|
|
b <- data.frame(scenario=zz,
|
|
scenario.type=substr(zz,start=nchar(zz),stop=nchar(zz)),
|
|
N=N,
|
|
J=J,
|
|
M=M,
|
|
eff.size=eff.size,
|
|
nb.dif=nb.dif,
|
|
dif.size=dif.size
|
|
)
|
|
true.value.in.ci <- eff.size <= s$beta+1.96*s$se_beta & eff.size >= s$beta-1.96*s$se_beta
|
|
beta.same.sign.truebeta.p <- ifelse(eff.size==0,NA,(eff.size/s$beta)>0)
|
|
print(beta.same.sign.truebeta.p)
|
|
num.reject <- which((s$beta-1.96*s$se_beta)>0 | (s$beta+1.96*s$se_beta)<0)
|
|
z <- data.frame(m.beta=mean(s$beta),
|
|
se.empirical.beta=sd(s$beta),
|
|
se.analytical.beta=mean(s$se_beta),
|
|
m.low.ci.beta=mean(s$beta-1.96*s$se_beta),
|
|
m.high.ci.beta=mean(s$beta+1.96*s$se_beta),
|
|
true.value.in.ci.p=mean(true.value.in.ci),
|
|
h0.rejected.p=mean( (s$beta-1.96*s$se_beta)>0 | (s$beta+1.96*s$se_beta)<0 ),
|
|
beta.same.sign.truebeta.p=mean(beta.same.sign.truebeta.p),
|
|
beta.same.sign.truebeta.signif.p=mean(beta.same.sign.truebeta.p[num.reject])
|
|
)
|
|
d <- cbind(b,a,z)
|
|
d$prop.
|
|
return(d)
|
|
}
|
|
#### Compiled results
|
|
res.dat.dif <- compile_simulation2('5A_100')
|
|
for (x in results[seq(2,length(results))]) {
|
|
y <- compile_simulation2(x)
|
|
res.dat.dif <- bind_rows(res.dat.dif,y)
|
|
}
|
|
#### 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)[61:396]
|
|
#### Compiler function
|
|
compile_simulation2 <- 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_excel(paste0('/home/corentin/Documents/These/Recherche/Simulations/Analysis/DIF/N100/',scenario,'.xls'))
|
|
}
|
|
if (substr(scenario,start=nchar(scenario)-2,stop=nchar(scenario))=="200" & name>4) {
|
|
s <- read_excel(paste0('/home/corentin/Documents/These/Recherche/Simulations/Analysis/DIF/N200/',scenario,'.xls'))
|
|
}
|
|
if (substr(scenario,start=nchar(scenario)-2,stop=nchar(scenario))=="300" & name>4) {
|
|
s <- read_excel(paste0('/home/corentin/Documents/These/Recherche/Simulations/Analysis/DIF/N300/',scenario,'.xls'))
|
|
}
|
|
J <- max(which(sapply(1:7,function(x) paste0('item',x) %in% colnames(s) | paste0('item',x,'_1') %in% colnames(s))))
|
|
M <- 1+sum(sapply(1:3,function(x) paste0('item1_',x) %in% colnames(s) ))
|
|
if (M==1) {M <- 2}
|
|
nb.dif <- max(which(sapply(1:3,function(x) paste0('dif',x) %in% colnames(s) | paste0('dif',x,'_1') %in% colnames(s))))
|
|
if (J==4) {
|
|
if (M==2) {
|
|
a <- data.frame(m.item1=mean(s$item1),m.item2=mean(s$item2),m.item3=mean(s$item3),m.item4=mean(s$item4))
|
|
} 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),
|
|
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),
|
|
m.item4_1=mean(s$item4_1),m.item4_2=mean(s$item4_2),m.item4_3=mean(s$item4_3)
|
|
)
|
|
}
|
|
} else {
|
|
if (M==2) {
|
|
a <- data.frame(m.item1=mean(s$item1),m.item2=mean(s$item2),m.item3=mean(s$item3),m.item4=mean(s$item4),
|
|
m.item5=mean(s$item5),m.item6=mean(s$item6),m.item7=mean(s$item7))
|
|
} 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),
|
|
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),
|
|
m.item4_1=mean(s$item4_1),m.item4_2=mean(s$item4_2),m.item4_3=mean(s$item4_3),
|
|
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)
|
|
)
|
|
}
|
|
}
|
|
zz <- substr(scenario,start=0,stop=nchar(scenario)-4)
|
|
N <- substr(scenario,start=nchar(scenario)-2,stop=nchar(scenario))
|
|
eff.size <- unique(res.dat[res.dat$scenario==zz & res.dat$N==N,'eff.size'])
|
|
dif.size <- unique(res.dat[res.dat$scenario==zz & res.dat$N==N,'dif.size'])
|
|
b <- data.frame(scenario=zz,
|
|
scenario.type=substr(zz,start=nchar(zz),stop=nchar(zz)),
|
|
N=N,
|
|
J=J,
|
|
M=M,
|
|
eff.size=eff.size,
|
|
nb.dif=nb.dif,
|
|
dif.size=dif.size
|
|
)
|
|
true.value.in.ci <- eff.size <= s$beta+1.96*s$se_beta & eff.size >= s$beta-1.96*s$se_beta
|
|
beta.same.sign.truebeta.p <- ifelse(rep(eff.size,nrow(s))==0,NA,(rep(eff.size,nrow(s))/s$beta)>0)
|
|
num.reject <- which((s$beta-1.96*s$se_beta)>0 | (s$beta+1.96*s$se_beta)<0)
|
|
z <- data.frame(m.beta=mean(s$beta),
|
|
se.empirical.beta=sd(s$beta),
|
|
se.analytical.beta=mean(s$se_beta),
|
|
m.low.ci.beta=mean(s$beta-1.96*s$se_beta),
|
|
m.high.ci.beta=mean(s$beta+1.96*s$se_beta),
|
|
true.value.in.ci.p=mean(true.value.in.ci),
|
|
h0.rejected.p=mean( (s$beta-1.96*s$se_beta)>0 | (s$beta+1.96*s$se_beta)<0 ),
|
|
beta.same.sign.truebeta.p=mean(beta.same.sign.truebeta.p),
|
|
beta.same.sign.truebeta.signif.p=mean(beta.same.sign.truebeta.p[num.reject])
|
|
)
|
|
d <- cbind(b,a,z)
|
|
d$prop.
|
|
return(d)
|
|
}
|
|
#### Compiled results
|
|
res.dat.dif <- compile_simulation2('5A_100')
|
|
for (x in results[seq(2,length(results))]) {
|
|
y <- compile_simulation2(x)
|
|
res.dat.dif <- bind_rows(res.dat.dif,y)
|
|
}
|
|
res.dat.dif
|
|
## Proportion of rejected h0 per dif value in h0 scenarios (A) by DIF size
|
|
res.null <- res.dat.dif[res.dat.dif$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')
|
|
res.null0 <- res.dat.dif[res.dat.dif$eff.size==0 & res.dat.dif$dif.size==0,]
|
|
points(y=res.null0$h0.rejected.p,x=rep(3,nrow(res.null0)),col='gray',pch=3)
|
|
res.null3 <- res.dat.dif[res.dat.dif$eff.size==0 & res.dat.dif$dif.size==-0.3,]
|
|
points(y=res.null3$h0.rejected.p,x=rep(2,nrow(res.null3)),col='#590b0c',pch=3)
|
|
res.null5 <- res.dat.dif[res.dat.dif$eff.size==0 & res.dat.dif$dif.size==-0.5,]
|
|
points(y=res.null5$h0.rejected.p,x=rep(1,nrow(res.null5)),col='#053305',pch=3)
|
|
par(mfrow=c(2,2))
|
|
# 0 item
|
|
res.null <- res.dat.dif[res.dat.dif$eff.size==0 & res.dat.dif$nb.dif==0,]
|
|
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))
|
|
par(mfrow=c(2,2))
|
|
# 0 item
|
|
res.null <- res.dat.dif[res.dat.dif$eff.size==0 & res.dat.dif$nb.dif==0,]
|
|
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))
|
|
res.null
|
|
par(mfrow=c(2,2))
|
|
# 1 item
|
|
res.null <- res.dat.dif[res.dat.dif$eff.size==0 & res.dat.dif$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)
|
|
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.dif[res.dat.dif$eff.size==0 & res.dat.dif$nb.dif==2,]
|
|
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.dif[res.dat.dif$eff.size==0 & res.dat.dif$nb.dif==3,]
|
|
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))
|