When trying to design single-trait environmental filter with a species pool with multiple traits I struggled to understand how to define the filt() function:
library("ecolottery")
# Define a regional pool of species with equal abundances
pool <- cbind(1:10000, rep(1:500, 20), rep(NA, 10000), rep(NA, 10000))
# Uniform distribution of trait values
t.sp <- runif(500)
t2.sp <- runif(500)
# No intraspecific variation
pool[,3] <- t.sp[pool[,2]]
pool[,4] <- t2.sp[pool[,2]]
# Bad environmental filtering function
# (it does not specify which x to use)
bad_filt <- function(x) exp(-(x - 0.2)^2/(2*0.1^2))
# Generate a community drawn from the pool with environmental filtering
comm2 <- coalesc(J = 500, m = 1, pool = pool, filt = bad_filt)
#> Error in sample.int(length(x), size, replace, prob): nombre de probabilités incorrect
# Good environmental filtering function
# (it specifies which x to use)
good_filt <- function(x) exp(-(x[1] - 0.2)^2/(2*0.1^2))
# Generate a community drawn from the pool with environmental filtering
comm2 <- coalesc(J = 500, m = 1, pool = pool, filt = good_filt)
We could add a specific section in the documentation that shows example of a single-trait filter when there are several traits. We should note that filt() functions always take a single trait argument that is a vector of all available traits.
When trying to design single-trait environmental filter with a species pool with multiple traits I struggled to understand how to define the
filt()
function:We could add a specific section in the documentation that shows example of a single-trait filter when there are several traits. We should note that filt() functions always take a single trait argument that is a vector of all available traits.
Created on 2019-04-17 by the reprex package (v0.2.1)
Session info
``` r devtools::session_info() #> - Session info ---------------------------------------------------------- #> setting value #> version R version 3.5.3 (2019-03-11) #> os Windows 8.1 x64 #> system x86_64, mingw32 #> ui RTerm #> language (EN) #> collate French_France.1252 #> ctype French_France.1252 #> tz Europe/Paris #> date 2019-04-17 #> #> - Packages -------------------------------------------------------------- #> package * version date lib #> abc 2.1 2015-05-05 [1] #> abc.data 1.0 2015-05-05 [1] #> assertthat 0.2.1 2019-03-21 [1] #> backports 1.1.4 2019-04-10 [1] #> callr 3.2.0 2019-03-15 [1] #> cli 1.1.0 2019-03-19 [1] #> colorspace 1.4-1 2019-03-18 [1] #> crayon 1.3.4 2017-09-16 [1] #> desc 1.2.0 2018-05-01 [1] #> devtools 2.0.2 2019-04-08 [1] #> digest 0.6.18 2018-10-10 [1] #> dplyr 0.8.0.1 2019-02-15 [1] #> ecolottery * 1.2.0 2019-04-16 [1] #> evaluate 0.13 2019-02-12 [1] #> fs 1.2.7 2019-03-19 [1] #> ggplot2 3.1.1 2019-04-07 [1] #> glue 1.3.1 2019-03-12 [1] #> gtable 0.3.0 2019-03-25 [1] #> highr 0.8 2019-03-20 [1] #> htmltools 0.3.6 2017-04-28 [1] #> knitr 1.22 2019-03-08 [1] #> lattice 0.20-38 2018-11-04 [1] #> lazyeval 0.2.2 2019-03-15 [1] #> locfit 1.5-9.1 2013-04-20 [1] #> magrittr 1.5 2014-11-22 [1] #> MASS 7.3-51.3 2019-03-31 [1] #> Matrix 1.2-17 2019-03-22 [1] #> MatrixModels 0.4-1 2015-08-22 [1] #> memoise 1.1.0 2017-04-21 [1] #> munsell 0.5.0 2018-06-12 [1] #> nnet 7.3-12 2016-02-02 [1] #> pillar 1.3.1 2018-12-15 [1] #> pkgbuild 1.0.3 2019-03-20 [1] #> pkgconfig 2.0.2 2018-08-16 [1] #> pkgload 1.0.2 2018-10-29 [1] #> plyr 1.8.4 2016-06-08 [1] #> prettyunits 1.0.2 2015-07-13 [1] #> processx 3.3.0 2019-03-10 [1] #> ps 1.3.0 2018-12-21 [1] #> purrr 0.3.2 2019-03-15 [1] #> quantreg 5.38 2018-12-18 [1] #> R6 2.4.0 2019-02-14 [1] #> Rcpp 1.0.1 2019-03-17 [1] #> remotes 2.0.4 2019-04-10 [1] #> rlang 0.3.4 2019-04-07 [1] #> rmarkdown 1.12 2019-03-14 [1] #> rprojroot 1.3-2 2018-01-03 [1] #> scales 1.0.0 2018-08-09 [1] #> sessioninfo 1.1.1 2018-11-05 [1] #> SparseM 1.77 2017-04-23 [1] #> stringi 1.4.3 2019-03-12 [1] #> stringr 1.4.0 2019-02-10 [1] #> testthat 2.0.1 2018-10-13 [1] #> tibble 2.1.1 2019-03-16 [1] #> tidyselect 0.2.5 2018-10-11 [1] #> usethis 1.5.0 2019-04-07 [1] #> withr 2.1.2.9000 2018-11-19 [1] #> xfun 0.6 2019-04-02 [1] #> yaml 2.2.0 2018-07-25 [1] #> source #> CRAN (R 3.5.0) #> CRAN (R 3.5.0) #> CRAN (R 3.5.2) #> CRAN (R 3.5.3) #> CRAN (R 3.5.3) #> CRAN (R 3.5.2) #> CRAN (R 3.5.2) #> CRAN (R 3.5.0) #> CRAN (R 3.5.0) #> CRAN (R 3.5.3) #> CRAN (R 3.5.1) #> CRAN (R 3.5.2) #> Github (frmunoz/ecolottery@afb861d) #> CRAN (R 3.5.1) #> CRAN (R 3.5.3) #> CRAN (R 3.5.3) #> CRAN (R 3.5.2) #> CRAN (R 3.5.2) #> CRAN (R 3.5.2) #> CRAN (R 3.5.0) #> CRAN (R 3.5.2) #> CRAN (R 3.5.3) #> CRAN (R 3.5.3) #> CRAN (R 3.5.0) #> CRAN (R 3.5.0) #> CRAN (R 3.5.3) #> CRAN (R 3.5.3) #> CRAN (R 3.5.0) #> CRAN (R 3.5.0) #> CRAN (R 3.5.0) #> CRAN (R 3.5.3) #> CRAN (R 3.5.1) #> CRAN (R 3.5.2) #> CRAN (R 3.5.1) #> CRAN (R 3.5.1) #> CRAN (R 3.5.0) #> CRAN (R 3.5.0) #> CRAN (R 3.5.2) #> CRAN (R 3.5.2) #> CRAN (R 3.5.3) #> CRAN (R 3.5.1) #> CRAN (R 3.5.1) #> CRAN (R 3.5.3) #> CRAN (R 3.5.3) #> CRAN (R 3.5.3) #> CRAN (R 3.5.2) #> CRAN (R 3.5.0) #> CRAN (R 3.5.0) #> CRAN (R 3.5.1) #> CRAN (R 3.5.0) #> CRAN (R 3.5.3) #> CRAN (R 3.5.2) #> CRAN (R 3.5.1) #> CRAN (R 3.5.3) #> CRAN (R 3.5.1) #> CRAN (R 3.5.3) #> Github (jimhester/withr@be57595) #> CRAN (R 3.5.2) #> CRAN (R 3.5.1) #> #> [1] C:/Users/grenie/Documents/R/R-3.5.3/library ```