Created ROSALI screening version

This commit is contained in:
2025-02-13 15:24:10 +01:00
parent 7712f8396f
commit f04322a9db
8 changed files with 3751 additions and 49 deletions

View File

@ -147,19 +147,35 @@ replicate_pcm_analysis<- function(df=NULL,treatment='TT',irtmodel='PCM2',method=
#### Create data.frame
#results <- c(sapply(c(2,4),function(x) paste0(x,c('A','B','C'))),sapply(c(6,8),function(x) paste0(x,c('A','B','C','D','E'))))
#results2 <- c(sapply(seq(10,20,2),function(x) paste0(x,c('A','B','C','D','E'))))
#results <- c(sapply(c(50,100,300),function(x) paste0(results,'_',x)))
#results2 <- c(sapply(c(50,100,300),function(x) paste0(results2,'_',x)))
#results <- c(results,results2)
results <- c(sapply(c(2,4),function(x) paste0(x,c('A','B','C'))),sapply(c(6,8),function(x) paste0(x,c('A','B','C','D','E'))))
results2 <- c(sapply(seq(10,20,2),function(x) paste0(x,c('A','B','C','D','E'))))
results <- c(sapply(c(50,100,300),function(x) paste0(results,'_',x)))
results <- c(sapply(c("050",100,300),function(x) paste0(results,'_',x)))
results2 <- c(sapply(c(50,100,300),function(x) paste0(results2,'_',x)))
results2 <- c(sapply(c("050",100,300),function(x) paste0(results2,'_',x)))
results <- sort(results)
results2 <- sort(results2)
results <- c(results,results2)
results <- c(sapply(1:16,function(x) c(results[x],results[x+16],results[x+32])),
sapply(1:30,function(x) c(results[x+48],results[x+30+48],results[x+60+48]))
)
results <- gsub('050',"50",results)
# results <- c(sapply(1:16,function(x) c(results[x],results[x+16],results[x+32])),
# sapply(1:30,function(x) c(results[x+48],results[x+30+48],results[x+60+48]))
# )
#### Compiler function
compile_simulation <- function(scenario) {
@ -302,21 +318,21 @@ res.dat[is.nan(res.dat)] <- NA
#### Create data.frame
results <- c(sapply(c(2,4),function(x) paste0(x,c('A','B','C'))),sapply(c(6,8),function(x) paste0(x,c('A','B','C','D','E'))))
results <- c(sapply(c(6,8),function(x) paste0(x,c('A','B','C','D','E'))))
results2 <- c(sapply(seq(10,20,2),function(x) paste0(x,c('A','B','C','D','E'))))
results <- c(sapply(c(50,100,300),function(x) paste0(results,'_',x)))
results <- c(sapply(c("050",100,300),function(x) paste0(results,'_',x)))
results2 <- c(sapply(c(50,100,300),function(x) paste0(results2,'_',x)))
results2 <- c(sapply(c("050",100,300),function(x) paste0(results2,'_',x)))
results <- sort(results)
results2 <- sort(results2)
results <- c(results,results2)
results <- c(sapply(1:16,function(x) c(results[x],results[x+16],results[x+32])),
sapply(1:30,function(x) c(results[x+48],results[x+30+48],results[x+60+48]))
)
results <- results[19:length(results)]
results <- gsub('050',"50",results)
#### Compiler function
@ -425,19 +441,23 @@ res.dat.dif$bias <- res.dat.dif$eff.size-res.dat.dif$m.beta
#### Create data.frame
results <- c(sapply(c(2,4),function(x) paste0(x,c('A','B','C'))),sapply(c(6,8),function(x) paste0(x,c('A','B','C','D','E'))))
results2 <- c(sapply(seq(10,20,2),function(x) paste0(x,c('A','B','C','D','E'))))
results <- c(sapply(c(50,100,300),function(x) paste0(results,'_',x)))
results <- c(sapply(c("050",100,300),function(x) paste0(results,'_',x)))
results2 <- c(sapply(c(50,100,300),function(x) paste0(results2,'_',x)))
results2 <- c(sapply(c("050",100,300),function(x) paste0(results2,'_',x)))
results <- sort(results)
results2 <- sort(results2)
results <- c(results,results2)
results <- c(sapply(1:16,function(x) c(results[x],results[x+16],results[x+32])),
sapply(1:30,function(x) c(results[x+48],results[x+30+48],results[x+60+48]))
)
results <- gsub('050',"50",results)
#### Compiler function
@ -719,19 +739,36 @@ res.dat.dif.rosali$bias <- res.dat.dif.rosali$eff.size-res.dat.dif.rosali$m.beta
#### Create data.frame
#results <- c(sapply(c(2,4),function(x) paste0(x,c('A','B','C'))),sapply(c(6,8),function(x) paste0(x,c('A','B','C','D','E'))))
#results2 <- c(sapply(seq(10,20,2),function(x) paste0(x,c('A','B','C','D','E'))))
#results <- c(sapply(c(50,100,300),function(x) paste0(results,'_',x)))
#results2 <- c(sapply(c(50,100,300),function(x) paste0(results2,'_',x)))
#results <- c(results,results2)
#results <- c(sapply(1:16,function(x) c(results[x],results[x+16],results[x+32])),
# sapply(1:30,function(x) c(results[x+48],results[x+30+48],results[x+60+48]))
#)
results <- c(sapply(c(2,4),function(x) paste0(x,c('A','B','C'))),sapply(c(6,8),function(x) paste0(x,c('A','B','C','D','E'))))
results2 <- c(sapply(seq(10,20,2),function(x) paste0(x,c('A','B','C','D','E'))))
results <- c(sapply(c(50,100,300),function(x) paste0(results,'_',x)))
results <- c(sapply(c("050",100,300),function(x) paste0(results,'_',x)))
results2 <- c(sapply(c(50,100,300),function(x) paste0(results2,'_',x)))
results2 <- c(sapply(c("050",100,300),function(x) paste0(results2,'_',x)))
results <- sort(results)
results2 <- sort(results2)
results <- c(results,results2)
results <- c(sapply(1:16,function(x) c(results[x],results[x+16],results[x+32])),
sapply(1:30,function(x) c(results[x+48],results[x+30+48],results[x+60+48]))
)
results <- gsub('050',"50",results)
#### Compiler function
@ -985,6 +1022,7 @@ res.dat.dif.resali[substr(res.dat.dif.resali$scenario,1,2)%in%seq(10,16,2),'nb.d
res.dat.dif.resali[substr(res.dat.dif.resali$scenario,1,2)%in%seq(18,20,2),'nb.dif'] <- 3
res.dat.dif.resali[res.dat.dif.resali$N==50,"dif.size"] <- res.dat.dif.resali[which(res.dat.dif.resali$N==50)+1,"dif.size"]
res.dat.dif.resali[res.dat.dif.resali$scenario.type=="B",]$eff.size <- 0.2
res.dat.dif.resali[res.dat.dif.resali$scenario=="20E" & res.dat.dif.resali$N==50,]$dif.size <- -0.5
res.dat.dif.resali[res.dat.dif.resali$scenario.type=="C" & res.dat.dif.resali$dif.size==0,]$eff.size <- 0.4
res.dat.dif.resali[res.dat.dif.resali$scenario.type=="C" & res.dat.dif.resali$dif.size!=0,]$eff.size <- 0.2
res.dat.dif.resali[res.dat.dif.resali$scenario.type=="D" & res.dat.dif.resali$dif.size!=0,]$eff.size <- 0.4
@ -1203,7 +1241,8 @@ res.dat.article.rosali.2$bias <- -1*res.dat.article.rosali.2$bias
res.dat.article.rosali.2.nodif <- res.dat.article.rosali.2[res.dat.article.rosali.2$nb.dif==0,]
# STRATEGY 3 - RESIDIF
res.dat.dif.resali[1,"N"] <- 50
res.dat.dif.resali$dif.size <- res.dat.dif.rosali$dif.size
res.dat.article.residif <- res.dat.dif.resali[,c("N","J","eff.size","nb.dif","dif.size",
"m.beta","bias","true.value.in.ci.p","h0.rejected.p",
"theoretical.power")]
@ -1219,7 +1258,7 @@ res.dat.article.residif[res.dat.article.residif$nb.dif==0,"true.gamma"] <- NA
res.dat.article.residif[is.na(res.dat.article.residif)] <- " "
res.dat.article.residif$bias <- -1*res.dat.article.residif$bias
res.dat.article.residif <- reshape(res.dat.article.residif,
direction = "wide", idvar = c("J","true.beta","nb.dif",'true.gamma'),timevar = "N" )
direction = "wide", idvar = c("J","true.beta","nb.dif",'true.gamma'),timevar = "N")
res.dat.article.residif.dif <- res.dat.article.residif[res.dat.article.residif$nb.dif>0,]
write.csv(res.dat.article.residif.dif,"/home/corentin/Documents/These/Valorisation/Articles/Simulations 1/Tables/res_RESIDIF_DIF.csv")
res.dat.article.residif.nodif <- res.dat.article.residif[res.dat.article.residif$nb.dif==0,]
@ -1240,6 +1279,7 @@ res.dat.article.residif.2[res.dat.article.residif.2$nb.dif==0,"true.gamma"] <- N
res.dat.article.residif.2[is.na(res.dat.article.residif.2)] <- " "
res.dat.article.residif.2$bias <- -1*res.dat.article.residif.2$bias
res.dat.article.residif.2.nodif <- res.dat.article.residif.2[res.dat.article.residif.2$nb.dif==0,]
res.dat.article.residif.dif
# STRATEGY 4 - PERFECT-DIF

View File

@ -27,10 +27,9 @@ resali <- function(df=NULL,items=NULL,group=NULL,verbose=T) {
for (i in items) {
dat[,paste0('res_',i)] <- IRT.residuals(pcm_initial)$stand_residuals[,i]
res.anova[i] <- summary(aov(dat[,paste0('res_',i)]~TT*score_q5,data=dat))
pval[i] <- res.anova[[i]][1,"Pr(>F)"]
fval[i] <- res.anova[[i]][1,'F value']
pval[c(i,i+nbitems)] <- c(res.anova[[i]][1,"Pr(>F)"],res.anova[[i]][3,"Pr(>F)"])
fval[c(i,i+nbitems)] <- c(res.anova[[i]][1,'F value'],res.anova[[i]][3,"F value"])
}
print(res.anova)
if (verbose) {
cat('DONE\n')
cat('-----------------------------------------------------------\n')
@ -44,9 +43,10 @@ resali <- function(df=NULL,items=NULL,group=NULL,verbose=T) {
cat(paste('COMPUTING STEP',k,'\n'))
cat('-----------------------------------------------------------\n')
}
res.item <- gsub("[a-z]", "",colnames(resp)[which.max(fval)])
numitem <- ifelse(which.max(fval)%%(length(fval)/2)!=0,which.max(fval)%%(length(fval)/2),length(fval)/2)
res.item <- gsub("[a-z]", "",colnames(resp)[numitem])
res.items <- c(res.items,res.item)
res.uni <- res.anova[[which.max(fval)]][3,"Pr(>F)"]>0.05
res.uni <- res.anova[[numitem]][3,"Pr(>F)"]>0.05
res.uniform <- c(res.uniform,res.uni)
items_n <- c(items_n[items_n!=paste0('item',res.item)],paste0("item",res.item,c("noTT","TT")))
dat[dat$TT==1,paste0("item",res.item,'TT')] <- dat[dat$TT==1,paste0('item',res.item)]
@ -54,24 +54,19 @@ resali <- function(df=NULL,items=NULL,group=NULL,verbose=T) {
resp <- dat[,items_n]
grp <- dat[,group]
pcm_while <- TAM::tam.mml(resp=resp,Y=grp,irtmodel = "PCM",est.variance = T,verbose=F)
nbitems <- length(items_n)
nbitems <- length(items_n)-2*length(res.items)
res.anova <- rep(NA,nbitems)
pval <- rep(NA,nbitems)
fval <- rep(NA,nbitems)
pval <- rep(NA,2*nbitems)
fval <- rep(NA,2*nbitems)
for (i in 1:nbitems) {
dat[,paste0('res_',i)] <- IRT.residuals(pcm_while)$stand_residuals[,i]
res.anova[i] <- summary(aov(dat[,paste0('res_',i)]~TT*score_q5,data=dat))
pval[i] <- res.anova[[i]][1,"Pr(>F)"]
pval[i+nbitems] <- res.anova[[i]][3,"Pr(>F)"]
fval[i] <- res.anova[[i]][1,'F value']
fval[i+nbitems] <- res.anova[[i]][3,"F value"]
}
zz <- 0
for (name_i in items_n) {
zz <- zz+1
if (grepl("TT",name_i)) {
pval[zz] <- 1
fval[zz] <- 0
}
}
if (verbose) {
cat('DONE\n')
cat('-----------------------------------------------------------\n')

View File

@ -0,0 +1,167 @@
library(TAM)
resali <- function(df=NULL,items=NULL,group=NULL,verbose=T) {
if (verbose) {
cat('-----------------------------------------------------------\n')
cat('COMPUTING INITIAL PCM\n')
cat('-----------------------------------------------------------\n')
}
nbitems <- length(items)
nbitems_o <- nbitems
items_n <- paste0('item',items)
resp <- df[,items_n]
grp <- df[,group]
pcm_initial <- TAM::tam.mml(resp=resp,Y=grp,irtmodel = "PCM",est.variance = T,verbose=F)
dat <- df
dat$score <- rowSums(dat[,items_n])
nqt <- ifelse(length(unique(quantile(dat$score,seq(0,1,0.2))))==6,5,length(unique(quantile(dat$score,seq(0,1,0.2))))-1)
while (length(unique(quantile(dat$score,seq(0,1,1/nqt))))!=nqt+1) {
nqt <- nqt-1
}
# ITEM POLYTOMIQUE
if (max(resp)>1) {
dat$score_q5 <- cut(dat$score,unique(quantile(dat$score,seq(0,1,1/nqt))),labels=1:nqt,include.lowest=T)
res.anova <- rep(NA,nbitems)
pval <- rep(NA,nbitems)
fval <- rep(NA,nbitems)
for (i in items) {
dat[,paste0('res_',i)] <- IRT.residuals(pcm_initial)$stand_residuals[,i]
res.anova[i] <- summary(aov(dat[,paste0('res_',i)]~TT*score_q5,data=dat))
pval[i] <- res.anova[[i]][1,"Pr(>F)"]
fval[i] <- res.anova[[i]][1,'F value']
}
print(res.anova)
if (verbose) {
cat('DONE\n')
cat('-----------------------------------------------------------\n')
}
res.items <- c()
res.uniform <- c()
k <- 1
while(any(pval<0.05/(nbitems_o*3))) {
k <- k+1
if (verbose) {
cat(paste('COMPUTING STEP',k,'\n'))
cat('-----------------------------------------------------------\n')
}
res.item <- gsub("[a-z]", "",colnames(resp)[which.max(fval)])
res.items <- c(res.items,res.item)
res.uni <- res.anova[[which.max(fval)]][3,"Pr(>F)"]>0.05
res.uniform <- c(res.uniform,res.uni)
items_n <- c(items_n[items_n!=paste0('item',res.item)],paste0("item",res.item,c("noTT","TT")))
dat[dat$TT==1,paste0("item",res.item,'TT')] <- dat[dat$TT==1,paste0('item',res.item)]
dat[dat$TT==0,paste0("item",res.item,'noTT')] <- dat[dat$TT==0,paste0('item',res.item)]
resp <- dat[,items_n]
grp <- dat[,group]
pcm_while <- TAM::tam.mml(resp=resp,Y=grp,irtmodel = "PCM",est.variance = T,verbose=F)
nbitems <- length(items_n)
res.anova <- rep(NA,nbitems)
pval <- rep(NA,nbitems)
fval <- rep(NA,nbitems)
for (i in 1:nbitems) {
dat[,paste0('res_',i)] <- IRT.residuals(pcm_while)$stand_residuals[,i]
res.anova[i] <- summary(aov(dat[,paste0('res_',i)]~TT*score_q5,data=dat))
pval[i] <- res.anova[[i]][1,"Pr(>F)"]
fval[i] <- res.anova[[i]][1,'F value']
}
zz <- 0
for (name_i in items_n) {
zz <- zz+1
if (grepl("TT",name_i)) {
pval[zz] <- 1
fval[zz] <- 0
}
}
if (verbose) {
cat('DONE\n')
cat('-----------------------------------------------------------\n')
}
}
if (verbose) {
cat("DETECTED DIF ITEMS\n")
cat('-----------------------------------------------------------\n')
}
if (length(res.items>0)) {
results <- data.frame(dif.items=res.items,
uniform=1*res.uniform)
return(results)
}
else {
if (verbose) {
cat("No DIF was detected\n")
}
return(NULL)
}
# ITEM DICHOTOMIQUE
} else {
res.anova <- rep(NA,nbitems)
pval <- rep(NA,nbitems)
fval <- rep(NA,nbitems)
for (i in items) {
dat[,paste0('res_',i)] <- IRT.residuals(pcm_initial)$stand_residuals[,i]
res.anova[i] <- summary(aov(dat[,paste0('res_',i)]~TT,data=dat))
pval[i] <- res.anova[[i]][1,"Pr(>F)"]
fval[i] <- res.anova[[i]][1,'F value']
}
if (verbose) {
cat('DONE\n')
cat('-----------------------------------------------------------\n')
}
res.items <- c()
k <- 1
while(any(pval<0.05/(nbitems_o))) {
k <- k+1
if (verbose) {
cat(paste('COMPUTING STEP',k,'\n'))
cat('-----------------------------------------------------------\n')
}
res.item <- gsub("[a-z]", "",colnames(resp)[which.max(fval)])
res.items <- c(res.items,res.item)
items_n <- c(items_n[items_n!=paste0('item',res.item)],paste0("item",res.item,c("noTT","TT")))
dat[dat$TT==1,paste0("item",res.item,'TT')] <- dat[dat$TT==1,paste0('item',res.item)]
dat[dat$TT==0,paste0("item",res.item,'noTT')] <- dat[dat$TT==0,paste0('item',res.item)]
resp <- dat[,items_n]
grp <- dat[,group]
pcm_while <- TAM::tam.mml(resp=resp,Y=grp,irtmodel = "PCM",est.variance = T,verbose=F)
nbitems <- length(items_n)
res.anova <- rep(NA,nbitems)
pval <- rep(NA,nbitems)
fval <- rep(NA,nbitems)
for (i in 1:nbitems) {
dat[,paste0('res_',i)] <- IRT.residuals(pcm_while)$stand_residuals[,i]
res.anova[i] <- summary(aov(dat[,paste0('res_',i)]~TT,data=dat))
pval[i] <- res.anova[[i]][1,"Pr(>F)"]
fval[i] <- res.anova[[i]][1,'F value']
}
zz <- 0
for (name_i in items_n) {
zz <- zz+1
if (grepl("TT",name_i)) {
pval[zz] <- 1
fval[zz] <- 0
}
}
if (verbose) {
cat('DONE\n')
cat('-----------------------------------------------------------\n')
}
}
if (verbose) {
cat("DETECTED DIF ITEMS\n")
cat('-----------------------------------------------------------\n')
}
if (length(res.items>0)) {
results <- data.frame(dif.items=res.items,
uniform=rep(1,length(res.items)))
return(results)
}
else {
if (verbose) {
cat("No DIF was detected\n")
}
return(NULL)
}
}
}

View File

@ -113,15 +113,18 @@ generate_resali <- function(scenario=NULL,grp=NULL) {
return(df_res)
}
#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(50,100,200,300),function(x) paste0(results,'_',x)))
#results2 <- c(sapply(c(50,100,200,300),function(x) paste0(results2,'_',x)))
results <- c(sapply(c(2:4),function(x) paste0(x,c('A','B','C'))),sapply(c(6,8),function(x) paste0(x,c('A','B','C','D','E'))))
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(seq(10,20,2),function(x) paste0(x,c('A','B','C','D','E'))))
results2 <- c(sapply(10:20,function(x) paste0(x,c('A','B','C','D','E','F','G'))))
results <- c(sapply(c(50,100,300),function(x) paste0(results,'_',x)))
results <- c(sapply(c(50,100,200,300),function(x) paste0(results,'_',x)))
results2 <- c(sapply(c(50,100,200,300),function(x) paste0(results2,'_',x)))
results2 <- c(sapply(c(50,100,300),function(x) paste0(results2,'_',x)))
results <- sort(results)
@ -144,13 +147,27 @@ for (r in results) {
## Liste des scenarios
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(50,100,200,300),function(x) paste0(results,'_',x)))
#results <- c(sapply(c(50,100,200,300),function(x) paste0(results,'_',x)))
results2 <- c(sapply(c(50,100,200,300),function(x) paste0(results2,'_',x)))
#results2 <- c(sapply(c(50,100,200,300),function(x) paste0(results2,'_',x)))
#results <- sort(results)
#results2 <- sort(results2)
#results <- c(results,results2)
results <- c(sapply(c(2:4),function(x) paste0(x,c('A','B','C'))),sapply(c(6,8),function(x) paste0(x,c('A','B','C','D','E'))))
results2 <- c(sapply(seq(10,20,2),function(x) paste0(x,c('A','B','C','D','E'))))
results <- c(sapply(c(50,100,300),function(x) paste0(results,'_',x)))
results2 <- c(sapply(c(50,100,300),function(x) paste0(results2,'_',x)))
results <- sort(results)