This vignette is aimed to give you a high-level overview of the types of models supported by the galamm package, and to point you to relevant vignettes where you can find more information.
Generalized Additive Latent and Mixed Models
Generalized additive latent and mixed models (GALAMMs) (Sørensen, Fjell, and Walhovd 2023) is an extension of generalized linear latent and mixed models (GLLAMMs) (Rabe-Hesketh, Skrondal, and Pickles 2004; Skrondal and Rabe-Hesketh 2004) which allows both observed responses and latent variables to depend smoothly on observed variables. Smoothly here means that the relationship is not assumed to follow a particular parametric form, e.g., as specified by a linear model. Instead, an a priori assumption is made that the relationship is smooth, and the model then attempts to learn the relationship from the data. GALAMM uses smoothing splines to obtain this, identically to how generalized additive models (GAMs) (Wood 2017) are estimated.
The GLLAMM framework contains many elements which are currently not implemented in the galamm package. This includes both nonparametric random effects and a large number of model families, e.g., for censored responses. If you need any of this, but not semiparametric estimation, the Stata based GLLAMM package is likely the place you should go. Conversely, galamm incorporates crossed random effects easily and efficiently, while these are hard to specify using GLLAMM.
Response Model
GALAMMs are specified using three building blocks. First, responses are assumed independently distributed according to an exponential family with density
here is the mean, is the inverse of link function , is a “nonlinear predictor”, is a dispersion parameter, and and are known functions. In contrast to what is assumed, e.g., by lme4 (Bates et al. 2015), the functions , , and are allowed to vary between observations. That is, the observations can come from different members of the exponential family. The vignette on models with mixed response types describes this in detail.
Using canonical link functions, the response model simplifies to
Nonlinear Predictor
Next, the nonlinear predictor, which corresponds to the measurement model in a classical structural equation model, is defined by
where are explanatory variables, , are smooth functions, are latent variables varying at level , and is the weighted sum of a vector of explanatory variables varying at level and parameters . Let
be the vector of all latent variables at level , and
the vector of all latent variables belonging to a given level-2 unit, where . The word “level” is here used to denote a grouping level; they are not necessarily hierarchical.
Structural Model
The structural model specifies how the latent variables are related to each other and to observed variables, and is given by
where is an matrix of regression coefficients for regression among latent variables and is a vector of predictors for the latent variables. is a vector of smooth functions whose components are vectors of functions predicting the latent variables varying at level , and depending on a subset of the elements . is a vector of normally distributed random effects, for , where is the covariance matrix of random effects at level . Defining the covariance matrix , we also have .
Mixed Model Representation
In Sørensen, Fjell, and Walhovd (2023) we show that any model specified as above can be transformed to a GLLAMM, which is essentially a generalized nonlinear mixed model. This transformation is rather complex, so we won’t spell it out here, but the key steps are:
- Converting smooth terms to their mixed model form.
- Estimate the resulting GLLAMM.
- Convert back to the original parametrization.
In galamm we use the same transformations as the gamm4 package does.
Maximum Marginal Likelihood Estimation
In mixed model representation, the nonlinear predictor can be written on the form
where is the regression matrix for fixed effects and is the regression matrix for random effects . In contrast to with generalized linear mixed models, however, both matrices will in general depend on factor loadings and regression coefficients between latent variables . Both of these are parameters that need to be estimated, and hence and and need to be updated throughout the estimation process.
Evaluating the Marginal Likelihood
Plugging the nonlinear predictor into the structural model, we obtain the joint likelihood for the model. We then obtain the marginal likelihood by integrating over the random effects, yielding a marginal likelihood function of the form
where is a standardized version of . In order to evaluate the marginal likelihood at a given set of parameter values, we use the Laplace approximation combined with sparse matrix operations, extending Bates et al. (2015)’s algorithm for linear mixed models.
Maximizing the Marginal Likelihood
We obtain maximum marginal likelihood estimates by maximizing
,
subject to possible constraints, e.g., that variances are non-negative.
For this, we use the L-BFGS-B algorithm implement in
stats::optim
. The predicted values of random effects,
are obtained as posterior modes at the final estimates.
Example Models
To see how galamm is used in practice, take a look at the vignettes describing models with different components.
- Linear mixed models with factor structures.
- Generalized linear mixed models with factor structures.
- Linear mixed models with heteroscedastic residuals.
- Models with interactions between latent and observed covariates.
- Mixed models with mixed response types.
- Generalized additive mixed models with factor structures.