Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Clone this wiki locally
Frequently Asked Questions
Question in bold, answer in normal font. Short items only (2-3 lines).
- What is TMB? An R package based on AD (Automatic differentiation) for fitting latent variable models in statistics.
- What can TMB do that R, ADMB and/or INLA cannot? Why should I invest in learning TMB? TMB is strongly inspired by ADMB, but is faster for latent variable models and has better functionality for GMRF models. TMB does not directly provide Bayesian inference, but frequentist style empirical Bayes, using more flexible model formulation than R-INLA.
- How do I teach myself TMB? Start by reading the Tutorial. Courses will be announced as News (under github issues).
- Where can I post questions? Please join the TMB Google group !
- Where can I find good examples and documentation of TMB? Start by reading the Tutorial. Then look through the examples that comes with TMB.
- I'm ready to publish! How do I cite TMB?
For R users
- Is it necessary to have a deep knowledge of C++? No, but you do need some knowledge of C++. The C++ code you write looks very much like R but there are differences between R and C++. Do not expect everything in R to work in C++. You will find differences like indexes for vectors, matrices and arrays starting at 0 in C++ rather than 1. Also, R is much more forgiving about variable typing so make sure your variables for subscripts are integers. There is a brief C++ tutorial in the C++ API.
For ADMB users
ADREPORT and REPORT Equivalent to
sdreport_numberin ADMB, but with one important difference: you should invoke
ADREPORT(x)after you have evaluated
Is there a ragged array? On the R side a ragged array is list of vectors. See variable
- Beware in converting ADMB TPL Files If you are converting an ADMB TPL file to a .cpp file for TMB, use a different base name for the file (eg xx.TPL and xx_tmb.cpp). If you use the same base name and run ADMB, it will overwrite your TMB .cpp file.
Why don't I find docs for standard functions like
cosin the C++ API? These functions are part of CppAD and are not separately documented in TMB. General rule: basic mathematical functions are in CppAD, while probability stuff is part in TMB.
How do I create a new vector from a subset of a vector? E.g., in R I would write
y=x[3:5]. In C++, you could write
segmentfunction and other handy operations are documented in the Eigen quick reference guide.
- Which probability distributions are available? You find a list of available distributions under "R style probability distributions" in the C++ API
How do I choose betweeen models fitted with TMB?
An R function 'AICTMB' to extract the AIC from an optimized model is provided in the 'TMBhelper' contributed package, with download instructions here
For an example of how to do likelihood ratio test look at the example
- Is it possible to extract a DIC value ? There is no special support for doing this in TMB.
- How do I validate a model fitted with TMB (e.g. residual plots)? Residual plots are more difficult in models with latent random variables. Further, in complex hierarchical models, different model components may require their own set of diagnostics. Hence, it is hard to construct general diagnostics techniques in TMB. Examples of special cases may be added in the future.
Install and configure
Why can I not build and run models in Windows, after installing TMB from CRAN? TMB on Windows requires Rtools. The PATH environment variable should point to the Rtools 'make' and 'gcc', and no other instances of 'make' or 'gcc'.
I installed TMB from CRAN and now I get this message on startup:
Warning message: In checkMatrixPackageVersion() : Package version inconsistency detected. TMB was built with Matrix version 126.96.36.199 Current Matrix version is 1.2.6 Please re-install 'TMB' from source or restore original 'Matrix' package
This can be fixed by updating the Matrix package:
I updated TMB and now my old models no longer work. Whenever installing or upgrading the TMB package be sure to remove old .o and .dll files. They are no longer compatible after upgrading. Then try compiling and running the model again.
After updating R on Windows I can no longer compile TMB models. You probably need to update Rtools to the version matching your new R version - see the Rtoools compatibility table.
Can I reduce the size of binary model files (*.so) on Linux? You can add
SHLIB_CXXLD = $(CXX) -Wl,-sto Makevars see