| tulpa_laplace | R Documentation |
General-purpose Laplace approximation for latent Gaussian models. Finds the mode of the latent field (beta + random effects) and returns the Laplace-approximated marginal likelihood.
This is the public API for model packages (tulpaGlmm, tulpaObs, etc.)
to call tulpa's Laplace engine. As the low-level engine entry point (not a
front-door fitter), it keeps its numerical controls (max_iter, tol,
n_threads, return_hessian) inline in the signature rather than in a
control list, so callers assembling many solves pass them positionally.
tulpa_laplace(
y,
n_trials,
X,
re_list = list(),
family = "binomial",
phi = 1,
phi2 = NULL,
spatial = NULL,
weights = NULL,
offset = NULL,
max_iter = 100L,
tol = 1e-06,
n_threads = 1L,
return_hessian = TRUE,
beta_prior = NULL,
return_re_cov = FALSE,
X_zi = NULL,
zi_prior_sd = 2.5,
return_joint_hessian = FALSE,
compute_skew = FALSE,
skew_idx = NULL,
debias = NULL
)
y |
Response vector (integer for binomial/poisson/negbin, numeric for gaussian) |
n_trials |
Trial sizes (integer vector, used for binomial only) |
X |
Fixed-effects design matrix |
re_list |
List of RE specifications. Each element is a list with:
|
family |
Character: |
phi |
Dispersion passed to the family, held fixed. One convention at
every door: for Defaulted, it conditions at 1 and says so with a warning, since for a
family that reads a dispersion that is a modelling choice rather than a
neutral value. |
phi2 |
Optional second dispersion: the Student-t degrees of freedom
( |
spatial |
Optional spatial specification (tulpa_spatial object) |
weights |
Optional observation weights (numeric vector, length |
offset |
Optional observation-level offset on the linear predictor
(numeric vector, length |
max_iter |
Maximum Newton iterations (default 100) |
tol |
Convergence tolerance (default 1e-6) |
n_threads |
Number of threads (default 1) |
return_hessian |
Logical: return the fixed-effect Hessian block? (default TRUE) |
beta_prior |
Optional Gaussian prior on the fixed effects. |
return_re_cov |
If |
X_zi |
Optional zero-inflation design matrix ( |
zi_prior_sd |
Prior SD on the zero-inflation coefficients,
|
return_joint_hessian |
If |
compute_skew |
If |
skew_idx |
1-based latent indices to probe (in the |
debias |
Subspace debias: a list with |
A list with:
mode: full mode vector (beta, then RE values per term)
log_marginal: Laplace-approximated log-marginal likelihood
n_iter: number of Newton iterations
converged: logical, whether the stopping rule was met
score_max: largest absolute component of the joint penalized score at
the returned mode – the residual the solve actually achieved, which is a
different question from converged and the one anything differentiating
through the mode depends on
log_det_Q: log-determinant of the Hessian
H_beta: fixed-effect block of the Hessian (if return_hessian = TRUE)
H_joint, H_latent: the joint latent precision, at the kernel's and
at the observed curvature (if return_joint_hessian = TRUE)
cov_blocks: list of per-group posterior covariance matrices, one per
(RE term, group) in term-major then group order (if return_re_cov = TRUE)
set.seed(1)
n <- 200L
X <- cbind(1, rnorm(n))
eta <- X %*% c(-0.3, 0.8)
y <- rbinom(n, 1, plogis(eta))
fit <- tulpa_laplace(y, rep(1L, n), X, family = "binomial")
fit$mode # posterior mode of the fixed effects
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.