View source: R/hyper_quadrature.R
| tulpa_grid_log_quad | R Documentation |
The per-cell log quadrature weight (prior mass) of a nested-Laplace outer
grid: every path that turns a fit's log_marginal into posterior cell
weights goes through this one rule, so the prior mass a cell carries is
decided in one place. Rebuilds axis specs from the grid's own columns when
specs is not supplied. Intended for reconstructing a fit's outer-grid
posterior weights (with tulpa_theta_matrix() and
tulpa_normalise_weights_safe()) when the fit doesn't already carry
fit$log_quad.
tulpa_grid_log_quad(
theta_grid,
specs = NULL,
copy_slab = "exponential",
close_domain = TRUE,
folded_axes = NULL,
refining = NULL
)
theta_grid |
A named |
specs |
Optional pre-built per-axis spec list; |
copy_slab |
|
close_domain |
Whether an unbounded axis's outer cells are closed at the grid's own edge rather than left open to infinity. |
folded_axes |
Optional names of axes folded onto |
refining |
Optional refinement tag vector (see
|
Numeric vector of per-cell log quadrature weights, length
nrow(theta_grid), or NULL if theta_grid has no axis names.
tulpa_theta_matrix(), tulpa_normalise_weights_safe(),
tulpa_joint_axis_specs_from_grid()
set.seed(1)
S <- 30L # spatial units 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))))
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",
control = list(progress = FALSE))
tg <- tulpa_theta_matrix(fit)
lq <- tulpa_grid_log_quad(tg)
# The fit's own cell weights, rebuilt from its log marginals:
tulpa_normalise_weights_safe(fit$log_marginal, log_quad = lq)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.