Skip to content
Snippets Groups Projects
Commit bb7f73f5 authored by Francesco Sabatini's avatar Francesco Sabatini
Browse files

Relaxed round - fixed

parent 681d56e7
No related branches found
No related tags found
No related merge requests found
...@@ -116,6 +116,7 @@ Mesobromion <- function(species.path, traits.path, output, myfunction="get.corXY ...@@ -116,6 +116,7 @@ Mesobromion <- function(species.path, traits.path, output, myfunction="get.corXY
if(combinations=="sequential"){ if(combinations=="sequential"){
if(!is.na(start.round)){ if(!is.na(start.round)){
print(paste("Load data from previous round=", start.round-1)) print(paste("Load data from previous round=", start.round-1))
load(file = paste(output, "_round_", start.round-1, ".RData", sep="")) load(file = paste(output, "_round_", start.round-1, ".RData", sep=""))
...@@ -127,23 +128,37 @@ Mesobromion <- function(species.path, traits.path, output, myfunction="get.corXY ...@@ -127,23 +128,37 @@ Mesobromion <- function(species.path, traits.path, output, myfunction="get.corXY
allcomb.t <- lapply(1:ncol(traits), function(x){return(x)}) allcomb.t <- lapply(1:ncol(traits), function(x){return(x)})
nall <- length(allcomb.t) nall <- length(allcomb.t)
} else { } else {
best.row <- corXY.ci %>% if(nround >= relax.round){
filter(Trait.comb==best) best <- corXY.ci %>%
upper <- best.row$q975 filter(ntraits==(nround-1)) %>%
lower <- best.row$q025 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, "_"))) 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) #n.traits <- ncol(traits)
list.traits <- as.numeric(traits.sign.alone) list.traits <- as.numeric(traits.sign.alone)
list.traits <- list.traits[-which(list.traits %in% best.split)] ## list of remaining traits without best 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="")) save(corXY.output, file = paste(output, ".RData", sep=""))
if(ncores>1) {stopCluster(cl)} if(ncores>1) {stopCluster(cl)}
stop("Tested all combo of significant traits") stop("Tested all combo of significant traits")
} }
allcomb.t <- NULL allcomb.t <- NULL
#for(n.inter in 1:max.inter.t){ #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 #add best to all combo
allcomb.t <- lapply(allcomb.t, function(x){return(c(best.split, x))}) 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 ...@@ -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)) print(paste("new best at nround=", nround, "is trait combination", best))
} }
if(nround>1 & nround < relax.round){ if(nround>1){
better <- corXY.ci %>% better <- corXY.ci %>%
filter(ntraits==nround) %>% filter(ntraits==nround) %>%
filter(q025>upper) %>% filter(q025>upper) %>%
...@@ -219,22 +234,6 @@ Mesobromion <- function(species.path, traits.path, output, myfunction="get.corXY ...@@ -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)) print(paste("new best at round=", nround, "is trait combination", best))
} else {print(paste("no new best at round=", nround))} } 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)) print(paste("save intermediate results at round", nround))
save(corXY.output, best, traits.sign.alone, corXY.ci, file = paste(output, "_round_",nround, ".RData", sep="")) save(corXY.output, best, traits.sign.alone, corXY.ci, file = paste(output, "_round_",nround, ".RData", sep=""))
} }
......
species.path <- "_data/Mesobromion/species.out.10perc.txt" species.path <- "_data/Mesobromion/species.out.10perc.txt"
traits.path <- "_data/Mesobromion/traits.out.10perc.txt" traits.path <- "_data/Mesobromion/traits.out.10perc.txt"
output <- "test99" output <- "_derived/Mesobromion/HIDDEN"
myfunction <- "get.corXY.bootstrap" myfunction <- "get.corXY.bootstrap"
max.inter.t <- 3 max.inter.t <- 7
chunk.i <- NA chunk.i <- NA
nperm <- 20 nperm <- 2
ncores <- 1 ncores <- 1
chunkn <- 3*ncores chunkn <- 3*ncores
combinations <- "sequential" combinations <- "sequential"
start.round <- 4 start.round <- 6
relax.round <- 6
source("01b_MesobromionCluster.R") 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, 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) chunkn, chunk.i, nperm, ncores)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment