From 5d8a58e196afde89f100230360a7a65c4c3fae90 Mon Sep 17 00:00:00 2001 From: Francesco Sabatini <francesco.sabatini@idiv.de> Date: Wed, 22 Apr 2020 18:53:48 +0200 Subject: [PATCH] Adjusted get.corXY.bootstrap to account for asymmetric binary traits in FD:gowdis --- 99_HIDDEN_functions.R | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/99_HIDDEN_functions.R b/99_HIDDEN_functions.R index 7d5580d..0f7dfce 100644 --- a/99_HIDDEN_functions.R +++ b/99_HIDDEN_functions.R @@ -50,6 +50,11 @@ get.corXY <- function(comm, traits, trait.sel="all", stat=c("mantel", "RV", "pro #### Function 1b - CorXY bootstrap#### 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 + binary.traits <- which( (traits %>% summarize_all(is.bin)) ==T) + if(identical(trait.sel, "all")) {trait.sel <- 1:ncol(traits)} ii <- trait.sel lab.tmp <- paste(ii, collapse="_") @@ -62,7 +67,7 @@ get.corXY.bootstrap <- function(comm, traits, trait.sel="all", bootstrap=199){ #Calculate correlations on full data n.sites <- nrow(comm) n.species <- ncol(comm) - syn.out.tmp <- matrix.x(comm=comm, traits=traits[,ii,drop=F], scale=T)$matrix.X + syn.out.tmp <- matrix.x(comm=comm, traits=traits[,ii,drop=F], scale=T, asym.bin=binary.traits)$matrix.X W.beals <- as.data.frame(beals(comm, include=T, type=2)) # permtute traits index.traits <- lapply(1:(bootstrap+1), function(x){sample(1:n.species, replace=F)}) @@ -81,7 +86,8 @@ get.corXY.bootstrap <- function(comm, traits, trait.sel="all", bootstrap=199){ for(b in 1:bootstrap){ #RV.tmp <- RV.rtest(W.beals[index.bootstr[[b]],], as.data.frame(syn.out.tmp)[index.bootstr[[b]],]) 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[index.traits[[bootstrap]],ii,drop=F], scale=T)$matrix.X + syn.out.perm.tmp <- matrix.x(comm=comm, traits=traits[index.traits[[bootstrap]],ii,drop=F], + scale=T, asym.bin=binary.traits)$matrix.X #RV.perm.tmp <- RV.rtest(W.beals[index.bootstr[[b]],], as.data.frame(syn.out.perm.tmp)[index.bootstr[[b]],]) RD.perm.tmp <- dcor(W.beals[index.bootstr[[b]],], as.data.frame(syn.out.perm.tmp)[index.bootstr[[b]],])^2 corXY <- rbind(corXY, @@ -210,4 +216,7 @@ get.SES <- function(obs.df, perm.df, stat="RV") { +## Cracked version of matrix.x from SYNCSA to account for asymmetric binary variables in gowdis + + -- GitLab