diff --git a/RProject/.RData b/RProject/.RData index 32c9193..f7cb732 100644 Binary files a/RProject/.RData and b/RProject/.RData differ diff --git a/RProject/.Rhistory b/RProject/.Rhistory index 871b7c1..ab949ab 100644 --- a/RProject/.Rhistory +++ b/RProject/.Rhistory @@ -1,7 +1,223 @@ -wwwwww <- read.csv('/home/corentin/Documents/These/Recherche/Simulations/Analysis/RESALI/Detection_data/3A_200.csv') -table(wwwwww$dif.detect.1) -table(wwwwww$dif.detect.1)/400 -sum(table(wwwwww$dif.detect.1)/400) +item2 ~~ 1*item2 +item3 ~~ 1*item3 +item4 ~~ 1*item4 +# thresholds +item1 | t1 +item2 | t1 +item3 | t1 +item4 | t1 +" +fit <- lavaan::sem(model,data=aaaa,estimator='WLSMV',link="logit",do.fit=T,mimic="Mplus") +summary(fit) +library(lavaan) +model <- " +# measurement model +lt =~ 1*item1 +lt =~ 1*item2 +lt =~ 1*item3 +lt =~ 1*item4 +# regressions +lt ~ TT +# residual correlations +item1 ~~ 1*item2+1*item3+1*item4 +item2 ~~ 1*item3+1*item4 +item3 ~~ 1*item4 +" +fit <- lavaan::sem(model,data=aaaa,estimator='WLSMV',link="logit",do.fit=T,mimic="Mplus") +summary(fit) +library(lavaan) +model <- " +# measurement model +lt =~ item1 +lt =~ item2 +lt =~ item3 +lt =~ item4 +# regressions +lt ~ TT +# residual correlations +item1 ~~ 1*item2+1*item3+1*item4 +item2 ~~ 1*item3+1*item4 +item3 ~~ 1*item4 +" +fit <- lavaan::sem(model,data=aaaa,estimator='WLSMV',link="logit",do.fit=T,mimic="Mplus") +summary(fit) +library(lavaan) +model <- " +# measurement model +lt =~ item1 +lt =~ item2 +lt =~ item3 +lt =~ item4 +# regressions +lt ~ TT +# residual correlations +item1 ~~ 1*item2+1*item3+1*item4 +item2 ~~ 1*item3+1*item4 +item3 ~~ 1*item4 +" +fit <- lavaan::sem(model,data=aaaa,estimator='MML',link="logit",do.fit=T,mimic="Mplus") +summary(fit) +library(lavaan) +model <- " +# measurement model +lt =~ 1*item1 +lt =~ 1*item2 +lt =~ 1*item3 +lt =~ 1*item4 +# regressions +lt ~ TT +# residual correlations +item1 ~~ item1 +item2 ~~ item2 +item3 ~~ item3 +item4 ~~ item4 +" +fit <- lavaan::cfa(model,data=aaaa,estimator='MML',link="logit",do.fit=T,mimic="Mplus") +summary(fit) +library(lavaan) +model <- " +# measurement model +lt =~ 1*item1 +lt =~ 1*item2 +lt =~ 1*item3 +lt =~ 1*item4 +# regressions +lt ~ TT +# residual correlations +item1 ~~ item1 +item2 ~~ item2 +item3 ~~ item3 +item4 ~~ item4 +" +fit <- lavaan::cfa(model,data=aaaa,estimator='MML',link="logit",do.fit=T,mimic="Mplus",std.lv=T) +summary(fit) +library(lavaan) +model <- " +# measurement model +lt =~ 1*item1 +lt =~ 1*item2 +lt =~ 1*item3 +lt =~ 1*item4 +# regressions +lt ~ TT +item1 | t1 +item2 | t1 +item3 | t1 +item4 | t1 +# residual correlations +item1 ~~ item1 +item2 ~~ item2 +item3 ~~ item3 +item4 ~~ item4 +" +fit <- lavaan::cfa(model,data=aaaa,estimator='MML',link="logit",do.fit=T,mimic="Mplus",std.lv=T) +summary(fit) +library(lavaan) +model <- " +# measurement model +lt =~ 1*item1 +lt =~ 1*item2 +lt =~ 1*item3 +lt =~ 1*item4 +# regressions +lt ~ TT +item1 | t1 +item2 | t2 +item3 | t3 +item4 | t4 +# residual correlations +item1 ~~ item1 +item2 ~~ item2 +item3 ~~ item3 +item4 ~~ item4 +" +fit <- lavaan::cfa(model,data=aaaa,estimator='MML',link="logit",do.fit=T,mimic="Mplus",std.lv=T) +summary(fit) +library(lavaan) +model <- " +# measurement model +lt =~ 1*item1 +lt =~ 1*item2 +lt =~ 1*item3 +lt =~ 1*item4 +# regressions +lt ~ TT +item1 | t1 +item2 | t1 +item3 | t1 +item4 | t1 +# residual correlations +item1 ~~ item1 +item2 ~~ item2 +item3 ~~ item3 +item4 ~~ item4 +" +fit <- lavaan::cfa(model,data=aaaa,estimator='MML',link="logit",do.fit=T,mimic="Mplus",std.lv=T) +summary(fit) +library(lavaan) +model <- " +# measurement model +lt =~ 1*item1 +lt =~ 1*item2 +lt =~ 1*item3 +lt =~ 1*item4 +# regressions +lt ~ TT +item1 | t1 +item2 | t1 +item3 | t1 +item4 | t1 +# residual correlations +item1 ~~ item1 +item2 ~~ item2 +item3 ~~ item3 +item4 ~~ item4 +" +fit <- lavaan::sem(model,data=aaaa,estimator='MML',link="logit",do.fit=T,mimic="Mplus",std.lv=T) +summary(fit) +library(lavaan) +model <- " +# measurement model +lt =~ 1*item1 +lt =~ 1*item2 +lt =~ 1*item3 +lt =~ 1*item4 +# regressions +lt ~ TT +item1 | t1 +item2 | t1 +item3 | t1 +item4 | t1 +# residual correlations +item1 ~~ item1 +item2 ~~ item2 +item3 ~~ item3 +item4 ~~ item4 +" +fit <- lavaan::sem(model,data=aaaa,estimator='ML',link="logit",do.fit=T,mimic="Mplus",std.lv=T) +library(lavaan) +model <- " +# measurement model +lt =~ 1*item1 +lt =~ 1*item2 +lt =~ 1*item3 +lt =~ 1*item4 +# regressions +lt ~ TT +item1 | t1 +item2 | t1 +item3 | t1 +item4 | t1 +# residual correlations +item1 ~~ item1 +item2 ~~ item2 +item3 ~~ item3 +item4 ~~ item4 +" +fit <- lavaan::sem(model,data=aaaa,estimator='WLSMV',link="logit",do.fit=T,mimic="Mplus",std.lv=T) +summary(fit) +lavaanCatItemPlot = function(lavObject, varname, sds = 3){ output = inspect(object = lavObject, what = "est") if (!varname %in% rownames(output$lambda)) stop(paste(varname, "not found in lavaan object")) if (dim(output$lambda)[2]>1) stop("plots only given for one factor models") itemloading = output$lambda[which(rownames(output$lambda) == varname),1] itemthresholds = output$tau[grep(pattern = varname, x = rownames(output$tau))] factorname = colnames(output$lambda) factormean = output$alpha[which(rownames(output$alpha) == factorname)] factorvar = output$psi[which(rownames(output$psi) == factorname)] factormin = factormean - 3*sqrt(factorvar) factormax = factormean + 3*sqrt(factorvar) factorX = seq(factormin, factormax, .01) itemloc = which(lavObject@Data@ov$name == varname) itemlevels = unlist(strsplit(x = lavObject@Data@ov$lnam[itemloc], split = "\\|")) if (length(itemthresholds)>1){ plotdata = NULL plotdata2 = NULL itemY = NULL itemY2 = NULL itemX = NULL itemText = NULL for (level in 1:length(itemthresholds)){ itemY = pnorm(q = -1*itemthresholds[level] + itemloading*factorX) itemY2 = cbind(itemY2, pnorm(q = -1*itemthresholds[level] + itemloading*factorX)) itemText = paste0("P(", varname, " > ", itemlevels[level], ")") itemText2 = paste0("P(", varname, " = ", itemlevels[level], ")") plotdata = rbind(plotdata, data.frame(factor = factorX, prob = itemY, plot = itemText)) if (level == 1){ plotdata2 = data.frame(factor = factorX, plot = itemText2, prob = matrix(1, nrow = dim(itemY2)[1], ncol=1) - itemY2[,level]) } else if (level == length(itemthresholds)){ plotdata2 = rbind(plotdata2, data.frame(factor = factorX, plot = itemText2, prob = itemY2[,level-1] - itemY2[,level])) plotdata2 = rbind(plotdata2, data.frame(factor = factorX, plot = paste0("P(", varname, " = ", itemlevels[level+1], ")"), prob = itemY2[,level])) } else { plotdata2 = rbind(plotdata2, data.frame(factor = factorX, plot = itemText2, prob = itemY2[,level-1] - itemY2[,level])) } } names(plotdata) = c(factorname , "Probability", "Cumulative") ggplot(data = plotdata, aes_string(x = factorname, y = "Probability", colour = "Cumulative")) + geom_line(size = 2) names(plotdata2) = c(factorname, "Response", "Probability") ggplot(data = plotdata2, aes_string(x = factorname, y = "Probability", colour = "Response")) + geom_line(size = 2) } else { itemY = pnorm(q = -1*itemthresholds[1] + itemloading*factorX) itemText2 = paste0("P(", varname, " = ", itemlevels[1], ")") plotdata = data.frame(factor = factorX, prob = itemY, plot = itemText2) names(plotdata) = c(factorname , "Probability", "Response") ggplot(data = plotdata, aes_string(x = factorname, y = "Probability", colour = "Response")) + geom_line(size = 2) } } lavaanCatItemPlot(lavObject = grm2Pestimates, varname = "cia2", sds = 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))) @@ -9,8 +225,7 @@ 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[473:length(results)]) { +for (r in results[5]) { cat('--------------------------------------------------------------------------\n') cat(paste0(r,"\n")) cat('--------------------------------------------------------------------------\n') @@ -28,54 +243,43 @@ 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"] <- "" +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" +analyse[analyse$dif_detect_1==999,"dif_detect_1"] <- "" +analyse[analyse$dif_detect_2==999,"dif_detect_2"] <- "" +analyse[analyse$dif_detect_3==999,"dif_detect_3"] <- "" +analyse[analyse$dif_detect_4==999,"dif_detect_4"] <- "" +analyse[analyse$dif_detect_unif_1==999,"dif_detect_unif_1"] <- "" +analyse[analyse$dif_detect_unif_2==999,"dif_detect_unif_2"] <- "" +analyse[analyse$dif_detect_unif_3==999,"dif_detect_unif_3"] <- "" +analyse[analyse$dif_detect_unif_4==999,"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"] <- "" +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$dif_detect_5==999,"dif_detect_5"] <- "" +analyse[analyse$dif_detect_6==999,"dif_detect_6"] <- "" +analyse[analyse$dif_detect_7==999,"dif_detect_7"] <- "" +analyse[analyse$dif_detect_unif_5==999,"dif_detect_unif_5"] <- "" +analyse[analyse$dif_detect_unif_6==999,"dif_detect_unif_6"] <- "" +analyse[analyse$dif_detect_unif_7==999,"dif_detect_unif_7"] <- "" } -write.csv(datt,paste0("/home/corentin/Documents/These/Recherche/Simulations/Analysis/RESALI/Detection_data/",r,".csv")) +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")) } +## 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))) @@ -84,7 +288,7 @@ results <- sort(results) results2 <- sort(results2) results <- c(results,results2) ## Importer l'analyse resali pour chaque scenario -for (r in results) { +for (r in results[5]) { cat('--------------------------------------------------------------------------\n') cat(paste0(r,"\n")) cat('--------------------------------------------------------------------------\n') @@ -150,60 +354,7 @@ 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")) -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" -analyse[analyse$dif_detect_1==999,"dif_detect_1"] <- "" -analyse[analyse$dif_detect_2==999,"dif_detect_2"] <- "" -analyse[analyse$dif_detect_3==999,"dif_detect_3"] <- "" -analyse[analyse$dif_detect_4==999,"dif_detect_4"] <- "" -analyse[analyse$dif_detect_unif_1==999,"dif_detect_unif_1"] <- "" -analyse[analyse$dif_detect_unif_2==999,"dif_detect_unif_2"] <- "" -analyse[analyse$dif_detect_unif_3==999,"dif_detect_unif_3"] <- "" -analyse[analyse$dif_detect_unif_4==999,"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$dif_detect_5==999,"dif_detect_5"] <- "" -analyse[analyse$dif_detect_6==999,"dif_detect_6"] <- "" -analyse[analyse$dif_detect_7==999,"dif_detect_7"] <- "" -analyse[analyse$dif_detect_unif_5==999,"dif_detect_unif_5"] <- "" -analyse[analyse$dif_detect_unif_6==999,"dif_detect_unif_6"] <- "" -analyse[analyse$dif_detect_unif_7==999,"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")) -} -for (r in results[-c(1:4)]) { +for (r in results[5]) { cat('--------------------------------------------------------------------------\n') cat(paste0(r,"\n")) cat('--------------------------------------------------------------------------\n') @@ -223,6 +374,7 @@ 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" @@ -231,14 +383,6 @@ 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" -analyse[analyse$dif_detect_1==999,"dif_detect_1"] <- "" -analyse[analyse$dif_detect_2==999,"dif_detect_2"] <- "" -analyse[analyse$dif_detect_3==999,"dif_detect_3"] <- "" -analyse[analyse$dif_detect_4==999,"dif_detect_4"] <- "" -analyse[analyse$dif_detect_unif_1==999,"dif_detect_unif_1"] <- "" -analyse[analyse$dif_detect_unif_2==999,"dif_detect_unif_2"] <- "" -analyse[analyse$dif_detect_unif_3==999,"dif_detect_unif_3"] <- "" -analyse[analyse$dif_detect_unif_4==999,"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" @@ -246,17 +390,21 @@ 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$dif_detect_5==999,"dif_detect_5"] <- "" -analyse[analyse$dif_detect_6==999,"dif_detect_6"] <- "" -analyse[analyse$dif_detect_7==999,"dif_detect_7"] <- "" -analyse[analyse$dif_detect_unif_5==999,"dif_detect_unif_5"] <- "" -analyse[analyse$dif_detect_unif_6==999,"dif_detect_unif_6"] <- "" -analyse[analyse$dif_detect_unif_7==999,"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")) } -for (r in results) { +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')))) +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[17]) { cat('--------------------------------------------------------------------------\n') cat(paste0(r,"\n")) cat('--------------------------------------------------------------------------\n') @@ -274,189 +422,55 @@ 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")) -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$dif_detect_5==999,"dif_detect_5"] <- "" -#analyse[analyse$dif_detect_6==999,"dif_detect_6"] <- "" -#analyse[analyse$dif_detect_7==999,"dif_detect_7"] <- "" -#analyse[analyse$dif_detect_unif_5==999,"dif_detect_unif_5"] <- "" -#analyse[analyse$dif_detect_unif_6==999,"dif_detect_unif_6"] <- "" -#analyse[analyse$dif_detect_unif_7==999,"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")) -} -for (r in results[-c(1:4)]) { -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 (scen<5) { +datt <- read.csv(paste0('/home/corentin/Documents/These/Recherche/Simulations/Data/NoDIF/N',N,'/scenario_',r,'.csv')) } -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/DIF/N',N,'/scenario_',r,'.csv')) } #### Importer l'analyse -analyse <- read.csv(paste0("/home/corentin/Documents/These/Recherche/Simulations/Analysis/RESALI/Detection_data/",r,".csv")) -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" -analyse[analyse$dif_detect_1==999,"dif_detect_1"] <- "" -analyse[analyse$dif_detect_2==999,"dif_detect_2"] <- "" -analyse[analyse$dif_detect_3==999,"dif_detect_3"] <- "" -analyse[analyse$dif_detect_4==999,"dif_detect_4"] <- "" -analyse[analyse$dif_detect_unif_1==999,"dif_detect_unif_1"] <- "" -analyse[analyse$dif_detect_unif_2==999,"dif_detect_unif_2"] <- "" -analyse[analyse$dif_detect_unif_3==999,"dif_detect_unif_3"] <- "" -analyse[analyse$dif_detect_unif_4==999,"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$dif_detect_5==999,"dif_detect_5"] <- "" -analyse[analyse$dif_detect_6==999,"dif_detect_6"] <- "" -analyse[analyse$dif_detect_7==999,"dif_detect_7"] <- "" -analyse[analyse$dif_detect_unif_5==999,"dif_detect_unif_5"] <- "" -analyse[analyse$dif_detect_unif_6==999,"dif_detect_unif_6"] <- "" -analyse[analyse$dif_detect_unif_7==999,"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")) -} -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 +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")) } -#### Importer l'analyse -analyse <- read.csv(paste0("/home/corentin/Documents/These/Recherche/Simulations/Analysis/RESALI/Detection_data/",r,".csv")) -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" -analyse[analyse$dif_detect_1==999,"dif_detect_1"] <- "" -analyse[analyse$dif_detect_2==999,"dif_detect_2"] <- "" -analyse[analyse$dif_detect_3==999,"dif_detect_3"] <- "" -analyse[analyse$dif_detect_4==999,"dif_detect_4"] <- "" -analyse[analyse$dif_detect_unif_1==999,"dif_detect_unif_1"] <- "" -analyse[analyse$dif_detect_unif_2==999,"dif_detect_unif_2"] <- "" -analyse[analyse$dif_detect_unif_3==999,"dif_detect_unif_3"] <- "" -analyse[analyse$dif_detect_unif_4==999,"dif_detect_unif_4"] <- "" +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) { -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$dif_detect_5==999,"dif_detect_5"] <- "" -analyse[analyse$dif_detect_6==999,"dif_detect_6"] <- "" -analyse[analyse$dif_detect_7==999,"dif_detect_7"] <- "" -analyse[analyse$dif_detect_unif_5==999,"dif_detect_unif_5"] <- "" -analyse[analyse$dif_detect_unif_6==999,"dif_detect_unif_6"] <- "" -analyse[analyse$dif_detect_unif_7==999,"dif_detect_unif_7"] <- "" -} -analyse[is.na(analyse)] <- "" -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")) -} -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 +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"] } -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" -analyse[analyse$dif_detect_1==999,"dif_detect_1"] <- "" -analyse[analyse$dif_detect_2==999,"dif_detect_2"] <- "" -analyse[analyse$dif_detect_3==999,"dif_detect_3"] <- "" -analyse[analyse$dif_detect_4==999,"dif_detect_4"] <- "" -analyse[analyse$dif_detect_unif_1==999,"dif_detect_unif_1"] <- "" -analyse[analyse$dif_detect_unif_2==999,"dif_detect_unif_2"] <- "" -analyse[analyse$dif_detect_unif_3==999,"dif_detect_unif_3"] <- "" -analyse[analyse$dif_detect_unif_4==999,"dif_detect_unif_4"] <- "" +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) { -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" +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"] <- "" } -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")) +write.csv(datt,paste0("/home/corentin/Documents/These/Recherche/Simulations/Analysis/RESALI/Detection_data/",r,".csv")) } -for (r in results) { +for (r in results[17]) { cat('--------------------------------------------------------------------------\n') cat(paste0(r,"\n")) cat('--------------------------------------------------------------------------\n') @@ -485,14 +499,6 @@ 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" -analyse[analyse$dif_detect_1==999,"dif_detect_1"] <- "" -analyse[analyse$dif_detect_2==999,"dif_detect_2"] <- "" -analyse[analyse$dif_detect_3==999,"dif_detect_3"] <- "" -analyse[analyse$dif_detect_4==999,"dif_detect_4"] <- "" -analyse[analyse$dif_detect_unif_1==999,"dif_detect_unif_1"] <- "" -analyse[analyse$dif_detect_unif_2==999,"dif_detect_unif_2"] <- "" -analyse[analyse$dif_detect_unif_3==999,"dif_detect_unif_3"] <- "" -analyse[analyse$dif_detect_unif_4==999,"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" @@ -500,12 +506,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$dif_detect_5==999,"dif_detect_5"] <- "" -analyse[analyse$dif_detect_6==999,"dif_detect_6"] <- "" -analyse[analyse$dif_detect_7==999,"dif_detect_7"] <- "" -analyse[analyse$dif_detect_unif_5==999,"dif_detect_unif_5"] <- "" -analyse[analyse$dif_detect_unif_6==999,"dif_detect_unif_6"] <- "" -analyse[analyse$dif_detect_unif_7==999,"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")) diff --git a/RProject/Scripts/functions/resali.R b/RProject/Scripts/functions/resali.R index 1cf0a42..00f77cc 100644 --- a/RProject/Scripts/functions/resali.R +++ b/RProject/Scripts/functions/resali.R @@ -61,6 +61,14 @@ resali <- function(df=NULL,items=NULL,group=NULL,verbose=T) { 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') diff --git a/RProject/Scripts/resali_generate_newdata.R b/RProject/Scripts/resali_generate_newdata.R index 19173d5..fd60de5 100644 --- a/RProject/Scripts/resali_generate_newdata.R +++ b/RProject/Scripts/resali_generate_newdata.R @@ -120,14 +120,7 @@ for (r in results) { 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" - analyse[analyse$dif_detect_1==999,"dif_detect_1"] <- "" - analyse[analyse$dif_detect_2==999,"dif_detect_2"] <- "" - analyse[analyse$dif_detect_3==999,"dif_detect_3"] <- "" - analyse[analyse$dif_detect_4==999,"dif_detect_4"] <- "" - analyse[analyse$dif_detect_unif_1==999,"dif_detect_unif_1"] <- "" - analyse[analyse$dif_detect_unif_2==999,"dif_detect_unif_2"] <- "" - analyse[analyse$dif_detect_unif_3==999,"dif_detect_unif_3"] <- "" - analyse[analyse$dif_detect_unif_4==999,"dif_detect_unif_4"] <- "" + if (scen==3 | scen==4 | scen>=13) { names(analyse)[names(analyse)=="dif.detect.5"] <- "dif_detect_5" @@ -136,12 +129,7 @@ for (r in results) { 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$dif_detect_5==999,"dif_detect_5"] <- "" - analyse[analyse$dif_detect_6==999,"dif_detect_6"] <- "" - analyse[analyse$dif_detect_7==999,"dif_detect_7"] <- "" - analyse[analyse$dif_detect_unif_5==999,"dif_detect_unif_5"] <- "" - analyse[analyse$dif_detect_unif_6==999,"dif_detect_unif_6"] <- "" - analyse[analyse$dif_detect_unif_7==999,"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"))