View source: R/nested_laplace_moments.R
| tulpa_theta_matrix | R Documentation |
Coerces a nested-Laplace fit's theta_grid to matrix form with named axis
columns. A single-axis grid is stored on the fit as a bare vector named by
theta_names; every downstream reader that keys an axis by name needs the
named matrix form, so this is the one place that coercion happens.
Intended for reconstructing a fit's outer-grid posterior cell weights (see
tulpa_grid_log_quad(), tulpa_normalise_weights_safe()) for a fit or
path whose driver doesn't already carry fit$log_quad.
tulpa_theta_matrix(res)
res |
A |
res$theta_grid as an [n_cells x n_axes] matrix with axis names
as column names, or NULL if the fit has no grid.
tulpa_grid_log_quad(), tulpa_normalise_weights_safe()
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))
tulpa_theta_matrix(fit)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.