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

Undone changes of commit aaaaadf

parent 4fa25d73
Branches
No related tags found
No related merge requests found
...@@ -33,6 +33,12 @@ get.corXY.bootstrap <- function(comm, traits, trait.sel="all", bootstrap=199){ ...@@ -33,6 +33,12 @@ get.corXY.bootstrap <- function(comm, traits, trait.sel="all", bootstrap=199){
## caution ## caution
## ALL columns with only 0-1 values are AUTOMATICALLY considered as asym.bin sensu FD:gowdis ## ALL columns with only 0-1 values are AUTOMATICALLY considered as asym.bin sensu FD:gowdis
##get all columns with binary variables
## CAUTION - function below doesn't work as expected
# binary.traits <- which(apply(traits[,ii,drop=F], MARGIN=2, function(x)( all(na.omit(x) %in% 0:1) ))==T)
syn.out.tmp <- matrix.x(comm=comm, traits=traits[,ii,drop=F], scale=T)$matrix.X #, asym.bin=binary.traits
W.beals <- as.data.frame(beals(comm, include=T, type=2))
# permute traits # permute traits
### Create vector of species to resample from, which exclude species with NAs ### Create vector of species to resample from, which exclude species with NAs
traits.ii <- traits[,ii, drop=F] traits.ii <- traits[,ii, drop=F]
...@@ -47,15 +53,12 @@ get.corXY.bootstrap <- function(comm, traits, trait.sel="all", bootstrap=199){ ...@@ -47,15 +53,12 @@ get.corXY.bootstrap <- function(comm, traits, trait.sel="all", bootstrap=199){
out[is.na(out)] <- sample(toresample, replace=F) out[is.na(out)] <- sample(toresample, replace=F)
return(out) return(out)
}) })
##calculate corXY on observed values using all plots #index.traits <- lapply(1:(bootstrap+1), function(x){sample(1:nrow(traits), replace=F)})
syn.out.tmp <- matrix.x(comm=comm, traits=traits.ii, scale=T)$matrix.X #, asym.bin=binary.traits syn.out.perm.tmp <- matrix.x(comm=comm, traits=traits[index.traits[[bootstrap+1]],ii,drop=F],
W.beals <- as.data.frame(beals(comm, include=T, type=2))
(RD.tmp <- dcor(W.beals, as.data.frame(syn.out.tmp))^2)
##calculate corresponding permuted corXY using all plots
syn.out.perm.tmp <- matrix.x(comm=comm, traits=traits.ii[index.traits[[bootstrap+1]],],
scale=T)$matrix.X #, asym.bin=binary.traits scale=T)$matrix.X #, asym.bin=binary.traits
(RD.tmp <- dcor(W.beals, as.data.frame(syn.out.tmp))^2)
(RD.perm.tmp <- dcor(W.beals, as.data.frame(syn.out.perm.tmp))^2) (RD.perm.tmp <- dcor(W.beals, as.data.frame(syn.out.perm.tmp))^2)
## calculate corXY for each bootstrap run
corXY <- NULL corXY <- NULL
corXY <- data.frame(Trait.comb=lab.tmp, bootstr.n=0, Test="RD", corXY <- data.frame(Trait.comb=lab.tmp, bootstr.n=0, Test="RD",
Coef.obs=RD.tmp, Coef.perm=RD.perm.tmp) Coef.obs=RD.tmp, Coef.perm=RD.perm.tmp)
...@@ -63,7 +66,7 @@ get.corXY.bootstrap <- function(comm, traits, trait.sel="all", bootstrap=199){ ...@@ -63,7 +66,7 @@ get.corXY.bootstrap <- function(comm, traits, trait.sel="all", bootstrap=199){
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){
RD.tmp <- dcor(W.beals[index.bootstr[[b]],], as.data.frame(syn.out.tmp)[index.bootstr[[b]],])^2 RD.tmp <- dcor(W.beals[index.bootstr[[b]],], as.data.frame(syn.out.tmp)[index.bootstr[[b]],])^2
syn.out.perm.tmp <- matrix.x(comm=comm, traits=traits.ii[index.traits[[b]],], syn.out.perm.tmp <- matrix.x(comm=comm, traits=traits[index.traits[[b]],ii,drop=F],
scale=T)$matrix.X #, asym.bin=binary.traits scale=T)$matrix.X #, asym.bin=binary.traits
RD.perm.tmp <- dcor(W.beals[index.bootstr[[b]],], as.data.frame(syn.out.perm.tmp)[index.bootstr[[b]],])^2 RD.perm.tmp <- dcor(W.beals[index.bootstr[[b]],], as.data.frame(syn.out.perm.tmp)[index.bootstr[[b]],])^2
corXY <- rbind(corXY, corXY <- rbind(corXY,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment