First read the Statistical Modelling section of Tutorial.
9.0.1 Non-normal latent variables (random effects)
The underlying latent random variables in TMB must be Gaussian for the
Laplace approximation to be accurate. To obtain other distributions,
say a gamma distribution, the “transformation trick” can be used. We
start out with normally distributed variables
u and transform these
into new variables
w via the
qgamma functions as
w now has a gamma distribution.
9.0.2 Discrete latent variables
The Laplace approximation can not be applied to discrete latent variables that occur in mixture models and HMMs (Hidden Markov models). However, such likelihoods have analytic expressions, and may be coded up in TMB. TMB would still calculate the exact gradient of the HMM likelihood.
9.0.3 Mixture models
Although mixture models are a special case of discrete latent variable models, they do deserve special attention. Consider the case that we want a mixture of two zero-mean normal distributions (with different standard deviations). This can be implemented as:
9.0.4 Time series
Autoregressive (AR) processes may be implemented using the compact notation of section Densities. The resulting AR process may be applied both in the observational part and in the distribution of a latent variable.
Nonlinear time must be implemented from scratch, as in the example thetalog.cpp