From 90679f2ba9e5575e8d22bdcc14d70a36a2659146 Mon Sep 17 00:00:00 2001 From: Francesco Sabatini <francesco.sabatini@idiv.de> Date: Fri, 21 Aug 2020 08:42:10 +0200 Subject: [PATCH] Undone changes of commit aaaaadf --- 99_HIDDEN_functions.R | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/99_HIDDEN_functions.R b/99_HIDDEN_functions.R index cb45b92..c5c919a 100644 --- a/99_HIDDEN_functions.R +++ b/99_HIDDEN_functions.R @@ -33,6 +33,12 @@ get.corXY.bootstrap <- function(comm, traits, trait.sel="all", bootstrap=199){ ## caution ## 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 ### Create vector of species to resample from, which exclude species with NAs traits.ii <- traits[,ii, drop=F] @@ -47,15 +53,12 @@ get.corXY.bootstrap <- function(comm, traits, trait.sel="all", bootstrap=199){ out[is.na(out)] <- sample(toresample, replace=F) return(out) }) - ##calculate corXY on observed values using all plots - syn.out.tmp <- matrix.x(comm=comm, traits=traits.ii, scale=T)$matrix.X #, asym.bin=binary.traits - 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]],], + #index.traits <- lapply(1:(bootstrap+1), function(x){sample(1:nrow(traits), replace=F)}) + syn.out.perm.tmp <- matrix.x(comm=comm, traits=traits[index.traits[[bootstrap+1]],ii,drop=F], 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) - ## calculate corXY for each bootstrap run corXY <- NULL corXY <- data.frame(Trait.comb=lab.tmp, bootstr.n=0, Test="RD", Coef.obs=RD.tmp, Coef.perm=RD.perm.tmp) @@ -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)}) for(b in 1:bootstrap){ 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 RD.perm.tmp <- dcor(W.beals[index.bootstr[[b]],], as.data.frame(syn.out.perm.tmp)[index.bootstr[[b]],])^2 corXY <- rbind(corXY, -- GitLab