View source: R/nested_laplace.R
| print.tulpa_nested_laplace | R Documentation |
Generic outer-grid nested Laplace driver. Builds a grid over the hyperparameters of a single latent prior block (spatial or temporal), runs an inner Laplace at each grid point with warm-starting, and integrates over the grid to give proper hyperparameter marginals.
Supported priors:
Spatial (areal): "icar" (1D grid on tau), "bym2"
(2D on (sigma, rho)), "car_proper" (2D on (tau, rho); rho lives
in the eigenvalue interval (1/lambda_min, 1/lambda_max) of
D^{-1} W).
Spatial (continuous): "nngp" (2D on (sigma2, phi_gp)),
"hsgp" (2D on (sigma2, lengthscale)).
Temporal: "rw1", "rw2" (1D grid on tau), "ar1" (2D on (tau, rho))
SPDE continuous spatial: see cpp_nested_laplace_spde() (separate
entry, rebuilds Q via SPDE Q-builder).
## S3 method for class 'tulpa_nested_laplace'
print(x, ...)
tulpa_nested_laplace(
y,
n_trials,
X,
prior = NULL,
spec = NULL,
data = NULL,
re_idx = NULL,
n_re_groups = 0L,
sigma_re = 1,
family = "binomial",
phi = 1,
offset = NULL,
likelihood = NULL,
hyperprior = c("proper", "flat"),
control = list()
)
x |
A nested-Laplace fit. |
... |
Ignored. |
y |
Response vector. |
n_trials |
Trial sizes (binomial). Pass |
X |
Fixed-effects design matrix. |
prior |
A list describing the latent prior block. Required field
Any block accepts an optional
An Grids of a two-axis type ( A default grid axis is a starting axis, not a hard ceiling: for |
spec |
Optional |
data |
Data frame used to validate |
re_idx |
Optional 1-based RE group index per obs (defaults to no RE). |
n_re_groups |
RE group count (default 0). |
sigma_re |
RE standard deviation (default 1). |
family |
|
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. |
offset |
Optional per-observation offset added to the linear predictor
(length |
likelihood |
Optional model-supplied likelihood, replacing the built-in
|
hyperprior |
The prior an outer hyperparameter axis carries when the
call states no density for it, |
control |
Optional list of perf/numerical tuning knobs (statistical
arguments stay top-level), following the
|
print() shows the integrated hyperparameters, the outer-grid
size, the outer Pareto-\hat{k} diagnostic when present and the
wall-clock timing line ("fit in 5h 25m (grid 2h 09m)") when
fit$timing is attached, then the fixed effects.
A list with:
theta_grid: matrix or vector of grid hyperparameter values.
log_marginal: log p(y, mode | theta_k) at each grid point.
weights: integration weights normalising to sum 1.
theta_mean, theta_sd: posterior moments per hyperparameter.
n_iter: inner Newton iterations per grid point.
modes: matrix [n_grid x n_x] of inner modes, when stored.
pareto_k, pareto_k_is_ess: outer Pareto-\hat{k} and its
importance-sampling ESS (NA when not computed for the grid; see
control$diagnose_k).
pareto_k_proposal_source, pareto_k_first_pass: which proposal family
the reported k-hat came from (the outer k-hat is scored against several
candidates and the best is kept), and the k-hat of the FIRST pass – the
proposal exactly as this backend placed it, before any candidate refined
or replaced it. A large gap between the two says the nodes are badly
scaled around the hyperparameter posterior even though the verdict is
fine; no gap says the placement was already right.
inner_skew, inner_skew_idx, inner_skew_dropped: the inner-Laplace
skewness diagnostic (gamma_3) at each scored latent index and its
1-based index, plus a count of (index, observation) contributions
dropped for a non-finite third derivative (see control$diagnose_skew).
timing: named numeric of wall-clock seconds (total, setup,
grid, postproc, diagnostics); the grid phase is the inner
Laplace pass that scales with grid size. Surfaced one-line in print.
prune_cheap_log_marginal, prune_mask, prune_n_pruned, prune_tol:
present when the grid was screened and the safety gate did not
trip – the cheap-screen log-marginal per cell (the truncated solve's
value plus half its Newton decrement, the second-order estimate of the
converged value the cells are ranked by; the decrement itself is
prune_screen_decrement), the logical mask of
pruned cells, the pruned-cell count, and the threshold actually applied.
prune_log_gap_cut, prune_cheap_lm_spread, prune_min_keep,
prune_n_floor_restored: the same screen read on the scale it operates
on – how many nats below the best screened cell the tolerance cut at,
how many nats the screened surface spans, the kept-cell floor applied,
and how many cells that floor put back. A cut that is a sliver of the
spread is a tolerance with no resolution on this grid.
prune_dropped_mass_bound, prune_n_repaired, prune_gate_mass: the
posterior mass the dropped cells may carry, with each lifted by the worst
screening error measured on a kept cell; how many dropped cells the
driver solved in full to bring that under the gate; and the gate.
prune_fallback_triggered, prune_fallback_reason: present only when
the gate did trip; the rest of the fit is then the full-grid result and
the reason string records which check fired.
prior: echoed input.
Rue, Martino & Chopin (2009). Approximate Bayesian inference for latent Gaussian models by using integrated nested Laplace approximations. JRSS-B 71(2):319-392.
set.seed(1)
S <- 30L # spatial units arranged in a chain
nb <- lapply(seq_len(S), function(s) setdiff(c(s - 1L, s + 1L), c(0L, S + 1L)))
nn <- lengths(nb)
field <- as.numeric(scale(cumsum(rnorm(S, 0, 0.4)))) # smooth spatial field
idx <- rep(seq_len(S), each = 6L); n <- length(idx); x <- rnorm(n)
y <- rbinom(n, 1L, plogis(-0.2 + 0.6 * x + field[idx]))
prior <- list(type = "icar", n_spatial_units = S, spatial_idx = idx,
adj_row_ptr = c(0L, cumsum(nn)), adj_col_idx = unlist(nb) - 1L,
n_neighbors = nn, tau_grid = c(0.5, 1, 2, 4, 8))
fit <- tulpa_nested_laplace(y, rep(1L, n), cbind(1, x), prior = prior,
family = "binomial")
fit$theta_mean # marginalized ICAR precision
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.