diff --git a/01b_MesobromionCluster.R b/01b_MesobromionCluster.R index 74c33e52d9ad46701bd34ff63c393b22e2ef6f4a..bf025d498eda01feeb7500d2943bf9b9f326f104 100644 --- a/01b_MesobromionCluster.R +++ b/01b_MesobromionCluster.R @@ -116,6 +116,7 @@ Mesobromion <- function(species.path, traits.path, output, myfunction="get.corXY if(combinations=="sequential"){ + if(!is.na(start.round)){ print(paste("Load data from previous round=", start.round-1)) load(file = paste(output, "_round_", start.round-1, ".RData", sep="")) @@ -127,23 +128,37 @@ Mesobromion <- function(species.path, traits.path, output, myfunction="get.corXY allcomb.t <- lapply(1:ncol(traits), function(x){return(x)}) nall <- length(allcomb.t) } else { - best.row <- corXY.ci %>% - filter(Trait.comb==best) - upper <- best.row$q975 - lower <- best.row$q025 + if(nround >= relax.round){ + best <- corXY.ci %>% + filter(ntraits==(nround-1)) %>% + arrange(desc(Coef.obs)) %>% + slice(1) %>% + pull(Trait.comb) + + new.best.row <- corXY.ci %>% + filter(Trait.comb==best) + upper <- new.best.row$q975 + lower <- new.best.row$q025 + print(paste("Assumptions relaxed - new best at round=", nround, "is trait combination", best)) + } else { + best.row <- corXY.ci %>% + filter(Trait.comb==best) + upper <- best.row$q975 + lower <- best.row$q025 + } best.split <- as.numeric(unlist(strsplit(best, "_"))) - max.inter.t <- nround-length(best.split) + max.inter.ti <- nround-length(best.split) #n.traits <- ncol(traits) list.traits <- as.numeric(traits.sign.alone) list.traits <- list.traits[-which(list.traits %in% best.split)] ## list of remaining traits without best - if(length(list.traits) < max.inter.t) { + if(length(list.traits) < max.inter.ti) { save(corXY.output, file = paste(output, ".RData", sep="")) if(ncores>1) {stopCluster(cl)} stop("Tested all combo of significant traits") } allcomb.t <- NULL #for(n.inter in 1:max.inter.t){ - allcomb.t <- c(allcomb.t, combn(list.traits, max.inter.t, simplify=F)) + allcomb.t <- c(allcomb.t, combn(list.traits, max.inter.ti, simplify=F)) #} #add best to all combo allcomb.t <- lapply(allcomb.t, function(x){return(c(best.split, x))}) @@ -196,7 +211,7 @@ Mesobromion <- function(species.path, traits.path, output, myfunction="get.corXY print(paste("new best at nround=", nround, "is trait combination", best)) } - if(nround>1 & nround < relax.round){ + if(nround>1){ better <- corXY.ci %>% filter(ntraits==nround) %>% filter(q025>upper) %>% @@ -219,22 +234,6 @@ Mesobromion <- function(species.path, traits.path, output, myfunction="get.corXY print(paste("new best at round=", nround, "is trait combination", best)) } else {print(paste("no new best at round=", nround))} } - - if(nround>1 & nround > relax.round){ - better <- corXY.ci %>% - filter(ntraits==nround) %>% - arrange(desc(Coef.obs)) %>% - slice(1) %>% - pull(Trait.comb) - - new.best.row <- corXY.ci %>% - filter(Trait.comb==better) - upper <- new.best.row$q975 - lower <- new.best.row$q025 - best <- better - print(paste("Assumptions relaxed - new best at round=", nround, "is trait combination", best)) - } - print(paste("save intermediate results at round", nround)) save(corXY.output, best, traits.sign.alone, corXY.ci, file = paste(output, "_round_",nround, ".RData", sep="")) } diff --git a/session.R b/session.R index c62e04869bbdb9542ba71fef80d667cb0e487edd..f17c1c5334bb8c3bf842bee3b3bf9a17262a3bb6 100644 --- a/session.R +++ b/session.R @@ -1,17 +1,19 @@ species.path <- "_data/Mesobromion/species.out.10perc.txt" traits.path <- "_data/Mesobromion/traits.out.10perc.txt" -output <- "test99" +output <- "_derived/Mesobromion/HIDDEN" myfunction <- "get.corXY.bootstrap" -max.inter.t <- 3 +max.inter.t <- 7 chunk.i <- NA -nperm <- 20 +nperm <- 2 ncores <- 1 chunkn <- 3*ncores combinations <- "sequential" -start.round <- 4 +start.round <- 6 +relax.round <- 6 source("01b_MesobromionCluster.R") #Mesobromion(species.path, traits.path, output, myfunction, max.inter.t, chunkn, chunk.i, nperm) -Mesobromion(species.path, traits.path, output, myfunction, combinations, start.round, max.inter.t, +Mesobromion(species.path, traits.path, output, myfunction, + combinations, start.round, relax.round, max.inter.t, chunkn, chunk.i, nperm, ncores)