It all started with this paper in Methods in Ecol. Evol. where we looked at detectability of many species. So we wanted to use life history traits to validate our results. But we had to cut the manuscript, and there was this leftover with some neat patterns, but without much focus. It took a few years, and the most positive peer-review experience ever, and the paper is now early view in Ecography. This post is a quick summary of the goodies stuffed inside the lhreg R package that makes the whole analysis reproducible, and provides some functions for similar PGLMM models.
The R package is hosted on GitHub
(no CRAN version yet),
please submit any issues here.
The package is also archived on Zenodo with DOI 10.5281/zenodo.596410.
To install the package, use
Here, I am going to skim the implementation based on the more
complete supporting information of the paper which has all the
reproducible code (try
vignette(topic = "lhreg", package = "lhreg") after
installing and loading the package).
Here is the rendered html version.
The most important function is
lhreg which takes the following main arguments:
Y: response vector,
X: model matrix for the mean.
SE: standard error estimate (observation error) for the response,
V: correlation matrix,
and fits a Multivariate Normal model to the observed
with phylogenetically based (or any other known) correlations
and optionally with observation error (
SE), and covariate effects (
The function is pretty bare-bones (i.e. no formula interface,
the design matrix
X needs to be properly specified through
is a non-negative number modifying the strength of phylogenetic effects.
lambda = 0 is equivalent to
weights = 1/(SE^2),
lambda = 1 implies Brownian motion evolution,
lambda = NA lets the function estimate it based on the data.
In terms of optimization, besides the algorithms from
we also have differential evolution algorithm based on the
DEoptim package (a bit time consuming but very reliable).
The output object class has some methods defined (like
and as a result AIC/BIC will work out of the box. The vignette also
describes a few techniques which are pretty nice to have in
a multivariate setting (i.e. profile likelihood, parametric bootstrap)
to support advanced hypothesis testing and model selection.
We used leave one out cross-validation to see how well we could predict the
values based on data from the other species, traits and phylogeny.
The conditional distribution we used for that is described in the paper which
made this exercise very straightforward.
Maybe it is just ignorance, but I couldn’t find another paper
that would have described it in a nice and useful manner,
however, if one wishes to make trait/phylogeny based
predictions for detectability, this formula is going to be
very useful (look inside the
loo2 function for implementation).
At the end of the vignette, there is a hack based on
function to produce non-rainbow colors.
(It was surprisingly non-straightforward to hack the code —
modular code please!)
The following figure shows the two input data vectors mirrored side-by-side:
I realize this is not a very detailed post, but the paper and the vignette should satisfy your curiosity. If you still have unanswered questions, feel free to ask them below!
In a recent paper entitled “Lessons learned from comparing spatially explicit models and the Partners in Flight approach to estimate population sizes of boreal birds in Alberta, Canada” we developed improved, spatially explicit models for 81 land bird species in northern Alberta, Canada. We then compared these estimates of bird abundance to a commonly-used but non-spatially explicit estimate by Partners in Flight (PIF v 3.0) that’s based on the North American Breeding Bird Survey (BBS) data set. The publication is a result of years of collaboration between the ABMI, Boreal Avian Modelling (BAM) project, Canadian Wildlife Service (Environment and Climate Change Canada), and United States Geological Survey.
ABMI (7) ARU (1) Alberta (1) BAM (1) C (1) CRAN (1) Hungary (2) JOSM (2) PVA (2) PVAClone (1) QPAD (3) R (20) R packages (1) abundance (1) bioacoustics (1) biodiversity (1) birds (2) course (2) data (1) data cloning (4) dclone (3) density (1) dependencies (1) detect (3) detectability (3) footprint (3) forecasting (1) functions (3) intrval (4) lhreg (1) mefa4 (1) monitoring (2) pbapply (5) phylogeny (1) plyr (1) poster (2) processing time (2) progress bar (4) publications (2) report (1) sector effects (1) shiny (1) single visit (1) site (1) slider (1) slides (2) special (3) species (1) trend (1) tutorials (2) video (4)