Spatial and spatiotemporal GLMMs with TMB
sdmTMB is an R package that implements spatial and spatiotemporal predictive-process GLMMs (Generalized Linear Mixed Effects Models) using Template Model Builder (TMB), R-INLA, and Gaussian Markov random fields. One common application is for species distribution models (SDMs).
Assuming you have a C++ compiler installed, you can install sdmTMB:
# install.packages("remotes") remotes::install_github("pbs-assess/sdmTMB")
formula = y ~ 1 + x1 + (1 | g), time_varying = ~ 0 + x2), where
yis the response,
1represents an intercept,
0omits an intercept,
x1is a covariate with a constant effect,
(1 | g)is a random intercept across groups
x2is a covariate with a time-varying effect.
y ~ s(x).
y ~ breakpt(x1)or
y ~ logistic(x2).
family(link)format similar to
glm(), lme4, or glmmTMB. This includes Gaussian, Poisson, negative binomial, gamma, binomial, lognormal, Student-t, and Tweedie distributions with identity, log, inverse, and logit links. E.g.,
family = tweedie(link = "log").
residuals()methods. The residuals are randomized-quantile residuals similar to those implemented in the DHARMa package. The
predict()function can take a
newdataargument similar to
glm()etc. The predictions are bilinear interpolated predictive-process predictions (i.e., they make smooth pretty maps).
sdmTMB_sim()for simulation testing models and
sdmTMB_cv()for cross-validation testing of model accuracy or comparing across model configurations.