make_matrices: Create model matrices

View source: R/make_mat.R

make_matricesR Documentation

Create model matrices

Description

Create model matrices

Usage

make_matrices(formulas, data, new_data = NULL, gam_args = NULL)

Arguments

formulas

List of formulas (possibly nested, e.g. for use within Observation)

data

Data frame including covariates

new_data

Optional new data set, including covariates for which the design matrices should be created. This needs to be passed in addition to the argument 'data', for cases where smooth terms or factor covariates are included, and the original data set is needed to determine the full range of covariate values.

gam_args

Named list of additional arguments for mgcv::gam(), such as knots.

Details

Note the two indices: ncol_re, log_det_S and gmrf have one entry per penalty, while L, sp_names, sp_gmrf and theta_start have one per smoothing parameter. The two coincide for an ordinary smooth, which has one of each, but an SPDE field has three penalties and two parameters.

Value

A list of

  • X_fe Design matrix for fixed effects

  • X_re Design matrix for random effects

  • S Smoothness matrix

  • log_det_S Vector of log-determinants of smoothness matrices, one for each penalty

  • ncol_fe Number of columns of X_fe for each parameter

  • ncol_re Number of columns of X_re and S for each random effect

  • L Matrix with log(lambda) = L * theta, mapping the smoothing parameters of each smooth to the weights of its penalties (mgcv's convention). It is the identity unless a smooth combines several penalties through fewer parameters. See ?mgcv::smooth.construct for details.

  • gmrf For each penalty, 1 if its log-determinant depends on the parameters and so has to be computed inside the likelihood, and 0 if the penalty is a fixed matrix scaled by exp(theta)

  • sp_names Name of each smoothing parameter

  • theta_start Starting value of each log smoothing parameter


hmmTMB documentation built on Nov. 10, 2026, 5:09 p.m.