diff --git a/RProject/Scripts/aggregation.R b/RProject/Scripts/aggregation.R index b059396..41b1c20 100644 --- a/RProject/Scripts/aggregation.R +++ b/RProject/Scripts/aggregation.R @@ -531,6 +531,8 @@ compile_simulation2_rosali <- function(scenario) { flexible.detect <- prop.perfect moreflexible.detect <- sapply(1:1000,function(x) ifelse(sum(!is.na(s[x,paste0("dif_detect_",1:4)]))!=0,s[x,"real_dif_1"]%in%c(s[x,paste0("dif_detect_",1:4)]),0) ) moreflexible.detect <- mean(moreflexible.detect) + percent.detect <- sapply(1:1000,function(x) sum(s[x,paste0("dif_detect_",1:4)]%in%c(s[x,c("real_dif_1")]))/1) + percent.detect <- mean(percent.detect) } if (nb.dif.true==2 & unique(b$J)==4 & unique(b$M)==2) { perfect.detection <- sapply(1:1000,function(x) ifelse(sum(!is.na(s[x,paste0("dif_detect_",1:4)]))==2,s[x,paste0('dif_detect_',which(sapply(paste0("dif_detect_",1:4),function(y) !is.na(s[x,y])))[1])]%in%c(s[x,c("real_dif_1","real_dif_2")]) & s[x,paste0('dif_detect_',which(sapply(paste0("dif_detect_",1:4),function(y) !is.na(s[x,y])))[2])]%in%c(s[x,c("real_dif_1","real_dif_2")]) @@ -540,6 +542,9 @@ compile_simulation2_rosali <- function(scenario) { moreflexible.detect <- sapply(1:1000,function(x) ifelse(sum(!is.na(s[x,paste0("dif_detect_",1:4)]))!=0,s[x,"real_dif_1"]%in%c(s[x,paste0("dif_detect_",1:4)]) & s[x,"real_dif_2"]%in%c(s[x,paste0("dif_detect_",1:4)]),0) ) moreflexible.detect <- mean(moreflexible.detect) + percent.detect <- sapply(1:1000,function(x) sum(s[x,paste0("dif_detect_",1:4)]%in%c(s[x,c("real_dif_1","real_dif_2")]))/2) + percent.detect <- mean(percent.detect) + } if (nb.dif.true==2 & unique(b$J)==7 & unique(b$M)==2) { perfect.detection <- sapply(1:1000,function(x) ifelse(sum(!is.na(s[x,paste0("dif_detect_",1:7)]))==2,s[x,paste0('dif_detect_',which(sapply(paste0("dif_detect_",1:7),function(y) !is.na(s[x,y])))[1])]%in%c(s[x,c("real_dif_1","real_dif_2")]) & s[x,paste0('dif_detect_',which(sapply(paste0("dif_detect_",1:7),function(y) !is.na(s[x,y])))[2])]%in%c(s[x,c("real_dif_1","real_dif_2")]) @@ -549,6 +554,8 @@ compile_simulation2_rosali <- function(scenario) { moreflexible.detect <- sapply(1:1000,function(x) ifelse(sum(!is.na(s[x,paste0("dif_detect_",1:7)]))!=0,s[x,"real_dif_1"]%in%c(s[x,paste0("dif_detect_",1:7)]) & s[x,"real_dif_2"]%in%c(s[x,paste0("dif_detect_",1:7)]),0) ) moreflexible.detect <- mean(moreflexible.detect) + percent.detect <- sapply(1:1000,function(x) sum(s[x,paste0("dif_detect_",1:7)]%in%c(s[x,c("real_dif_1","real_dif_2")]))/2) + percent.detect <- mean(percent.detect) } if (nb.dif.true==3 & unique(b$J)==7 & unique(b$M)==2) { perfect.detection <- sapply(1:1000,function(x) ifelse(sum(!is.na(s[x,paste0("dif_detect_",1:7)]))==3,s[x,paste0('dif_detect_',which(sapply(paste0("dif_detect_",1:7),function(y) !is.na(s[x,y])))[1])]%in%c(s[x,c("real_dif_1","real_dif_2","real_dif_3")]) & s[x,paste0('dif_detect_',which(sapply(paste0("dif_detect_",1:7),function(y) !is.na(s[x,y])))[2])]%in%c(s[x,c("real_dif_1","real_dif_2","real_dif_3")]) & s[x,paste0('dif_detect_',which(sapply(paste0("dif_detect_",1:7),function(y) !is.na(s[x,y])))[3])]%in%c(s[x,c("real_dif_1","real_dif_2","real_dif_3")]) @@ -558,6 +565,8 @@ compile_simulation2_rosali <- function(scenario) { moreflexible.detect <- sapply(1:1000,function(x) ifelse(sum(!is.na(s[x,paste0("dif_detect_",1:7)]))!=0,s[x,"real_dif_1"]%in%c(s[x,paste0("dif_detect_",1:7)]) & s[x,"real_dif_2"]%in%c(s[x,paste0("dif_detect_",1:7)]) & s[x,"real_dif_3"]%in%c(s[x,paste0("dif_detect_",1:7)]),0) ) moreflexible.detect <- mean(moreflexible.detect) + percent.detect <- sapply(1:1000,function(x) sum(s[x,paste0("dif_detect_",1:7)]%in%c(s[x,c("real_dif_1","real_dif_2","real_dif_3")]))/3) + percent.detect <- mean(percent.detect) } z <- data.frame(m.beta=mean(s$beta), se.empirical.beta=sd(s$beta), @@ -571,7 +580,8 @@ compile_simulation2_rosali <- function(scenario) { dif.detected=dif.d, prop.perfect=prop.perfect, flexible.detect=flexible.detect, - moreflexible.detect=moreflexible.detect + moreflexible.detect=moreflexible.detect, + percent.detect=ifelse(name%%2==0,NA,percent.detect) ) d <- cbind(b,a,z) d$prop. diff --git a/RProject/Scripts/functions/resali.R b/RProject/Scripts/functions/resali.R index 00f77cc..36ba0f3 100644 --- a/RProject/Scripts/functions/resali.R +++ b/RProject/Scripts/functions/resali.R @@ -18,6 +18,8 @@ resali <- function(df=NULL,items=NULL,group=NULL,verbose=T) { 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) @@ -89,67 +91,15 @@ resali <- function(df=NULL,items=NULL,group=NULL,verbose=T) { } return(NULL) } -} - - - - - -resali_BF2 <- 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) - 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)] <- rowMeans(predict(pcm_initial)$stand.resid[,,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'] - } - if (verbose) { - cat('DONE\n') - cat('-----------------------------------------------------------\n') - } - res.items <- c() - res.uniform <- c() - k <- 1 - while(any(pval<0.05/(nbitems_o-k+1))) { - 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[,paste0("item",res.item,'TT')] <- dat[dat$TT==1,paste0('item',res.item)] - dat[,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) + # ITEM DICHOTOMIQUE + } else { + res.anova <- rep(NA,nbitems) pval <- rep(NA,nbitems) fval <- rep(NA,nbitems) - for (i in 1:nbitems) { - dat[,paste0('res_',i)] <- rowMeans(predict(pcm_while)$stand.resid[,,i]) - res.anova[i] <- summary(aov(dat[,paste0('res_',i)]~TT*score_q5,data=dat)) + 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'] } @@ -157,72 +107,9 @@ resali_BF2 <- function(df=NULL,items=NULL,group=NULL,verbose=T) { 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) - } -} - - - - - - - - -resali_LRT <- 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] - items_n_alt <- paste0(items_n,c("_TT","_noTT")) - for (i in items_n) { - df[df$TT==0,paste0(i,"_noTT")] <- df[df$TT==0,i] - df[df$TT==1,paste0(i,"_TT")] <- df[df$TT==1,i] - } - resp_alt <- df[,items_n_alt] - pcm_initial <- TAM::tam.mml(resp=resp,Y=grp,irtmodel = "PCM",est.variance = T,verbose=F) - pcm_alt <- TAM::tam.mml(resp=resp_alt,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) - 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)] <- rowMeans(predict(pcm_initial)$stand.resid[,,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'] - } - if (verbose) { - cat('DONE\n') - cat('-----------------------------------------------------------\n') - } - res.items <- c() - res.uniform <- c() - k <- 1 - if (anova(pcm_initial,pcm_alt)$p[1]<0.05) { - while(any(pval<0.05/nbitems_o)) { + res.items <- c() + k <- 1 + while(any(pval<0.05/(nbitems_o))) { k <- k+1 if (verbose) { cat(paste('COMPUTING STEP',k,'\n')) @@ -230,8 +117,6 @@ resali_LRT <- function(df=NULL,items=NULL,group=NULL,verbose=T) { } 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[,paste0("item",res.item,'TT')] <- dat[dat$TT==1,paste0('item',res.item)] dat[,paste0("item",res.item,'noTT')] <- dat[dat$TT==0,paste0('item',res.item)] @@ -243,11 +128,19 @@ resali_LRT <- function(df=NULL,items=NULL,group=NULL,verbose=T) { pval <- rep(NA,nbitems) fval <- rep(NA,nbitems) for (i in 1:nbitems) { - dat[,paste0('res_',i)] <- rowMeans(predict(pcm_while)$stand.resid[,,i]) - res.anova[i] <- summary(aov(dat[,paste0('res_',i)]~TT*score_q5,data=dat)) + 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') @@ -259,7 +152,7 @@ resali_LRT <- function(df=NULL,items=NULL,group=NULL,verbose=T) { } if (length(res.items>0)) { results <- data.frame(dif.items=res.items, - uniform=1*res.uniform) + uniform=rep(1,length(res.items))) return(results) } else { @@ -268,11 +161,6 @@ resali_LRT <- function(df=NULL,items=NULL,group=NULL,verbose=T) { } return(NULL) } + } - else { - if (verbose) { - cat("No DIF was detected\n") - } - return(NULL) - } -} \ No newline at end of file +} diff --git a/RProject/Scripts/resali_generate_newdata.R b/RProject/Scripts/resali_generate_newdata.R index f70009e..19c2d29 100644 --- a/RProject/Scripts/resali_generate_newdata.R +++ b/RProject/Scripts/resali_generate_newdata.R @@ -1,141 +1,3 @@ -## 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')))) - -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 <- sort(results) - -results2 <- sort(results2) - -results <- c(results,results2) - -## Importer l'analyse resali pour chaque scenario - -for (r in results) { - cat('--------------------------------------------------------------------------\n') - cat(paste0(r,"\n")) - cat('--------------------------------------------------------------------------\n') - #### Importer les datas - scen <- as.numeric(gsub("[A,B,C,D,E,F,G,_]","",substr(r,0,3))) - if (substr(r,start=nchar(r)-1,stop=nchar(r))=="50") { - N <- 50 - } - if (substr(r,start=nchar(r)-2,stop=nchar(r))=="100") { - N <- 100 - } - if (substr(r,start=nchar(r)-2,stop=nchar(r))=="200") { - N <- 200 - } - if (substr(r,start=nchar(r)-2,stop=nchar(r))=="300") { - N <- 300 - } - if (scen<5) { - datt <- read.csv(paste0('/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N',N,'/scenario_',r,'.csv')) - } - if (scen>=5) { - datt <- read.csv(paste0('/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N',N,'/scenario_',r,'.csv')) - } - #### Importer l'analyse - analyse <- read.csv(paste0('/home/corentin/Documents/These/Recherche/Simulations/Analysis/RESALI/Detection/',r,".csv")) - #### Pour chaque replication - for (k in 1:1000) { - if (k%%100==0) { - cat(paste0("N = ",k," / 1000\n")) - } - datt[datt$replication==k,"dif.detect.1"] <- analyse[analyse$X==k,"dif.detect.1"] - datt[datt$replication==k,"dif.detect.2"] <- analyse[analyse$X==k,"dif.detect.2"] - datt[datt$replication==k,"dif.detect.3"] <- analyse[analyse$X==k,"dif.detect.3"] - datt[datt$replication==k,"dif.detect.4"] <- analyse[analyse$X==k,"dif.detect.4"] - datt[datt$replication==k,"dif.detect.unif.1"] <- analyse[analyse$X==k,"dif.detect.unif.1"] - datt[datt$replication==k,"dif.detect.unif.2"] <- analyse[analyse$X==k,"dif.detect.unif.2"] - datt[datt$replication==k,"dif.detect.unif.3"] <- analyse[analyse$X==k,"dif.detect.unif.3"] - datt[datt$replication==k,"dif.detect.unif.4"] <- analyse[analyse$X==k,"dif.detect.unif.4"] - if (scen==3 | scen==4 | scen>=13) { - datt[datt$replication==k,"dif.detect.5"] <- analyse[analyse$X==k,"dif.detect.5"] - datt[datt$replication==k,"dif.detect.6"] <- analyse[analyse$X==k,"dif.detect.6"] - datt[datt$replication==k,"dif.detect.7"] <- analyse[analyse$X==k,"dif.detect.7"] - datt[datt$replication==k,"dif.detect.unif.5"] <- analyse[analyse$X==k,"dif.detect.unif.5"] - datt[datt$replication==k,"dif.detect.unif.6"] <- analyse[analyse$X==k,"dif.detect.unif.6"] - datt[datt$replication==k,"dif.detect.unif.7"] <- analyse[analyse$X==k,"dif.detect.unif.7"] - } - } - datt[is.na(datt$dif.detect.1),"dif.detect.1"] <- "" - datt[is.na(datt$dif.detect.2),"dif.detect.2"] <- "" - datt[is.na(datt$dif.detect.3),"dif.detect.3"] <- "" - datt[is.na(datt$dif.detect.4),"dif.detect.4"] <- "" - datt[is.na(datt$dif.detect.unif.1),"dif.detect.unif.1"] <- "" - datt[is.na(datt$dif.detect.unif.2),"dif.detect.unif.2"] <- "" - datt[is.na(datt$dif.detect.unif.3),"dif.detect.unif.3"] <- "" - datt[is.na(datt$dif.detect.unif.4),"dif.detect.unif.4"] <- "" - if (scen==3 | scen==4 | scen>=13) { - datt[is.na(datt$dif.detect.5),"dif.detect.5"] <- "" - datt[is.na(datt$dif.detect.6),"dif.detect.6"] <- "" - datt[is.na(datt$dif.detect.7),"dif.detect.7"] <- "" - datt[is.na(datt$dif.detect.unif.5),"dif.detect.unif.5"] <- "" - datt[is.na(datt$dif.detect.unif.6),"dif.detect.unif.6"] <- "" - datt[is.na(datt$dif.detect.unif.7),"dif.detect.unif.7"] <- "" - } - write.csv(datt,paste0("/home/corentin/Documents/These/Recherche/Simulations/Analysis/RESALI/Detection_data/",r,".csv")) -} - - - - - - - - - -for (r in results) { - cat('--------------------------------------------------------------------------\n') - cat(paste0(r,"\n")) - cat('--------------------------------------------------------------------------\n') - #### Importer les datas - scen <- as.numeric(gsub("[A,B,C,D,E,F,G,_]","",substr(r,0,3))) - if (substr(r,start=nchar(r)-1,stop=nchar(r))=="50") { - N <- 50 - } - if (substr(r,start=nchar(r)-2,stop=nchar(r))=="100") { - N <- 100 - } - if (substr(r,start=nchar(r)-2,stop=nchar(r))=="200") { - N <- 200 - } - if (substr(r,start=nchar(r)-2,stop=nchar(r))=="300") { - N <- 300 - } - #### Importer l'analyse - analyse <- read.csv(paste0("/home/corentin/Documents/These/Recherche/Simulations/Analysis/RESALI/Detection_data/",r,".csv")) - analyse[is.na(analyse)] <- "" - names(analyse)[names(analyse)=="dif.detect.1"] <- "dif_detect_1" - names(analyse)[names(analyse)=="dif.detect.2"] <- "dif_detect_2" - names(analyse)[names(analyse)=="dif.detect.3"] <- "dif_detect_3" - names(analyse)[names(analyse)=="dif.detect.4"] <- "dif_detect_4" - names(analyse)[names(analyse)=="dif.detect.unif.1"] <- "dif_detect_unif_1" - names(analyse)[names(analyse)=="dif.detect.unif.2"] <- "dif_detect_unif_2" - names(analyse)[names(analyse)=="dif.detect.unif.3"] <- "dif_detect_unif_3" - names(analyse)[names(analyse)=="dif.detect.unif.4"] <- "dif_detect_unif_4" - - - if (scen==3 | scen==4 | scen>=13) { - names(analyse)[names(analyse)=="dif.detect.5"] <- "dif_detect_5" - names(analyse)[names(analyse)=="dif.detect.6"] <- "dif_detect_6" - names(analyse)[names(analyse)=="dif.detect.7"] <- "dif_detect_7" - names(analyse)[names(analyse)=="dif.detect.unif.5"] <- "dif_detect_unif_5" - names(analyse)[names(analyse)=="dif.detect.unif.6"] <- "dif_detect_unif_6" - names(analyse)[names(analyse)=="dif.detect.unif.7"] <- "dif_detect_unif_7" - - } - analyse <- analyse[,!names(analyse) %in% c("X","X.1","X.2")] - write.csv(analyse,paste0("/home/corentin/Documents/These/Recherche/Simulations/Analysis/RESALI/Detection_data/",r,".csv")) -} - - ############################################################################## #----------------------------------------------------------------------------# ################################### RESALI ################################### @@ -251,9 +113,6 @@ generate_resali <- function(scenario=NULL,grp=NULL) { - - - 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')))) @@ -275,6 +134,146 @@ for (r in results) { cat(paste0("-------------------------------------------","\n")) } +############################################################################## +#----------------------------------------------------------------------------# +################################### NEWDATA ################################## +#----------------------------------------------------------------------------# +############################################################################## + +## 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')))) + +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 <- sort(results) + +results2 <- sort(results2) + +results <- c(results,results2) + +## Importer l'analyse resali pour chaque scenario + +for (r in results) { + cat('--------------------------------------------------------------------------\n') + cat(paste0(r,"\n")) + cat('--------------------------------------------------------------------------\n') + #### Importer les datas + scen <- as.numeric(gsub("[A,B,C,D,E,F,G,_]","",substr(r,0,3))) + if (substr(r,start=nchar(r)-1,stop=nchar(r))=="50") { + N <- 50 + } + if (substr(r,start=nchar(r)-2,stop=nchar(r))=="100") { + N <- 100 + } + if (substr(r,start=nchar(r)-2,stop=nchar(r))=="200") { + N <- 200 + } + if (substr(r,start=nchar(r)-2,stop=nchar(r))=="300") { + N <- 300 + } + if (scen<5) { + datt <- read.csv(paste0('/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N',N,'/scenario_',r,'.csv')) + } + if (scen>=5) { + datt <- read.csv(paste0('/home/corentin/Documents/These/Recherche/Simulations/Data/DIF/N',N,'/scenario_',r,'.csv')) + } + #### Importer l'analyse + analyse <- read.csv(paste0('/home/corentin/Documents/These/Recherche/Simulations/Analysis/RESALI/Detection/',r,".csv")) + #### Pour chaque replication + for (k in 1:1000) { + if (k%%100==0) { + cat(paste0("N = ",k," / 1000\n")) + } + datt[datt$replication==k,"dif.detect.1"] <- analyse[analyse$X==k,"dif.detect.1"] + datt[datt$replication==k,"dif.detect.2"] <- analyse[analyse$X==k,"dif.detect.2"] + datt[datt$replication==k,"dif.detect.3"] <- analyse[analyse$X==k,"dif.detect.3"] + datt[datt$replication==k,"dif.detect.4"] <- analyse[analyse$X==k,"dif.detect.4"] + datt[datt$replication==k,"dif.detect.unif.1"] <- analyse[analyse$X==k,"dif.detect.unif.1"] + datt[datt$replication==k,"dif.detect.unif.2"] <- analyse[analyse$X==k,"dif.detect.unif.2"] + datt[datt$replication==k,"dif.detect.unif.3"] <- analyse[analyse$X==k,"dif.detect.unif.3"] + datt[datt$replication==k,"dif.detect.unif.4"] <- analyse[analyse$X==k,"dif.detect.unif.4"] + if (scen==3 | scen==4 | scen>=13) { + datt[datt$replication==k,"dif.detect.5"] <- analyse[analyse$X==k,"dif.detect.5"] + datt[datt$replication==k,"dif.detect.6"] <- analyse[analyse$X==k,"dif.detect.6"] + datt[datt$replication==k,"dif.detect.7"] <- analyse[analyse$X==k,"dif.detect.7"] + datt[datt$replication==k,"dif.detect.unif.5"] <- analyse[analyse$X==k,"dif.detect.unif.5"] + datt[datt$replication==k,"dif.detect.unif.6"] <- analyse[analyse$X==k,"dif.detect.unif.6"] + datt[datt$replication==k,"dif.detect.unif.7"] <- analyse[analyse$X==k,"dif.detect.unif.7"] + } + } + datt[is.na(datt$dif.detect.1),"dif.detect.1"] <- "" + datt[is.na(datt$dif.detect.2),"dif.detect.2"] <- "" + datt[is.na(datt$dif.detect.3),"dif.detect.3"] <- "" + datt[is.na(datt$dif.detect.4),"dif.detect.4"] <- "" + datt[is.na(datt$dif.detect.unif.1),"dif.detect.unif.1"] <- "" + datt[is.na(datt$dif.detect.unif.2),"dif.detect.unif.2"] <- "" + datt[is.na(datt$dif.detect.unif.3),"dif.detect.unif.3"] <- "" + datt[is.na(datt$dif.detect.unif.4),"dif.detect.unif.4"] <- "" + if (scen==3 | scen==4 | scen>=13) { + datt[is.na(datt$dif.detect.5),"dif.detect.5"] <- "" + datt[is.na(datt$dif.detect.6),"dif.detect.6"] <- "" + datt[is.na(datt$dif.detect.7),"dif.detect.7"] <- "" + datt[is.na(datt$dif.detect.unif.5),"dif.detect.unif.5"] <- "" + datt[is.na(datt$dif.detect.unif.6),"dif.detect.unif.6"] <- "" + datt[is.na(datt$dif.detect.unif.7),"dif.detect.unif.7"] <- "" + } + write.csv(datt,paste0("/home/corentin/Documents/These/Recherche/Simulations/Analysis/RESALI/Detection_data/",r,".csv")) +} + + + + + + + + + +for (r in results) { + cat('--------------------------------------------------------------------------\n') + cat(paste0(r,"\n")) + cat('--------------------------------------------------------------------------\n') + #### Importer les datas + scen <- as.numeric(gsub("[A,B,C,D,E,F,G,_]","",substr(r,0,3))) + if (substr(r,start=nchar(r)-1,stop=nchar(r))=="50") { + N <- 50 + } + if (substr(r,start=nchar(r)-2,stop=nchar(r))=="100") { + N <- 100 + } + if (substr(r,start=nchar(r)-2,stop=nchar(r))=="200") { + N <- 200 + } + if (substr(r,start=nchar(r)-2,stop=nchar(r))=="300") { + N <- 300 + } + #### Importer l'analyse + analyse <- read.csv(paste0("/home/corentin/Documents/These/Recherche/Simulations/Analysis/RESALI/Detection_data/",r,".csv")) + analyse[is.na(analyse)] <- "" + names(analyse)[names(analyse)=="dif.detect.1"] <- "dif_detect_1" + names(analyse)[names(analyse)=="dif.detect.2"] <- "dif_detect_2" + names(analyse)[names(analyse)=="dif.detect.3"] <- "dif_detect_3" + names(analyse)[names(analyse)=="dif.detect.4"] <- "dif_detect_4" + names(analyse)[names(analyse)=="dif.detect.unif.1"] <- "dif_detect_unif_1" + names(analyse)[names(analyse)=="dif.detect.unif.2"] <- "dif_detect_unif_2" + names(analyse)[names(analyse)=="dif.detect.unif.3"] <- "dif_detect_unif_3" + names(analyse)[names(analyse)=="dif.detect.unif.4"] <- "dif_detect_unif_4" + + if (scen==3 | scen==4 | scen>=13) { + names(analyse)[names(analyse)=="dif.detect.5"] <- "dif_detect_5" + names(analyse)[names(analyse)=="dif.detect.6"] <- "dif_detect_6" + names(analyse)[names(analyse)=="dif.detect.7"] <- "dif_detect_7" + names(analyse)[names(analyse)=="dif.detect.unif.5"] <- "dif_detect_unif_5" + names(analyse)[names(analyse)=="dif.detect.unif.6"] <- "dif_detect_unif_6" + names(analyse)[names(analyse)=="dif.detect.unif.7"] <- "dif_detect_unif_7" + } + analyse <- analyse[,!names(analyse) %in% c("X","X.1","X.2")] + write.csv(analyse,paste0("/home/corentin/Documents/These/Recherche/Simulations/Analysis/RESALI/Detection_data/",r,".csv")) +}