diff --git a/01_Mesobromion.R b/01_Mesobromion.R index 238aae563bfddee8309384980fdbb0c02763fd6d..9d6bf71f46292ea21ebf34a52e70ee765adebeec 100644 --- a/01_Mesobromion.R +++ b/01_Mesobromion.R @@ -170,20 +170,25 @@ traits <- traits %>% #### ## Import output #### -myfilelist <- list.files(path="_derived/Mesobromion/", pattern="HIDDEN_[0-9]+.RData", full.names = T) +myfilelist <- list.files(path="_derived/Mesobromion/", pattern="HIDDEN(\\.[A-Za-z]+|_[A-Za-z]+)_[0-9]+.RData", full.names = T) corXY <- NULL -corXY.perm <- NULL -corXY.bootstr <- NULL +#corXY.perm <- NULL +#corXY.bootstr <- NULL for(ff in myfilelist){ index <- as.numeric(regmatches(ff, gregexpr("[[:digit:]]+", ff))[[1]]) load(ff) - corXY <- rbind(corXY, cor.obs) - corXY.perm <- rbind(corXY.perm, cor.perm) - corXY.bootstr <- rbind(corXY.bootstr, cor.bootstr) + corXY <- bind_rows(corXY, cor.obs) + #corXY.perm <- rbind(corXY.perm, cor.perm) + #corXY.bootstr <- rbind(corXY.bootstr, cor.bootstr) print(index) } +dataFiles = map(myfilelist, load) +dat = bind_rows(dataFiles) + + + diffs <- corXY.bootstr - corXY.perm sign <- apply(diffs, MARGIN=1, function(x){sum(x>0)>190}) sign <- data.frame(Trait.comb=names(sign), sign=sign) @@ -293,8 +298,7 @@ ggplot(data=mydata) + traits.sign <- traits %>% - rownames_to_column("species0") %>% - dplyr::select(traits.sign.alone) + dplyr::select(species0, traits.sign.alone) write_delim(traits.sign, path="_data/Mesobromion/traits.out.10perc.sign.txt", delim="\t") break() diff --git a/99_HIDDEN_functions.R b/99_HIDDEN_functions.R index 354b3b5c6fa6edb0082b8a64893fa944133d44d6..00659b1662c36d8817c8f93907f10b0388627e12 100644 --- a/99_HIDDEN_functions.R +++ b/99_HIDDEN_functions.R @@ -47,8 +47,7 @@ get.corXY <- function(comm, traits, trait.sel="all", stat=c("mantel", "RV", "pro } -### Cor XY bootstrap -#### Function 1 - CorXY #### +#### Function 1b - CorXY bootstrap#### get.corXY.bootstrap <- function(comm, traits, trait.sel="all", stat="RV", bootstrap=199){ if(identical(trait.sel, "all")) {trait.sel <- 1:ncol(traits)} ii <- trait.sel @@ -77,6 +76,7 @@ get.corXY.bootstrap <- function(comm, traits, trait.sel="all", stat="RV", bootst index.bootstr <- lapply(1:bootstrap, function(x){sample(1:n.sites, replace=T)}) for(b in 1:bootstrap){ RV.tmp <- RV.rtest(W.beals[index.bootstr[[b]],], as.data.frame(syn.out.tmp)[index.bootstr[[b]],]) + syn.out.perm.tmp <- matrix.x(comm=comm, traits=traits[index.traits[[bootstrap]],ii,drop=F], scale=T)$matrix.X RV.perm.tmp <- RV.rtest(W.beals[index.bootstr[[b]],], as.data.frame(syn.out.perm.tmp)[index.bootstr[[b]],]) corXY <- rbind(corXY, data.frame(Trait.comb=lab.tmp, bootstr.n=b, Test="RV", Coef.obs=RV.tmp$obs, Coef.perm=RV.perm.tmp$obs))