logLik.tramME: Get the log-likelihood of the tramME model

View source: R/methods.R

logLik.tramMER Documentation

Get the log-likelihood of the tramME model

Description

Evaluates the log-likelihood function. New parameter values and data can optionally be supplied. In the latter case, the function returns the out-of-sample log-likelihood.

Usage

## S3 method for class 'tramME'
logLik(
  object,
  param = NULL,
  newdata = NULL,
  type = c("integrated", "fix_smooth", "penalized"),
  ...
)

Arguments

object

A tramME object.

param

An optional named list of parameter values (beta and theta). See details. Optionally, gamma elements can also be added, which leads to 'fixing' those random effects terms at the supplied values.

newdata

An optional data.frame to calculate the out-of-sample log-likelihood.

type

The type of the likelihood to be calculated:

  • integrated (default when newdata = NULL): The marginal log-likelihood, calculated by integrating out the random effects.

  • fix_smooth (default when newdata is supplied): Treating the penalized parameters of the smooth terms as fixed at their posterior mode predictions and only integrating out the 'true' random effects. (Consistent with the functionality of ranef.tramME and residuals.tramME when fix_smooth = TRUE.)

  • penalized: Treat all parameters as fixed, return the penalized log-likelihood (conditional log-likelihood + penalty for smooth terms and random effects). This is equivalent to fixing all random effect values.

See details.

...

Optional argument (for consistency with generic).

Details

By default, param is set to the estimated (or previously set) parameters. If the parameter vectors in the model are incomplete (contain NA elemets), the returned log-likelihood will also be NA, unless the user provides new values.

Setting type = "fix_smooth" fixes the random effects terms that correspond to penalized smooths at their estimated values, so that they are not refitted when newdata is supplied. This is consistent with treating these parameter regularized fixed terms, i.e. as 'new-style' random effects described by Hodges (2014, Chapter 13).

The "fix_smooth" and "penalized" options for type are just for convenience. The same functionality can be achieved by setting param$gamma to the desired values. "penalized" respects the values of param$gamma if both are supplied, while "fix_smooth" overwrites them with the fitted values if there are ambiguities.

Value

A numeric value of the log-likelihood.

Type of the log-likelihood

By default, logLik calculates the _integrated_ (or marginal) log-likelihood by integrating over the random effects. By fixing the random effects, the value of the log-likelihood changes, because TMB won't integrate over these random effects. This will result in the _penalized_ log-likelihood (conditional log-likelihood + penalty for smooth terms and random effects, see example).

By setting type = "penalized", the function will 'fix' all random effects and penalized parameters of the smooth terms at their predicted levels, and calcualte the penalized log-likelihood. In this sense, setting type = "fix_smooth" will result in a hybrid log-likelihood value, where the 'true' random effects (c.f. Hodges 2014, Ch. 13) are integrated out, while it includes the penalty values for the penalized parameters of the smooths terms.

In general, it is not clear which type of log-likelihood we should calculate when we want to evaluate models based on their out-of-sample log-likelihood values. The context and the model setup are key in these cases. Please make sure you know what you want to calculate to avoid misunderstandings.

References

Hodges, James S. (2014). Richly Parameterized Linear Models: Additive, Time Series, and Spatial Models Using Random Effects. Chapman & Hall/CRC Texts in Statistical Science Series.

Examples


data("sleepstudy", package = "lme4")
fit <- LmME(Reaction ~ Days + (Days | Subject), data = sleepstudy)
logLik(fit)

data("mcycle", package = "MASS")
fit <- LmME(accel ~ s(times), data = mcycle)
logLik(fit) < logLik(fit, type = "penalized")


tramME documentation built on July 9, 2023, 7:10 p.m.