View source: R/fit_spde_nuts.R
| tulpa_nuts_spde | R Documentation |
Bayesian counterpart to fit_spde() / laplace_spde_at(). Routes the
SPDE-augmented GLM through tulpa's full NUTS backend via the generic
LikelihoodSpec interface. Two modes:
Legacy / fixed-hyper (joint = FALSE, the default): conditions on
the supplied (range, sigma). Samples the latent block
(beta, w_mesh, log_phi) jointly. Useful as the inner step of an outer
CCD / nested-Laplace integration over hypers.
Joint hypers (joint = TRUE): samples (beta, z_mesh, log_kappa, log_tau, log_phi) jointly via the non-centered transform
w = L(theta)^{-T} z. A PC prior (Fuglstad et al. 2019 JASA) on
(range, sigma) is taken from prior_range, prior_sigma. Returns
additional w_draws, range_draws, sigma_draws, kappa_draws,
tau_draws columns/vectors on top of the raw parameter draws.
tulpa_nuts_spde(
y,
X,
spatial,
family = c("gaussian", "poisson", "binomial", "gamma", "neg_binomial_2", "beta"),
n_trials = NULL,
joint = FALSE,
range = NULL,
sigma = NULL,
prior_range = NULL,
prior_sigma = NULL,
log_kappa_init = NULL,
log_tau_init = NULL,
beta_prior = .tulpa_default_beta_prior("spde_nuts"),
log_phi_prior_sd = 3,
log_phi_init = 0,
control = list()
)
y |
Response vector. Family-specific:
|
X |
Fixed-effects design matrix. |
spatial |
A |
family |
One of |
n_trials |
Integer vector for |
joint |
Logical. |
range, sigma |
Fixed-hyper mode only. Matern range and marginal SD
on the field. Default to the SPDE prior medians
( |
prior_range, prior_sigma |
Joint mode only. PC prior anchors as
|
log_kappa_init, log_tau_init |
Joint mode only. Initial values for
the hyper slots. Default to the value implied by the PC anchor's
|
beta_prior |
Fixed-effect prior as |
log_phi_prior_sd |
Prior SD on
|
log_phi_init |
Starting value for |
control |
A named list of numerical / sampler knobs (statistical
arguments stay in the signature): |
A list with draws (matrix n_samples x n_params), means,
phi_summary (where applicable), accept_prob, divergent,
treedepth, epsilon, joint_hypers, plus the supplied spatial
spec. In joint = TRUE mode additionally:
w_draws (transformed z -> w per draw), range_draws,
sigma_draws, kappa_draws, tau_draws, and range_summary,
sigma_summary (mean/median/5%/95% quantiles).
fit_spde() for the Laplace counterpart and the nested-Laplace
path over (range, sigma).
# Gaussian response with a smooth spatial trend, sampled at fixed
# (range, sigma) on a coarse mesh.
set.seed(1)
n <- 60L
coords <- cbind(runif(n), runif(n))
x <- runif(n, -1, 1)
y <- 0.5 - 0.8 * x + 0.4 * sin(3 * coords[, 1]) + rnorm(n, 0, 0.3)
spec <- spatial_spde(coords, max_edge = c(0.3, 0.6), cutoff = 0.1,
prior_range = c(0.5, 0.5), prior_sigma = c(1, 0.5))
fit <- tulpa_nuts_spde(y, cbind(1, x), spatial = spec, family = "gaussian",
range = 0.4, sigma = 0.5, log_phi_init = log(0.3),
control = list(n_iter = 300L, n_warmup = 150L,
seed = 1L))
colMeans(fit$draws[, c("beta[1]", "beta[2]")])
fit$phi_summary
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.