One front door for inference over a user-defined tgmrf() latent block's
hyperparameter vector theta. mode selects the inference engine, all of
which share the same Laplace body for (beta, z) | theta:
"imh"(default) – Tier-1 exact MCMC: the Laplace body plus an independence-Metropolis bias correction overtheta(the "Laplace + MH debias" composition)."nuts"– Tier-1 exact MCMC: NUTS over the marginalthetaposterior."vi"– Tier-2 structured: a single-path Pathfinder Gaussian fit of thethetaposterior (no bias correction)."nuts_joint"– Tier-1 exact MCMC sampling the FULL joint(beta, z, theta)rather than the Laplace-marginalizedtheta(requires a C++-backend block, seetgmrf_cpp()).
The inference method is an argument, not a parallel verb.
Arguments
- y, n_trials, X
Response, binomial trial counts (or
NULL), and the fixed-effect design matrix.- block
A
tgmrf()latent block.- family, phi
Observation family and its dispersion.
- re_idx, n_re_groups, sigma_re
Optional scalar random-intercept structure.
- mode
Inference engine:
"imh","nuts","vi", or"nuts_joint".- control
A list of numerical / tuning knobs for the chosen
mode(e.g.n_iter,warmup,thin,scalefor"imh";epsilon,max_depth,target_acceptfor the NUTS modes;n_draws,max_lbfgs,lbfgs_tolfor"vi"; plus the sharedpilot_axis_points,max_iter,tol,n_threads,verbose). An unknown knob for the chosenmodeerrors rather than being silently ignored.- ...
Individual
controlknobs may also be passed directly by name; they are merged intocontrol(a named argument here wins over the same name insidecontrol).
See also
tgmrf() for the block, tgmrf_cpp() for the compiled-block form.
Examples
# \donttest{
# An iid random intercept written as a tgmrf block over 15 groups; the
# inference method is an argument, not a parallel verb. See the
# custom-process article at https://gillescolling.com/tulpa/articles/tgmrf.html.
set.seed(3)
J <- 15L; g <- rep(seq_len(J), each = 6L); n <- length(g); x <- rnorm(n)
y <- rpois(n, exp(0.3 + 0.5 * x + rnorm(J, 0, 0.6)[g]))
blk <- tgmrf(
Q = function(theta) Matrix::Diagonal(J, exp(-2 * theta[1])),
prior = function(theta) stats::dnorm(theta[1], 0, 1, log = TRUE),
init = c(log_sigma = 0), obs_idx = g)
fit <- tulpa_tgmrf(y, rep(1L, n), cbind(1, x), block = blk,
family = "poisson", mode = "imh",
control = list(n_iter = 300L, warmup = 150L))
mean(exp(fit$draws[, "log_sigma"])) # posterior mean group SD
# }