View source: R/nested_laplace_re_cov.R
| tulpa_re_cov_nested | R Documentation |
For one or more random-effects terms (e.g. (1 + x | g), (1 + x || g), or
several terms together), integrate the Laplace marginal likelihood over the
random-effect covariances Sigma instead of fixing them at point estimates.
Reports weighted posterior summaries (mean, SD, median, 2.5\
Sigma and its derived scale (sigma_i) and correlation (rho_ij)
parameters, marginalizing the joint posterior over a Sigma-grid.
This corrects the plug-in-MAP ("summary") bias: the mode of a skewed variance-component marginal is biased low relative to its median, so the headline summary should be the marginalized median, not the mode.
tulpa_re_cov_nested(
y,
n_trials = NULL,
X,
re_terms,
family = "binomial",
phi = 1,
phi2 = NULL,
prior_sigma = NULL,
eta = NULL,
hyperprior = c("proper", "flat"),
log_prior_theta = NULL,
beta_prior = NULL,
offset = NULL,
weights = NULL,
n_quad = 1L,
X_zi = NULL,
zi_prior_sd = 2.5,
control = list()
)
y, n_trials, X, family, phi |
Passed to |
re_terms |
Either a single random-effect term or a list of them. Each
term is a list with |
phi2 |
Optional second dispersion, threaded into every inner
|
prior_sigma, eta |
Hyperparameters of the PC + LKJ prior used when
|
hyperprior |
|
log_prior_theta |
Optional |
beta_prior |
Optional Gaussian prior on the fixed effects, threaded into
every inner |
offset |
Optional observation-level offset on the linear predictor
(length |
weights |
Optional non-negative observation weights (length
|
n_quad |
Quadrature order for the inner marginal. |
X_zi |
Optional zero-inflation design matrix ( |
zi_prior_sd |
Prior SD on |
control |
A named list of numerical / tuning knobs (statistical arguments stay in the signature above). Recognized entries:
|
Each term is one covariance block. A correlated block ((1 + x | g)) is
a full Sigma = L L' parameterized by its lower Cholesky factor in
log-Cholesky coordinates (the log-diagonal and the strictly-lower entries of
L, c(c+1)/2 values for a c-coefficient block), which keeps Sigma
positive definite for every coordinate. An uncorrelated block
((1 + x || g)) is a diagonal Sigma parameterized by its c log standard
deviations. A scalar (1 | g) term is the degenerate c = 1 block. Several
blocks stack their parameters into one integration vector; a single-term
model is the length-1 case.
Integration nodes live in the whitened stacked-parameter space, centred at
the joint marginal-likelihood mode and rotated/scaled by the Cholesky of the
mode's posterior covariance (solve(Hessian)), so points track the posterior
ridge. Two node layouts are available via integration:
"ccd" (default): a central-composite design (ccd_grid()) of
1 + 2k + 2^(k-q) points for the total k = sum_blocks parameters, with
the corrected R-INLA design weights (ccd_weights()). Scales polynomially
in k, where the tensor grid is exponential.
"grid": the full n_per_axis^k tensor product with uniform cell
weights – denser and more robust to a non-Gaussian whitened posterior,
but only tractable for small k.
Each node k contributes integration weight proportional to
Delta_k * exp(log_marginal(Sigma_k) + log_prior_theta(theta_k)), following
the INLA convention int ~ sum_k Delta_k pi(theta_k).
The two layouts also decide how the reported median and 2.5\
of each derived quantity are read off the nodes. A tensor grid's uniform
cells discretize the posterior density, so the cumulative node weights are a
CDF and the summary is the weighted quantile. A CCD is a moment rule: its
nodes sit where they reproduce the integrand's first two moments and carry no
probability mass of their own, so the summary is moment-matched instead –
the first two weighted moments on each quantity's own coordinate (log for a
scale or a variance, atanh for a correlation, the identity for a covariance)
define a Gaussian there whose quantiles are mapped back. Scale intervals are
therefore positive and asymmetric, and correlation intervals stay inside
(-1, 1). The mean and sd columns are the weighted moments under either
layout.
By default (hyperprior = "proper") log_prior_theta is the
weakly-informative PC + LKJ hyperprior, built per block by
re_cov_pc_lkj_prior() and summed over blocks (PC prior on each marginal SD
via prior_sigma, LKJ prior on each correlated block's correlation matrix via
eta), expressed in the same parameterization with the exact
change-of-variables Jacobian. hyperprior = "flat" makes it the zero
function, flat in log(theta). The likelihood it multiplies is the inner
Laplace marginal, which integrates the fixed effects out together with the
random effects rather than profiling them, so under "flat" the node centre
theta_hat is a restricted (REML-type) estimate – REML for a gaussian
response, agreeing with glmmTMB(..., REML = TRUE) rather than with the ML
fit of lme4::glmer() otherwise (see tulpa_eb()). Supply a custom log_prior_theta
function to override either default (then prior_sigma / eta /
hyperprior are ignored); it must act on the full stacked parameter vector.
tulpa_eb() shares this same objective and the same default, so
tulpa_eb()$theta_hat and tulpa_re_cov_nested()$theta_hat stay the same
estimate on the same data under either setting.
A list with:
posterior: data frame with one row per parameter and columns mean,
sd, median, ci_lo, ci_hi. Parameter names are sigma_i, rho_ij,
Sigma_ij for a single block, prefixed by the block label
(g.sigma_1, ...) when there are several blocks. Diagonal blocks report
no rho.
map: the plug-in-mode summary at theta_hat (a single list(Sigma, sigma, rho) for one block, or a named list of them).
Sigma_mean: the weighted posterior mean of Sigma (a matrix for one
block, or a named list of matrices).
beta, draws, means, param_names, process_info: the fixed-effect
posterior from the node mixture (drives coef/confint/vcov/summary).
re_nodes, re_var_nodes: the per-group random-effect posterior at each
integration node – conditional mean and marginal variance of every
(block, group, coefficient), one row per node. ranef() reports the
weights-mixture of them. NULL at n_quad > 1, whose inner marginal
integrates each group out instead of conditioning on it; that fit carries
ranef_unavailable (the reason) in their place.
re_debias_draws, re_debias_idx: present when the subspace debias
selected a random-effect coordinate. The sampled draws of those
coordinates on the node mixture the fixed-effect draws use, and their
positions within the random-effect block. ranef() reports those rows
empirically and the rest from the Gaussian mixture, recording which in
its source column.
theta_hat, theta_grid, weights, log_marginal, n_grid, layout,
n_blocks, n_coefs (vector of per-block c).
subspace_debias: present only when control$subspace_debias was set.
idx are the corrected latent coordinates, bands the per-probed-index
reliability table they were read from, closure_added what the coupling
closure added, and accept the per-node Metropolis acceptance rate.
Rue, Martino & Chopin (2009). Approximate Bayesian inference for latent Gaussian models by using integrated nested Laplace approximations. JRSS-B 71(2):319-392. Lewandowski, Kurowicka & Joe (2009). Generating random correlation matrices based on vines and extended onion method. Journal of Multivariate Analysis 100(9):1989-2001.
tulpa_laplace() for the inner solve; tulpa_nested_laplace() for
the analogous outer integration over spatial / temporal prior
hyperparameters.
set.seed(1)
G <- 20L; per <- 12L; n <- G * per
grp <- rep(seq_len(G), each = per); x <- rnorm(n)
b <- cbind(rnorm(G, 0, 0.7), rnorm(G, 0, 0.5)) # random intercept + slope
eta <- -0.2 + 0.5 * x + b[grp, 1] + b[grp, 2] * x
y <- rbinom(n, 1L, plogis(eta))
re_term <- list(idx = grp, n_groups = G, n_coefs = 2L, Z = cbind(1, x),
correlated = TRUE)
fit <- tulpa_re_cov_nested(y, rep(1L, n), cbind(1, x), re_term,
family = "binomial")
fit$Sigma_mean # marginalized RE covariance
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.