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

Fixed bug for asym.bin

parent c4745830
No related branches found
No related tags found
No related merge requests found
...@@ -50,11 +50,6 @@ get.corXY <- function(comm, traits, trait.sel="all", stat=c("mantel", "RV", "pro ...@@ -50,11 +50,6 @@ 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( ~all(na.omit(.) %in% 0:1) )) ==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="_")
...@@ -67,11 +62,18 @@ get.corXY.bootstrap <- function(comm, traits, trait.sel="all", bootstrap=199){ ...@@ -67,11 +62,18 @@ 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)
## 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(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, asym.bin=binary.traits)$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)})
syn.out.perm.tmp <- matrix.x(comm=comm, traits=traits[index.traits[[bootstrap+1]],ii,drop=F], scale=T)$matrix.X syn.out.perm.tmp <- matrix.x(comm=comm, traits=traits[index.traits[[bootstrap+1]],ii,drop=F],
scale=T, asym.bin=binary.traits)$matrix.X
corXY <- NULL corXY <- NULL
#RD.tmp <- RV.rtest(W.beals, as.data.frame(syn.out.tmp), nrepet = 0) #RD.tmp <- RV.rtest(W.beals, as.data.frame(syn.out.tmp), nrepet = 0)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment