R script for analysis 1-4A
This commit is contained in:
BIN
RProject/.RData
BIN
RProject/.RData
Binary file not shown.
@ -1,28 +1,24 @@
|
|||||||
|
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 {
|
||||||
|
returndat$beta.same.sign.truebeta <- 1*(sign(truebeta)==sign(returndat$beta))
|
||||||
}
|
}
|
||||||
#######################################
|
returndat2 <- data.frame(J=rep(nbitems,max(df[,sequence])),
|
||||||
## SCENARIO ANALYSIS
|
M=1+max(df$item1),
|
||||||
#######################################
|
N=nrow(df[df$replication==1,])/2,
|
||||||
registerDoMC(4)
|
eff.size=eff.size,
|
||||||
######### Scenario 1: J=4 / M=2 / H_0 TRUE
|
dif.size= difsize,
|
||||||
dat1 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N100/scenario_1A_100.csv')
|
nb.dif= nbdif
|
||||||
dat2 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N100/scenario_1A_100.csv')
|
)
|
||||||
dat3 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N100/scenario_1A_100.csv')
|
returndat <- cbind(returndat2,returndat)
|
||||||
replicate_pcm_analysis(dat1)
|
return(returndat)
|
||||||
pcm_analysis <- function(df=NULL,treatment='TT',irtmodel='PCM2',method='MML') {
|
|
||||||
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 (method=='JML') {
|
replicate_pcm_analysis_m2 <- function(df=NULL,treatment='TT',irtmodel='PCM2',method='MML',sequence='replication',truebeta=0,eff.size=0,difsize=NA,nbdif=0) {
|
||||||
tam1 <- tam.jml(resp=resp,group=1+df[,treatment])
|
|
||||||
}
|
|
||||||
if (method!='MML' & method!='JML') {
|
|
||||||
stop('Invalid method. Please choose among MML or JML')
|
|
||||||
}
|
|
||||||
return(tam1)
|
|
||||||
}
|
|
||||||
replicate_pcm_analysis <- function(df=NULL,treatment='TT',irtmodel='PCM2',method='MML',sequence='replication',truebeta=0,eff.size=0,difsize=NA,nbdif=0) {
|
|
||||||
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))]
|
||||||
if (method=='MML') {
|
if (method=='MML') {
|
||||||
@ -61,452 +57,456 @@ nb.dif= nbdif
|
|||||||
returndat <- cbind(returndat2,returndat)
|
returndat <- cbind(returndat2,returndat)
|
||||||
return(returndat)
|
return(returndat)
|
||||||
}
|
}
|
||||||
replicate_pcm_analysis(dat1)
|
replicate_pcm_analysis_m4(dat1[dat1$replication==1,])
|
||||||
########################################
|
|
||||||
## LIBRARIES
|
|
||||||
########################################
|
|
||||||
library(TAM)
|
|
||||||
library(doMC)
|
|
||||||
library(parallel)
|
|
||||||
library(pbmcapply)
|
|
||||||
library(SimDesign)
|
|
||||||
#######################################
|
|
||||||
## ANALYSIS FUNCTIONS
|
|
||||||
#######################################
|
|
||||||
pcm_analysis <- function(df=NULL,treatment='TT',irtmodel='PCM2',method='MML') {
|
|
||||||
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 <- quiet(tam.mml(resp=resp,Y=df[,treatment],irtmodel = irtmodel,est.variance = T,verbose=F))
|
|
||||||
}
|
|
||||||
if (method=='JML') {
|
|
||||||
tam1 <- tam.jml(resp=resp,group=1+df[,treatment])
|
|
||||||
}
|
|
||||||
if (method!='MML' & method!='JML') {
|
|
||||||
stop('Invalid method. Please choose among MML or JML')
|
|
||||||
}
|
|
||||||
return(tam1)
|
|
||||||
}
|
|
||||||
replicate_pcm_analysis <- function(df=NULL,treatment='TT',irtmodel='PCM2',method='MML',sequence='replication',truebeta=0,eff.size=0,difsize=NA,nbdif=0) {
|
|
||||||
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') {
|
|
||||||
n <- max(df[,sequence])
|
|
||||||
print(n)
|
|
||||||
tam1 <- pbmclapply(seq(1,n),
|
|
||||||
function(x) pcm_analysis(df=df[df[,sequence]==x,],treatment=treatment,irtmodel=irtmodel)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
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]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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 {
|
|
||||||
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=eff.size,
|
|
||||||
dif.size= difsize,
|
|
||||||
nb.dif= nbdif
|
|
||||||
)
|
|
||||||
returndat <- cbind(returndat2,returndat)
|
|
||||||
return(returndat)
|
|
||||||
}
|
|
||||||
#######################################
|
|
||||||
## SCENARIO ANALYSIS
|
|
||||||
#######################################
|
|
||||||
registerDoMC(4)
|
|
||||||
######### Scenario 1: J=4 / M=2 / H_0 TRUE
|
|
||||||
dat1 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N100/scenario_1A_100.csv')
|
|
||||||
dat2 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N100/scenario_1A_100.csv')
|
|
||||||
dat3 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N100/scenario_1A_100.csv')
|
|
||||||
replicate_pcm_analysis(dat1)
|
|
||||||
########################################
|
|
||||||
## LIBRARIES
|
|
||||||
########################################
|
|
||||||
library(TAM)
|
|
||||||
library(doMC)
|
|
||||||
library(parallel)
|
|
||||||
library(pbmcapply)
|
|
||||||
#######################################
|
|
||||||
## ANALYSIS FUNCTIONS
|
|
||||||
#######################################
|
|
||||||
pcm_analysis <- function(df=NULL,treatment='TT',irtmodel='PCM2',method='MML') {
|
|
||||||
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 <- invisible(tam.mml(resp=resp,Y=df[,treatment],irtmodel = irtmodel,est.variance = T,verbose=F))
|
|
||||||
}
|
|
||||||
if (method=='JML') {
|
|
||||||
tam1 <- tam.jml(resp=resp,group=1+df[,treatment])
|
|
||||||
}
|
|
||||||
if (method!='MML' & method!='JML') {
|
|
||||||
stop('Invalid method. Please choose among MML or JML')
|
|
||||||
}
|
|
||||||
return(tam1)
|
|
||||||
}
|
|
||||||
replicate_pcm_analysis <- function(df=NULL,treatment='TT',irtmodel='PCM2',method='MML',sequence='replication',truebeta=0,eff.size=0,difsize=NA,nbdif=0) {
|
|
||||||
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') {
|
|
||||||
n <- max(df[,sequence])
|
|
||||||
print(n)
|
|
||||||
tam1 <- pbmclapply(seq(1,n),
|
|
||||||
function(x) pcm_analysis(df=df[df[,sequence]==x,],treatment=treatment,irtmodel=irtmodel)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
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]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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 {
|
|
||||||
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=eff.size,
|
|
||||||
dif.size= difsize,
|
|
||||||
nb.dif= nbdif
|
|
||||||
)
|
|
||||||
returndat <- cbind(returndat2,returndat)
|
|
||||||
return(returndat)
|
|
||||||
}
|
|
||||||
#######################################
|
|
||||||
## SCENARIO ANALYSIS
|
|
||||||
#######################################
|
|
||||||
registerDoMC(4)
|
|
||||||
######### Scenario 1: J=4 / M=2 / H_0 TRUE
|
|
||||||
dat1 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N100/scenario_1A_100.csv')
|
|
||||||
dat2 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N100/scenario_1A_100.csv')
|
|
||||||
dat3 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N100/scenario_1A_100.csv')
|
|
||||||
replicate_pcm_analysis(dat1)
|
|
||||||
########################################
|
|
||||||
## LIBRARIES
|
|
||||||
########################################
|
|
||||||
library(TAM)
|
|
||||||
library(doMC)
|
|
||||||
library(parallel)
|
|
||||||
library(pbmcapply)
|
|
||||||
library(SimDesign)
|
|
||||||
#######################################
|
|
||||||
## ANALYSIS FUNCTIONS
|
|
||||||
#######################################
|
|
||||||
pcm_analysis <- function(df=NULL,treatment='TT',irtmodel='PCM2',method='MML') {
|
|
||||||
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 <- quiet(tam.mml(resp=resp,Y=df[,treatment],irtmodel = irtmodel,est.variance = T,verbose=F))
|
|
||||||
}
|
|
||||||
if (method=='JML') {
|
|
||||||
tam1 <- tam.jml(resp=resp,group=1+df[,treatment])
|
|
||||||
}
|
|
||||||
if (method!='MML' & method!='JML') {
|
|
||||||
stop('Invalid method. Please choose among MML or JML')
|
|
||||||
}
|
|
||||||
return(tam1)
|
|
||||||
}
|
|
||||||
replicate_pcm_analysis <- function(df=NULL,treatment='TT',irtmodel='PCM2',method='MML',sequence='replication',truebeta=0,eff.size=0,difsize=NA,nbdif=0) {
|
|
||||||
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') {
|
|
||||||
n <- max(df[,sequence])
|
|
||||||
print(n)
|
|
||||||
tam1 <- pbmclapply(seq(1,n),
|
|
||||||
function(x) quiet(pcm_analysis(df=df[df[,sequence]==x,],treatment=treatment,irtmodel=irtmodel))
|
|
||||||
)
|
|
||||||
}
|
|
||||||
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]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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 {
|
|
||||||
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=eff.size,
|
|
||||||
dif.size= difsize,
|
|
||||||
nb.dif= nbdif
|
|
||||||
)
|
|
||||||
returndat <- cbind(returndat2,returndat)
|
|
||||||
return(returndat)
|
|
||||||
}
|
|
||||||
#######################################
|
|
||||||
## SCENARIO ANALYSIS
|
|
||||||
#######################################
|
|
||||||
registerDoMC(4)
|
|
||||||
######### Scenario 1: J=4 / M=2 / H_0 TRUE
|
|
||||||
dat1 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N100/scenario_1A_100.csv')
|
|
||||||
dat2 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N100/scenario_1A_100.csv')
|
|
||||||
dat3 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N100/scenario_1A_100.csv')
|
|
||||||
replicate_pcm_analysis(dat1)
|
|
||||||
View(tam.mml)
|
|
||||||
library(TAM)
|
|
||||||
library(doMC)
|
|
||||||
library(parallel)
|
|
||||||
library(pbmcapply)
|
|
||||||
foo <- deparse(tam.mml)
|
|
||||||
tam.mml <- eval(parse(text=gsub("cat","#cat",foo)))
|
|
||||||
library(TAM)
|
|
||||||
library(doMC)
|
|
||||||
library(parallel)
|
|
||||||
library(pbmcapply)
|
|
||||||
oldcat <- cat
|
|
||||||
cat <- function( ..., file="", sep=" ", fill=F, labels=NULL, append=F ) {}
|
|
||||||
#######################################
|
|
||||||
## ANALYSIS FUNCTIONS
|
|
||||||
#######################################
|
|
||||||
pcm_analysis <- function(df=NULL,treatment='TT',irtmodel='PCM2',method='MML') {
|
|
||||||
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 <- quiet(tam.mml(resp=resp,Y=df[,treatment],irtmodel = irtmodel,est.variance = T,verbose=F))
|
|
||||||
}
|
|
||||||
if (method=='JML') {
|
|
||||||
tam1 <- tam.jml(resp=resp,group=1+df[,treatment])
|
|
||||||
}
|
|
||||||
if (method!='MML' & method!='JML') {
|
|
||||||
stop('Invalid method. Please choose among MML or JML')
|
|
||||||
}
|
|
||||||
return(tam1)
|
|
||||||
}
|
|
||||||
replicate_pcm_analysis <- function(df=NULL,treatment='TT',irtmodel='PCM2',method='MML',sequence='replication',truebeta=0,eff.size=0,difsize=NA,nbdif=0) {
|
|
||||||
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') {
|
|
||||||
n <- max(df[,sequence])
|
|
||||||
print(n)
|
|
||||||
tam1 <- pbmclapply(seq(1,n),
|
|
||||||
function(x) pcm_analysis(df=df[df[,sequence]==x,],treatment=treatment,irtmodel=irtmodel)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
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]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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 {
|
|
||||||
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=eff.size,
|
|
||||||
dif.size= difsize,
|
|
||||||
nb.dif= nbdif
|
|
||||||
)
|
|
||||||
returndat <- cbind(returndat2,returndat)
|
|
||||||
return(returndat)
|
|
||||||
}
|
|
||||||
#######################################
|
|
||||||
## SCENARIO ANALYSIS
|
|
||||||
#######################################
|
|
||||||
registerDoMC(4)
|
|
||||||
######### Scenario 1: J=4 / M=2 / H_0 TRUE
|
|
||||||
dat1 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N100/scenario_1A_100.csv')
|
|
||||||
dat2 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N100/scenario_1A_100.csv')
|
|
||||||
dat3 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N100/scenario_1A_100.csv')
|
|
||||||
replicate_pcm_analysis(dat1)
|
|
||||||
########################################
|
|
||||||
## LIBRARIES
|
|
||||||
########################################
|
|
||||||
library(TAM)
|
|
||||||
library(doMC)
|
|
||||||
library(parallel)
|
|
||||||
library(pbmcapply)
|
|
||||||
oldcat <- cat
|
|
||||||
cat <- function( ..., file="", sep=" ", fill=F, labels=NULL, append=F ) {}
|
|
||||||
#######################################
|
|
||||||
## ANALYSIS FUNCTIONS
|
|
||||||
#######################################
|
|
||||||
pcm_analysis <- function(df=NULL,treatment='TT',irtmodel='PCM2',method='MML') {
|
|
||||||
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 <- quiet(tam.mml(resp=resp,Y=df[,treatment],irtmodel = irtmodel,est.variance = T,verbose=F))
|
|
||||||
}
|
|
||||||
if (method=='JML') {
|
|
||||||
tam1 <- tam.jml(resp=resp,group=1+df[,treatment])
|
|
||||||
}
|
|
||||||
if (method!='MML' & method!='JML') {
|
|
||||||
stop('Invalid method. Please choose among MML or JML')
|
|
||||||
}
|
|
||||||
return(tam1)
|
|
||||||
}
|
|
||||||
replicate_pcm_analysis <- function(df=NULL,treatment='TT',irtmodel='PCM2',method='MML',sequence='replication',truebeta=0,eff.size=0,difsize=NA,nbdif=0) {
|
|
||||||
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') {
|
|
||||||
n <- max(df[,sequence])
|
|
||||||
print(n)
|
|
||||||
tam1 <- pbmclapply(seq(1,n),
|
|
||||||
function(x) pcm_analysis(df=df[df[,sequence]==x,],treatment=treatment,irtmodel=irtmodel)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
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]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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 {
|
|
||||||
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=eff.size,
|
|
||||||
dif.size= difsize,
|
|
||||||
nb.dif= nbdif
|
|
||||||
)
|
|
||||||
returndat <- cbind(returndat2,returndat)
|
|
||||||
return(returndat)
|
|
||||||
}
|
|
||||||
#######################################
|
|
||||||
## SCENARIO ANALYSIS
|
|
||||||
#######################################
|
|
||||||
registerDoMC(4)
|
|
||||||
######### Scenario 1: J=4 / M=2 / H_0 TRUE
|
|
||||||
dat1 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N100/scenario_1A_100.csv')
|
|
||||||
dat2 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N100/scenario_1A_100.csv')
|
|
||||||
dat3 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N100/scenario_1A_100.csv')
|
|
||||||
replicate_pcm_analysis(dat1)
|
|
||||||
tam1 <- tam(dat1)
|
|
||||||
tam1 <- tam(dat1[dat1$replication==1,])
|
|
||||||
library(TAM)
|
|
||||||
library(doMC)
|
|
||||||
library(parallel)
|
|
||||||
library(pbmcapply)
|
|
||||||
#######################################
|
|
||||||
## ANALYSIS FUNCTIONS
|
|
||||||
#######################################
|
|
||||||
pcm_analysis <- function(df=NULL,treatment='TT',irtmodel='PCM2',method='MML') {
|
|
||||||
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 <- quiet(tam.mml(resp=resp,Y=df[,treatment],irtmodel = irtmodel,est.variance = T,verbose=F))
|
|
||||||
}
|
|
||||||
if (method=='JML') {
|
|
||||||
tam1 <- tam.jml(resp=resp,group=1+df[,treatment])
|
|
||||||
}
|
|
||||||
if (method!='MML' & method!='JML') {
|
|
||||||
stop('Invalid method. Please choose among MML or JML')
|
|
||||||
}
|
|
||||||
return(tam1)
|
|
||||||
}
|
|
||||||
replicate_pcm_analysis <- function(df=NULL,treatment='TT',irtmodel='PCM2',method='MML',sequence='replication',truebeta=0,eff.size=0,difsize=NA,nbdif=0) {
|
|
||||||
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') {
|
|
||||||
n <- max(df[,sequence])
|
|
||||||
print(n)
|
|
||||||
tam1 <- pbmclapply(seq(1,n),
|
|
||||||
function(x) pcm_analysis(df=df[df[,sequence]==x,],treatment=treatment,irtmodel=irtmodel)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
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]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
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 {
|
|
||||||
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=eff.size,
|
|
||||||
dif.size= difsize,
|
|
||||||
nb.dif= nbdif
|
|
||||||
)
|
|
||||||
returndat <- cbind(returndat2,returndat)
|
|
||||||
return(returndat)
|
|
||||||
}
|
|
||||||
#######################################
|
|
||||||
## SCENARIO ANALYSIS
|
|
||||||
#######################################
|
|
||||||
registerDoMC(4)
|
|
||||||
######### Scenario 1: J=4 / M=2 / H_0 TRUE
|
|
||||||
dat1 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N100/scenario_1A_100.csv')
|
|
||||||
dat2 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N100/scenario_1A_100.csv')
|
|
||||||
dat3 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N100/scenario_1A_100.csv')
|
|
||||||
tam1 <- tam(dat1[dat1$replication==1,])
|
|
||||||
pcm_analysis(dat1[dat1$replication==1])
|
|
||||||
pcm_analysis(dat1[dat1$replication==1,])
|
pcm_analysis(dat1[dat1$replication==1,])
|
||||||
replicate_pcm_analysis(dat1)
|
pcm_analysis(dat1[dat1$replication==1,])$xsi
|
||||||
dat1 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N100/scenario_3A_100.csv')
|
pcm_analysis(dat1[dat1$replication==1,])$xsi$xsi
|
||||||
pcm_analysis(dat1[dat1$replication==1,])
|
pcm_analysis(dat1[dat1$replication==1,])
|
||||||
tam.se(pcm_analysis(dat1[dat1$replication==1,]))
|
u <- pcm_analysis(dat1[dat1$replication==1,])
|
||||||
1.413612*0.1225149
|
u$item_irt
|
||||||
|
u$item
|
||||||
|
-3.06+2.13
|
||||||
|
########################################
|
||||||
|
## LIBRARIES
|
||||||
|
########################################
|
||||||
|
library(TAM)
|
||||||
|
library(doMC)
|
||||||
|
library(parallel)
|
||||||
|
library(pbmcapply)
|
||||||
|
library(funprog)
|
||||||
|
lastChar <- function(str){
|
||||||
|
substr(str, nchar(str)-2, nchar(str))
|
||||||
|
}
|
||||||
|
#######################################
|
||||||
|
## ANALYSIS FUNCTIONS
|
||||||
|
#######################################
|
||||||
|
pcm_analysis <- function(df=NULL,treatment='TT',irtmodel='PCM2',method='MML') {
|
||||||
|
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 (method=='JML') {
|
||||||
|
tam1 <- tam.jml(resp=resp,group=1+df[,treatment])
|
||||||
|
}
|
||||||
|
if (method!='MML' & method!='JML') {
|
||||||
|
stop('Invalid method. Please choose among MML or JML')
|
||||||
|
}
|
||||||
|
return(tam1)
|
||||||
|
}
|
||||||
|
replicate_pcm_analysis_m4 <- function(df=NULL,treatment='TT',irtmodel='PCM2',method='MML',sequence='replication',truebeta=0,eff.size=0,difsize=NA,nbdif=0) {
|
||||||
|
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') {
|
||||||
|
n <- max(df[,sequence])
|
||||||
|
print(n)
|
||||||
|
tam1 <- pbmclapply(seq(1,n),
|
||||||
|
function(x) pcm_analysis(df=df[df[,sequence]==x,],treatment=treatment,irtmodel=irtmodel)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
listitems <- c(sapply(c('_1','_2','_3'),function(x) paste0(sapply(seq(1,nbitems),function(x) paste0('item',x)),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,'_1')] <- tam1[[s]]$item[k,'AXsi_.Cat1']
|
||||||
|
returndat[s,paste0('item',k,'_2')] <- tam1[[s]]$item[k,'AXsi_.Cat1']
|
||||||
|
returndat[s,paste0('item',k,'_3')] <- tam1[[s]]$item[k,'AXsi_.Cat1']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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 {
|
||||||
|
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=eff.size,
|
||||||
|
dif.size= difsize,
|
||||||
|
nb.dif= nbdif
|
||||||
|
)
|
||||||
|
returndat <- cbind(returndat2,returndat)
|
||||||
|
return(returndat)
|
||||||
|
}
|
||||||
|
replicate_pcm_analysis_m4(dat1[dat1$replication==1,])
|
||||||
|
########################################
|
||||||
|
## LIBRARIES
|
||||||
|
########################################
|
||||||
|
library(TAM)
|
||||||
|
library(doMC)
|
||||||
|
library(parallel)
|
||||||
|
library(pbmcapply)
|
||||||
|
library(funprog)
|
||||||
|
lastChar <- function(str){
|
||||||
|
substr(str, nchar(str)-2, nchar(str))
|
||||||
|
}
|
||||||
|
#######################################
|
||||||
|
## ANALYSIS FUNCTIONS
|
||||||
|
#######################################
|
||||||
|
pcm_analysis <- function(df=NULL,treatment='TT',irtmodel='PCM2',method='MML') {
|
||||||
|
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 (method=='JML') {
|
||||||
|
tam1 <- tam.jml(resp=resp,group=1+df[,treatment])
|
||||||
|
}
|
||||||
|
if (method!='MML' & method!='JML') {
|
||||||
|
stop('Invalid method. Please choose among MML or JML')
|
||||||
|
}
|
||||||
|
return(tam1)
|
||||||
|
}
|
||||||
|
replicate_pcm_analysis_m4 <- function(df=NULL,treatment='TT',irtmodel='PCM2',method='MML',sequence='replication',truebeta=0,eff.size=0,difsize=NA,nbdif=0) {
|
||||||
|
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') {
|
||||||
|
n <- max(df[,sequence])
|
||||||
|
print(n)
|
||||||
|
tam1 <- pbmclapply(seq(1,n),
|
||||||
|
function(x) pcm_analysis(df=df[df[,sequence]==x,],treatment=treatment,irtmodel=irtmodel)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
listitems <- c(sapply(c('_1','_2','_3'),function(x) paste0(sapply(seq(1,nbitems),function(x) paste0('item',x)),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,'_1')] <- tam1[[s]]$item[k,'AXsi_.Cat1']
|
||||||
|
returndat[s,paste0('item',k,'_2')] <- tam1[[s]]$item[k,'AXsi_.Cat2']
|
||||||
|
returndat[s,paste0('item',k,'_3')] <- tam1[[s]]$item[k,'AXsi_.Cat3']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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 {
|
||||||
|
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=eff.size,
|
||||||
|
dif.size= difsize,
|
||||||
|
nb.dif= nbdif
|
||||||
|
)
|
||||||
|
returndat <- cbind(returndat2,returndat)
|
||||||
|
return(returndat)
|
||||||
|
}
|
||||||
|
replicate_pcm_analysis_m4(dat1[dat1$replication==1,])
|
||||||
|
########################################
|
||||||
|
## LIBRARIES
|
||||||
|
########################################
|
||||||
|
library(TAM)
|
||||||
|
library(doMC)
|
||||||
|
library(parallel)
|
||||||
|
library(pbmcapply)
|
||||||
|
library(funprog)
|
||||||
|
lastChar <- function(str){
|
||||||
|
substr(str, nchar(str)-2, nchar(str))
|
||||||
|
}
|
||||||
|
#######################################
|
||||||
|
## ANALYSIS FUNCTIONS
|
||||||
|
#######################################
|
||||||
|
pcm_analysis <- function(df=NULL,treatment='TT',irtmodel='PCM2',method='MML') {
|
||||||
|
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 (method=='JML') {
|
||||||
|
tam1 <- tam.jml(resp=resp,group=1+df[,treatment])
|
||||||
|
}
|
||||||
|
if (method!='MML' & method!='JML') {
|
||||||
|
stop('Invalid method. Please choose among MML or JML')
|
||||||
|
}
|
||||||
|
return(tam1)
|
||||||
|
}
|
||||||
|
replicate_pcm_analysis_m4 <- function(df=NULL,treatment='TT',irtmodel='PCM2',method='MML',sequence='replication',truebeta=0,eff.size=0,difsize=NA,nbdif=0) {
|
||||||
|
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') {
|
||||||
|
n <- max(df[,sequence])
|
||||||
|
print(n)
|
||||||
|
tam1 <- pbmclapply(seq(1,n),
|
||||||
|
function(x) pcm_analysis(df=df[df[,sequence]==x,],treatment=treatment,irtmodel=irtmodel)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
listitems <- c(sapply(c('_1','_2','_3'),function(x) paste0(sapply(seq(1,nbitems),function(x) paste0('item',x)),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,'_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 {
|
||||||
|
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=eff.size,
|
||||||
|
dif.size= difsize,
|
||||||
|
nb.dif= nbdif
|
||||||
|
)
|
||||||
|
returndat <- cbind(returndat2,returndat)
|
||||||
|
return(returndat)
|
||||||
|
}
|
||||||
|
replicate_pcm_analysis_m4(dat1[dat1$replication==1,])
|
||||||
|
dat1 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N100/scenario_4A_100.csv')
|
||||||
|
replicate_pcm_analysis_m4(dat1[dat1$replication==1,])
|
||||||
|
dat1 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N100/scenario_1A_100.csv')
|
||||||
|
replicate_pcm_analysis_m2(dat1[dat1$replication==1,])
|
||||||
|
########################################
|
||||||
|
## LIBRARIES
|
||||||
|
########################################
|
||||||
|
library(TAM)
|
||||||
|
library(doMC)
|
||||||
|
library(parallel)
|
||||||
|
library(pbmcapply)
|
||||||
|
library(funprog)
|
||||||
|
lastChar <- function(str){
|
||||||
|
substr(str, nchar(str)-2, nchar(str))
|
||||||
|
}
|
||||||
|
#######################################
|
||||||
|
## ANALYSIS FUNCTIONS
|
||||||
|
#######################################
|
||||||
|
pcm_analysis <- function(df=NULL,treatment='TT',irtmodel='PCM2',method='MML') {
|
||||||
|
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 (method=='JML') {
|
||||||
|
tam1 <- tam.jml(resp=resp,group=1+df[,treatment])
|
||||||
|
}
|
||||||
|
if (method!='MML' & method!='JML') {
|
||||||
|
stop('Invalid method. Please choose among MML or JML')
|
||||||
|
}
|
||||||
|
return(tam1)
|
||||||
|
}
|
||||||
|
replicate_pcm_analysis_m4 <- function(df=NULL,treatment='TT',irtmodel='PCM2',method='MML',sequence='replication',truebeta=0,eff.size=0,difsize=NA,nbdif=0) {
|
||||||
|
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') {
|
||||||
|
n <- max(df[,sequence])
|
||||||
|
print(n)
|
||||||
|
tam1 <- pbmclapply(seq(1,n),
|
||||||
|
function(x) pcm_analysis(df=df[df[,sequence]==x,],treatment=treatment,irtmodel=irtmodel)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
listitems <- c(sapply(c('_1','_2','_3'),function(x) paste0(sapply(seq(1,nbitems),function(x) paste0('item',x)),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,'_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 {
|
||||||
|
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=eff.size,
|
||||||
|
dif.size= difsize,
|
||||||
|
nb.dif= nbdif
|
||||||
|
)
|
||||||
|
returndat <- cbind(returndat2,returndat)
|
||||||
|
return(returndat)
|
||||||
|
}
|
||||||
|
replicate_pcm_analysis_m2 <- function(df=NULL,treatment='TT',irtmodel='PCM2',method='MML',sequence='replication',truebeta=0,eff.size=0,difsize=NA,nbdif=0) {
|
||||||
|
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') {
|
||||||
|
n <- max(df[,sequence])
|
||||||
|
print(n)
|
||||||
|
tam1 <- pbmclapply(seq(1,n),
|
||||||
|
function(x) pcm_analysis(df=df[df[,sequence]==x,],treatment=treatment,irtmodel=irtmodel)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
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]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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 {
|
||||||
|
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=eff.size,
|
||||||
|
dif.size= difsize,
|
||||||
|
nb.dif= nbdif
|
||||||
|
)
|
||||||
|
returndat <- cbind(returndat2,returndat)
|
||||||
|
return(returndat)
|
||||||
|
}
|
||||||
|
dat1 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N100/scenario_2A_100.csv')
|
||||||
|
replicate_pcm_analysis_m4(dat1[dat1$replication==1,])
|
||||||
|
########################################
|
||||||
|
## LIBRARIES
|
||||||
|
########################################
|
||||||
|
library(TAM)
|
||||||
|
library(doMC)
|
||||||
|
library(parallel)
|
||||||
|
library(pbmcapply)
|
||||||
|
library(funprog)
|
||||||
|
lastChar <- function(str){
|
||||||
|
substr(str, nchar(str)-2, nchar(str))
|
||||||
|
}
|
||||||
|
#######################################
|
||||||
|
## ANALYSIS FUNCTIONS
|
||||||
|
#######################################
|
||||||
|
pcm_analysis <- function(df=NULL,treatment='TT',irtmodel='PCM2',method='MML') {
|
||||||
|
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 (method=='JML') {
|
||||||
|
tam1 <- tam.jml(resp=resp,group=1+df[,treatment])
|
||||||
|
}
|
||||||
|
if (method!='MML' & method!='JML') {
|
||||||
|
stop('Invalid method. Please choose among MML or JML')
|
||||||
|
}
|
||||||
|
return(tam1)
|
||||||
|
}
|
||||||
|
replicate_pcm_analysis_m4 <- function(df=NULL,treatment='TT',irtmodel='PCM2',method='MML',sequence='replication',truebeta=0,eff.size=0,difsize=NA,nbdif=0) {
|
||||||
|
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') {
|
||||||
|
n <- max(df[,sequence])
|
||||||
|
print(n)
|
||||||
|
tam1 <- pbmclapply(seq(1,n),
|
||||||
|
function(x) pcm_analysis(df=df[df[,sequence]==x,],treatment=treatment,irtmodel=irtmodel)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
listitems <- c(sapply(c('_1','_2','_3'),function(x) paste0(sapply(seq(1,nbitems),function(x) paste0('item',x)),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,'_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 {
|
||||||
|
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=eff.size,
|
||||||
|
dif.size= difsize,
|
||||||
|
nb.dif= nbdif
|
||||||
|
)
|
||||||
|
returndat <- cbind(returndat2,returndat)
|
||||||
|
return(returndat)
|
||||||
|
}
|
||||||
|
replicate_pcm_analysis_m2 <- function(df=NULL,treatment='TT',irtmodel='PCM2',method='MML',sequence='replication',truebeta=0,eff.size=0,difsize=NA,nbdif=0) {
|
||||||
|
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') {
|
||||||
|
n <- max(df[,sequence])
|
||||||
|
print(n)
|
||||||
|
tam1 <- pbmclapply(seq(1,n),
|
||||||
|
function(x) pcm_analysis(df=df[df[,sequence]==x,],treatment=treatment,irtmodel=irtmodel)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
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]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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 {
|
||||||
|
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=eff.size,
|
||||||
|
dif.size= difsize,
|
||||||
|
nb.dif= nbdif
|
||||||
|
)
|
||||||
|
returndat <- cbind(returndat2,returndat)
|
||||||
|
return(returndat)
|
||||||
|
}
|
||||||
|
#######################################
|
||||||
|
## SCENARIO ANALYSIS
|
||||||
|
#######################################
|
||||||
|
registerDoMC(4)
|
||||||
|
replicate_pcm_analysis_m4(dat1[dat1$replication==1,])
|
||||||
|
dat1 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N100/scenario_4A_100.csv')
|
||||||
|
replicate_pcm_analysis_m4(dat1[dat1$replication==1,])
|
||||||
|
@ -6,6 +6,11 @@ library(TAM)
|
|||||||
library(doMC)
|
library(doMC)
|
||||||
library(parallel)
|
library(parallel)
|
||||||
library(pbmcapply)
|
library(pbmcapply)
|
||||||
|
library(funprog)
|
||||||
|
|
||||||
|
lastChar <- function(str){
|
||||||
|
substr(str, nchar(str)-2, nchar(str))
|
||||||
|
}
|
||||||
|
|
||||||
#######################################
|
#######################################
|
||||||
## ANALYSIS FUNCTIONS
|
## ANALYSIS FUNCTIONS
|
||||||
@ -26,7 +31,7 @@ pcm_analysis <- function(df=NULL,treatment='TT',irtmodel='PCM2',method='MML') {
|
|||||||
return(tam1)
|
return(tam1)
|
||||||
}
|
}
|
||||||
|
|
||||||
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_m4 <- function(df=NULL,treatment='TT',irtmodel='PCM2',method='MML',sequence='replication',truebeta=0,eff.size=0,difsize=NA,nbdif=0) {
|
||||||
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))]
|
||||||
if (method=='MML') {
|
if (method=='MML') {
|
||||||
@ -36,20 +41,23 @@ replicate_pcm_analysis <- function(df=NULL,treatment='TT',irtmodel='PCM2',method
|
|||||||
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)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
listitems <- sapply(seq(1,nbitems),function(x) paste0('item',x))
|
listitems <- c(sapply(c('_1','_2','_3'),function(x) paste0(sapply(seq(1,nbitems),function(x) paste0('item',x)),x)))
|
||||||
returndat <- data.frame(matrix(nrow=max(df[,sequence]),ncol=length(listitems)))
|
returndat <- data.frame(matrix(nrow=max(df[,sequence]),ncol=length(listitems)))
|
||||||
colnames(returndat) <- listitems
|
colnames(returndat) <- listitems
|
||||||
for (s in seq(1,max(df[,sequence]))) {
|
for (s in seq(1,max(df[,sequence]))) {
|
||||||
for (k in seq(1,nbitems)) {
|
for (k in seq(1,nbitems)) {
|
||||||
returndat[s,paste0('item',k)] <- tam1[[s]]$xsi$xsi[k]
|
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$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$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$low.ci.beta <- returndat$beta-1.96*returndat$se.beta
|
||||||
returndat$high.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$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)
|
returndat$h0.rejected <- 1*(0<returndat$low.ci.beta | 0>returndat$high.ci.beta)
|
||||||
if (truebeta==0) {
|
if (truebeta==0) {
|
||||||
returndat$beta.same.sign.truebeta <- NA
|
returndat$beta.same.sign.truebeta <- NA
|
||||||
} else {
|
} else {
|
||||||
@ -61,7 +69,51 @@ replicate_pcm_analysis <- function(df=NULL,treatment='TT',irtmodel='PCM2',method
|
|||||||
eff.size=eff.size,
|
eff.size=eff.size,
|
||||||
dif.size= difsize,
|
dif.size= difsize,
|
||||||
nb.dif= nbdif
|
nb.dif= nbdif
|
||||||
)
|
)
|
||||||
|
returndat <- cbind(returndat2,returndat)
|
||||||
|
return(returndat)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
replicate_pcm_analysis_m2 <- function(df=NULL,treatment='TT',irtmodel='PCM2',method='MML',sequence='replication',truebeta=0,eff.size=0,difsize=NA,nbdif=0) {
|
||||||
|
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') {
|
||||||
|
n <- max(df[,sequence])
|
||||||
|
print(n)
|
||||||
|
tam1 <- pbmclapply(seq(1,n),
|
||||||
|
function(x) pcm_analysis(df=df[df[,sequence]==x,],treatment=treatment,irtmodel=irtmodel)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
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]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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 {
|
||||||
|
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=eff.size,
|
||||||
|
dif.size= difsize,
|
||||||
|
nb.dif= nbdif
|
||||||
|
)
|
||||||
returndat <- cbind(returndat2,returndat)
|
returndat <- cbind(returndat2,returndat)
|
||||||
return(returndat)
|
return(returndat)
|
||||||
}
|
}
|
||||||
@ -80,14 +132,26 @@ dat1 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Da
|
|||||||
dat2 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N200/scenario_1A_200.csv')
|
dat2 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N200/scenario_1A_200.csv')
|
||||||
dat3 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N300/scenario_1A_300.csv')
|
dat3 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N300/scenario_1A_300.csv')
|
||||||
|
|
||||||
res <- pbmclapply(c('dat1','dat2','dat3'),function(x) replicate_pcm_analysis(get(x)))
|
res <- pbmclapply(c('dat1','dat2','dat3'),function(x) replicate_pcm_analysis_m2(get(x)))
|
||||||
|
|
||||||
write.csv(res[[1]],'/home/corentin/Documents/These/Recherche/Simulation/Analysis/NoDIF/N100/scenario_1A_100.csv')
|
write.csv(res[[1]],'/home/corentin/Documents/These/Recherche/Simulation/Analysis/NoDIF/N100/scenario_1A_100.csv')
|
||||||
write.csv(res[[2]],'/home/corentin/Documents/These/Recherche/Simulation/Analysis/NoDIF/N200/scenario_1A_200.csv')
|
write.csv(res[[2]],'/home/corentin/Documents/These/Recherche/Simulation/Analysis/NoDIF/N200/scenario_1A_200.csv')
|
||||||
write.csv(res[[3]],'/home/corentin/Documents/These/Recherche/Simulation/Analysis/NoDIF/N300/scenario_1A_300.csv')
|
write.csv(res[[3]],'/home/corentin/Documents/These/Recherche/Simulation/Analysis/NoDIF/N300/scenario_1A_300.csv')
|
||||||
|
|
||||||
|
|
||||||
|
######### Scenario 2: J=4 / M=4
|
||||||
|
|
||||||
|
#### A: H0 TRUE
|
||||||
|
|
||||||
|
dat1 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N100/scenario_2A_100.csv')
|
||||||
|
dat2 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N200/scenario_2A_200.csv')
|
||||||
|
dat3 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N300/scenario_2A_300.csv')
|
||||||
|
|
||||||
|
res <- pbmclapply(c('dat1','dat2','dat3'),function(x) replicate_pcm_analysis_m4(get(x)))
|
||||||
|
|
||||||
|
write.csv(res[[1]],'/home/corentin/Documents/These/Recherche/Simulation/Analysis/NoDIF/N100/scenario_2A_100.csv')
|
||||||
|
write.csv(res[[2]],'/home/corentin/Documents/These/Recherche/Simulation/Analysis/NoDIF/N200/scenario_2A_200.csv')
|
||||||
|
write.csv(res[[3]],'/home/corentin/Documents/These/Recherche/Simulation/Analysis/NoDIF/N300/scenario_2A_300.csv')
|
||||||
|
|
||||||
|
|
||||||
######### Scenario 3: J=7 / M=2
|
######### Scenario 3: J=7 / M=2
|
||||||
@ -98,8 +162,24 @@ dat1 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Da
|
|||||||
dat2 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N200/scenario_3A_200.csv')
|
dat2 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N200/scenario_3A_200.csv')
|
||||||
dat3 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N300/scenario_3A_300.csv')
|
dat3 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N300/scenario_3A_300.csv')
|
||||||
|
|
||||||
res <- pbmclapply(c('dat1','dat2','dat3'),function(x) replicate_pcm_analysis(get(x)))
|
res <- pbmclapply(c('dat1','dat2','dat3'),function(x) replicate_pcm_analysis_m2(get(x)))
|
||||||
|
|
||||||
write.csv(res[[1]],'/home/corentin/Documents/These/Recherche/Simulation/Analysis/NoDIF/N100/scenario_3A_100.csv')
|
write.csv(res[[1]],'/home/corentin/Documents/These/Recherche/Simulation/Analysis/NoDIF/N100/scenario_3A_100.csv')
|
||||||
write.csv(res[[2]],'/home/corentin/Documents/These/Recherche/Simulation/Analysis/NoDIF/N200/scenario_3A_200.csv')
|
write.csv(res[[2]],'/home/corentin/Documents/These/Recherche/Simulation/Analysis/NoDIF/N200/scenario_3A_200.csv')
|
||||||
write.csv(res[[3]],'/home/corentin/Documents/These/Recherche/Simulation/Analysis/NoDIF/N300/scenario_3A_300.csv')
|
write.csv(res[[3]],'/home/corentin/Documents/These/Recherche/Simulation/Analysis/NoDIF/N300/scenario_3A_300.csv')
|
||||||
|
|
||||||
|
|
||||||
|
######### Scenario 4: J=7 / M=4
|
||||||
|
|
||||||
|
#### A: H0 TRUE
|
||||||
|
|
||||||
|
dat1 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N100/scenario_4A_100.csv')
|
||||||
|
dat2 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N200/scenario_4A_200.csv')
|
||||||
|
dat3 <- read.csv(file = '/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N300/scenario_4A_300.csv')
|
||||||
|
|
||||||
|
res <- pbmclapply(c('dat1','dat2','dat3'),function(x) replicate_pcm_analysis_m4(get(x)))
|
||||||
|
|
||||||
|
write.csv(res[[1]],'/home/corentin/Documents/These/Recherche/Simulation/Analysis/NoDIF/N100/scenario_4A_100.csv')
|
||||||
|
write.csv(res[[2]],'/home/corentin/Documents/These/Recherche/Simulation/Analysis/NoDIF/N200/scenario_4A_200.csv')
|
||||||
|
write.csv(res[[3]],'/home/corentin/Documents/These/Recherche/Simulation/Analysis/NoDIF/N300/scenario_4A_300.csv')
|
||||||
|
|
||||||
|
@ -29,10 +29,11 @@ local Nn = 100
|
|||||||
* Scenario 1A : H_0 is TRUE
|
* Scenario 1A : H_0 is TRUE
|
||||||
|
|
||||||
clear
|
clear
|
||||||
import delim "`path_data'/scenario_3A_100.csv", encoding(ISO-8859-2) case(preserve) clear
|
import delim "`path_data'/scenario_1A_100.csv", encoding(ISO-8859-2) case(preserve) clear
|
||||||
rename TT tt
|
rename TT tt
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
keep if replication==1
|
keep if replication==1
|
||||||
di `k'
|
di `k'
|
||||||
gsem (1.item1<-THETA@1)///
|
gsem (1.item1<-THETA@1)///
|
||||||
@ -43,3 +44,6 @@ gsem (1.item1<-THETA@1)///
|
|||||||
(1.item6<-THETA@1)///
|
(1.item6<-THETA@1)///
|
||||||
(1.item7<-THETA@1)///
|
(1.item7<-THETA@1)///
|
||||||
(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent
|
(THETA<-tt), mlogit tol(0.01) iterate(500) latent(THETA) nocapslatent
|
||||||
|
|
||||||
|
|
||||||
|
pcm item1 item2 item3 item4, categorical(tt)
|
||||||
|
Reference in New Issue
Block a user