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

Fixed bug in 99, started alignign 01

parent 1cd0f72e
Branches
No related tags found
No related merge requests found
...@@ -170,20 +170,25 @@ traits <- traits %>% ...@@ -170,20 +170,25 @@ traits <- traits %>%
#### ## Import output #### #### ## 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 <- NULL
corXY.perm <- NULL #corXY.perm <- NULL
corXY.bootstr <- NULL #corXY.bootstr <- NULL
for(ff in myfilelist){ for(ff in myfilelist){
index <- as.numeric(regmatches(ff, gregexpr("[[:digit:]]+", ff))[[1]]) index <- as.numeric(regmatches(ff, gregexpr("[[:digit:]]+", ff))[[1]])
load(ff) load(ff)
corXY <- rbind(corXY, cor.obs) corXY <- bind_rows(corXY, cor.obs)
corXY.perm <- rbind(corXY.perm, cor.perm) #corXY.perm <- rbind(corXY.perm, cor.perm)
corXY.bootstr <- rbind(corXY.bootstr, cor.bootstr) #corXY.bootstr <- rbind(corXY.bootstr, cor.bootstr)
print(index) print(index)
} }
dataFiles = map(myfilelist, load)
dat = bind_rows(dataFiles)
diffs <- corXY.bootstr - corXY.perm diffs <- corXY.bootstr - corXY.perm
sign <- apply(diffs, MARGIN=1, function(x){sum(x>0)>190}) sign <- apply(diffs, MARGIN=1, function(x){sum(x>0)>190})
sign <- data.frame(Trait.comb=names(sign), sign=sign) sign <- data.frame(Trait.comb=names(sign), sign=sign)
...@@ -293,8 +298,7 @@ ggplot(data=mydata) + ...@@ -293,8 +298,7 @@ ggplot(data=mydata) +
traits.sign <- traits %>% traits.sign <- traits %>%
rownames_to_column("species0") %>% dplyr::select(species0, traits.sign.alone)
dplyr::select(traits.sign.alone)
write_delim(traits.sign, path="_data/Mesobromion/traits.out.10perc.sign.txt", delim="\t") write_delim(traits.sign, path="_data/Mesobromion/traits.out.10perc.sign.txt", delim="\t")
break() break()
......
...@@ -47,8 +47,7 @@ get.corXY <- function(comm, traits, trait.sel="all", stat=c("mantel", "RV", "pro ...@@ -47,8 +47,7 @@ get.corXY <- function(comm, traits, trait.sel="all", stat=c("mantel", "RV", "pro
} }
### Cor XY bootstrap #### Function 1b - CorXY bootstrap####
#### Function 1 - CorXY ####
get.corXY.bootstrap <- function(comm, traits, trait.sel="all", stat="RV", bootstrap=199){ get.corXY.bootstrap <- function(comm, traits, trait.sel="all", stat="RV", bootstrap=199){
if(identical(trait.sel, "all")) {trait.sel <- 1:ncol(traits)} if(identical(trait.sel, "all")) {trait.sel <- 1:ncol(traits)}
ii <- trait.sel ii <- trait.sel
...@@ -77,6 +76,7 @@ get.corXY.bootstrap <- function(comm, traits, trait.sel="all", stat="RV", bootst ...@@ -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)}) index.bootstr <- lapply(1:bootstrap, function(x){sample(1:n.sites, replace=T)})
for(b in 1:bootstrap){ for(b in 1:bootstrap){
RV.tmp <- RV.rtest(W.beals[index.bootstr[[b]],], as.data.frame(syn.out.tmp)[index.bootstr[[b]],]) 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]],]) RV.perm.tmp <- RV.rtest(W.beals[index.bootstr[[b]],], as.data.frame(syn.out.perm.tmp)[index.bootstr[[b]],])
corXY <- rbind(corXY, 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)) data.frame(Trait.comb=lab.tmp, bootstr.n=b, Test="RV", Coef.obs=RV.tmp$obs, Coef.perm=RV.perm.tmp$obs))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment