Skip to contents

This function computes the Laplace approximate marginal likelihood.

Usage

marginal_likelihood(
  y,
  trials = NULL,
  X,
  Zt,
  Lambdat,
  beta,
  theta,
  theta_mapping,
  u_init = rep(0, nrow(Zt)),
  lambda = numeric(),
  lambda_mapping_X = integer(),
  lambda_mapping_X_covs = integer(),
  lambda_mapping_Zt = integer(),
  lambda_mapping_Zt_covs = integer(),
  weights = numeric(),
  weights_mapping = integer(),
  family = "gaussian",
  family_mapping = rep(0L, length(y)),
  maxit_conditional_modes = 1L,
  gradient = TRUE,
  hessian = FALSE,
  epsilon_u = 1e-10
)

Arguments

y

A numeric vector of responses.

trials

A numeric vector representing the number of trials. Only used for binomial models, but should be set to some arbitrary value otherwise.

X

A dense numeric matrix.

Zt

A sparse matrix of class dgCMatrix.

Lambdat

A sparse matrix of class dgCMatrix.

beta

A numeric vector of fixed effects.

theta

A numeric vector of variance components, parametrized identically to lme4.

theta_mapping

An integer vector corresponding to Lind used by lme4, but with base zero indexing.

u_init

Initial values from random effects. Defaults to a vector of zeros.

lambda

A numeric vector of factor loadings.

lambda_mapping_X

An integer vector of mappings between X and lambda, columnwise. Should be set to integer() if not used. An entry -1 indicates that the corresponding value of X does not depend on lambda, as in the case where the first element of lambda is fixed to 1.

lambda_mapping_X_covs

Optional list of covariates.

lambda_mapping_Zt

An integer vector of mappings between Zt and lambda, along the nonzero elements of Zt as can be found by Zt@x. Should be set to integer() if not used. An entry -1 indicates that the corresponding value of X does not depend on lambda, as in the case where the first element of lambda is fixed to 1.

lambda_mapping_Zt_covs

Optional list of covariates.

weights

Vector of weights.

weights_mapping

Mapping

family

A length one character denoting the family.

family_mapping

Mapping

maxit_conditional_modes

Maximum number of iterations for conditional models. Can be 1 when family = "gaussian".

gradient

Boolean specifying whether to including the gradient at the given parameters. Defaults to TRUE.

hessian

Boolean specifying whether to include the Hessian matrix at the given parameters. Defaults to FALSE.

epsilon_u

Tolerance in the inner iteration. Defaults to 1e-10.

Value

A list with elements logLik and gradient.

Details

For examples, see the vignette on maximum likelihood estimation.