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

Adjusted get.corXY.bootstrap to account for asymmetric binary traits in FD:gowdis

parent 6ac780f0
No related branches found
No related tags found
No related merge requests found
...@@ -50,6 +50,11 @@ get.corXY <- function(comm, traits, trait.sel="all", stat=c("mantel", "RV", "pro ...@@ -50,6 +50,11 @@ get.corXY <- function(comm, traits, trait.sel="all", stat=c("mantel", "RV", "pro
#### Function 1b - CorXY bootstrap#### #### Function 1b - CorXY bootstrap####
get.corXY.bootstrap <- function(comm, traits, trait.sel="all", bootstrap=199){ 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)} if(identical(trait.sel, "all")) {trait.sel <- 1:ncol(traits)}
ii <- trait.sel ii <- trait.sel
lab.tmp <- paste(ii, collapse="_") lab.tmp <- paste(ii, collapse="_")
...@@ -62,7 +67,7 @@ get.corXY.bootstrap <- function(comm, traits, trait.sel="all", bootstrap=199){ ...@@ -62,7 +67,7 @@ get.corXY.bootstrap <- function(comm, traits, trait.sel="all", bootstrap=199){
#Calculate correlations on full data #Calculate correlations on full data
n.sites <- nrow(comm) n.sites <- nrow(comm)
n.species <- ncol(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)) W.beals <- as.data.frame(beals(comm, include=T, type=2))
# permtute traits # permtute traits
index.traits <- lapply(1:(bootstrap+1), function(x){sample(1:n.species, replace=F)}) 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){ ...@@ -81,7 +86,8 @@ get.corXY.bootstrap <- function(comm, traits, trait.sel="all", bootstrap=199){
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]],])
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[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]],]) #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 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,
...@@ -210,4 +216,7 @@ get.SES <- function(obs.df, perm.df, stat="RV") { ...@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment