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

Fixed bug on exclusion of species without traits

parent 32cd730d
No related branches found
No related tags found
No related merge requests found
...@@ -41,13 +41,14 @@ get.corXY.bootstrap <- function(comm, traits, trait.sel="all", bootstrap=199){ ...@@ -41,13 +41,14 @@ get.corXY.bootstrap <- function(comm, traits, trait.sel="all", bootstrap=199){
W.beals <- as.data.frame(beals(comm, include=T, type=2)) 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
ids <- 1:nrow(traits) traits.ii <- traits[,ii, drop=F]
id.nas <- ids[which(rowSums(is.na(traits))>0)] ids <- 1:nrow(traits.ii)
id.nas <- ids[which(rowSums(is.na(traits.ii))==ncol(traits.ii))]
toresample <- ids[!ids %in% id.nas] toresample <- ids[!ids %in% id.nas]
## create list of indices of permuted traits, but without shuffling traits with missing data ## create list of indices of permuted traits, but without shuffling traits with missing data
## the length of the list is = to the number of bootstraps ## the length of the list is = to the number of bootstraps
index.traits <- lapply(1:(bootstrap+1), function(x){ index.traits <- lapply(1:(bootstrap+1), function(x){
out <- rep(NA, nrow(traits)) out <- rep(NA, nrow(traits.ii))
out[id.nas] <- id.nas out[id.nas] <- id.nas
out[is.na(out)] <- sample(toresample, replace=F) out[is.na(out)] <- sample(toresample, replace=F)
return(out) return(out)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment