glmmTMB
is an R package for fitting generalized linear
mixed models (GLMMs) and extensions, built on Template Model Builder, which
is in turn built on CppAD and Eigen. It is intended to handle a wide
range of statistical distributions (Gaussian, Poisson, binomial,
negative binomial, Beta …) and zero-inflation. Fixed and random effects
models can be specified for the conditional and zero-inflated components
of the model, as well as fixed effects for the dispersion parameter.
glmmTMB
usage
and mixed models (please subscribe
to the list before posting)Please do not cross-post, i.e. ask the same question in more than one forum, unless it’s suggested that you have posted in the wrong place, or unless you receive total silence in one forum. In the latter case it may be better to send a reminder/“bump” message to the original forum; in any case you should mention in your new message where/when you’ve previously asked the question.
See here for the development site.
install.packages("glmmTMB")
. (On Windows and MacOS this
will install binary packages, by default: see below for installation
from source and why you might want to do that.)install.packages()
to install the TMB
and
remotes
packages from CRAN, then
remotes::install_github("glmmTMB/glmmTMB/glmmTMB")
. If the
install fails at the vignette-building step, try specifying
build_vignettes=FALSE
within the
install_github
call. You will need to have development
tools (compilers etc.) installed: see here
or here.
(As well as being more up-to-date, the development version may contain
new bugs or untested features!)glmmTMB
should be run on a system with the same version
of TMB
installed that was originally used to build the
package; TMB
and Matrix
have a similar
dependency. If you update your system with binary versions of the
TMB
or Matrix
packages from CRAN that are
newer than the version of glmmTMB on CRAN, you’ll get warnings
or error messages.
You can:
Matrix
> TMB
>
glmmTMB
stack from source (this is slight
overkill, you might not need to re-install the whole stack, but it
doesn’t hurt):
gfortran
).install.packages("Matrix")
: this should install the
latest version of Matrix
install.packages("TMB", type = "source")
- this
installs the latest version of TMB
in a way that is
binary-compatible with the latest Matrixinstall.packages("glmmTMB", type = "source")
- this
installs the latest version of glmmTMB
in a way that is
binary-compatible with the latest TMBhttp://glmmtmb.github.io/glmmTMB/repos/bin/[OS]/contrib/[R_version]/PACKAGES
,
where [OS] is “macosx” or “windows”, and [R_version] is the
major version of R you’re using (e.g. 4.1). See “install
development version from GitHub, binary” above. (Windows and MacOS
binaries of TMB built with newer versions of the Matrix
package may be available here as well. Try:
install.packages("TMB", repos="https://glmmTMB.github.io/glmmTMB/repos")
.)Matrix
, TMB
, and
glmmTMB
from a date when they were consistent with each
other:(note: this recipe is not well tested … if you try it and encounter problems, please post an issue)
## load (installing if necessary) the groundhog package
while (!require("groundhog", quietly=TRUE)) install.packages("groundhog")
## retrieve build date of installed version of glmmTMB
bd1 <- as.character(asDateBuilt(packageDescription("glmmTMB",fields="Built")))
groundhog.library("TMB", bd1)
bd2 <- as.character(asDateBuilt(packageDescription("TMB",fields="Built")))
groundhog.library("Matrix", bd2)
The only disadvantage to this approach is that your versions of
TMB
and Matrix
will be behind the version on
CRAN; you might be missing out on some bug fixes or improvements, and
eventually you may find that updates of other packages require newer
versions of these packages. (If you accidentally update the packages
from CRAN, you’ll have to redo this step.) - Install older versions of
TMB
and/or Matrix
from CRAN, from
source using
remotes::install_version("[pkg]","[xxxx]")
, where
[pkg]
is TMB or Matrix and [xxxx]
is the older
package version referred to in the first error message you received.
This section and the next may become outdated as new versions of operating systems are released; please notify the maintainers if you run into trouble.
glmmTMB
enables parallel (threaded) computations based
on OpenMP
(see the parallel vignette for more
information). OpenMP will be available automatically if your system
supports it, but this may depend on the details of your operating
system, compiler, compilation flags used when your R executable was
built, etc.; in particular, see here
for tips on enabling OpenMP for older (<= El Capitan/10.11.4) MacOS
systems. (That page suggests using optimization level -O3
,
which may cause
problems for glmmTMB.)
The maximum number of threads used defaults to 48; to increase this value when installing from source, you can use
withr::with_makevars(c(PKG_CPPFLAGS="-DCPPAD_MAX_NUM_THREADS=128"), {
remotes::install_github("glmmTMB/glmmTMB/glmmTMB")
}, assignment="+="
)
(or the equivalent for remotes::install_cran()
).
library not found for -lgfortran
or
library not found for -lquadmath
you may need to follow these
instructions to update your Fortran compilers.unsupported option '-fopenmp'
you need to turn off OpenMP
compilation by adding the line SHLIB_OPENMP_CFLAGS=
to your
~/.R/Makevars
file. If you’ve already done step #1 this
file will already exist; use a text editor to add the line above.
Otherwise, you need to create it.After updating your compilers (if necessary) and turning off OpenMP compilation, re-try the installation from source.