prior_simfuncs: Prior Simulation Functions for glmbayes pfamily Objects

prior_simfuncsR Documentation

Prior Simulation Functions for glmbayes pfamily Objects

Description

Prior-simulation functions provide a unified interface for generating iid draws directly from the prior distribution stored in a pfamily object's prior_list, mirroring the existing simfuncs (rNormal_reg, rGamma_reg, rGamma_Conjugate_reg, rNormalGamma_reg, rindepNormalGamma_reg, rBeta_reg) that already generate iid draws from the posterior.

Every pfamily constructor (dNormal, dGamma, dNormal_Gamma, dIndependent_Normal_Gamma, dBeta) has a corresponding prior-simulation function below, named by dropping the leading "d" from the constructor's name, prepending "r", and appending "_prior" (e.g. dNormal() -> rNormal_prior()), matching the existing simfuncs' own "r..._reg" naming. dGamma() maps to one of two functions depending on Inv_Dispersion, exactly as it already selects between rGamma_reg and rGamma_Conjugate_reg for its simfun: rGamma_prior() (Inv_Dispersion = TRUE: prior on the inverse dispersion only) and rGamma_Conjugate_prior() (Inv_Dispersion = FALSE: conjugate prior on the rate directly).

All six functions share an identical signature function(n, prior_list, params = NULL, ...), so a caller holding only n and a prior_list (plus, optionally, a vector of parameter names) can invoke any of them the same way – exactly as rglmb/rlmb call whichever simfun a pfamily object carries without needing to know which one it is. Each pfamily constructor stores the matching function as pfun, alongside simfun, so simulate_prior methods can extract the pfamily and call pfun(n, prior_list, params) directly – mirroring how rglmb/rlmb call simfun.

Coefficient draws for a genuinely multivariate normal prior (dNormal, dNormal_Gamma, dIndependent_Normal_Gamma) are drawn from the true joint N(\mu, \Sigma) via a Cholesky factor of the complete (possibly non-diagonal) Sigma, preserving any correlation between coefficients – not reconstructed from per-parameter marginal moments. dBeta/dGamma (Inv_Dispersion = FALSE) coefficients are drawn independently, one rbeta/ rgamma draw per parameter, from their exact shape1/shape2 or shape/rate form, rather than their normal-moment surrogate.

dNormal_Gamma and dIndependent_Normal_Gamma both place priors on both the coefficients (joint normal) and the dispersion (inverse-gamma), so rNormal_Gamma_prior() and rIndependent_Normal_Gamma_prior() return both a coefficient block and a dispersion column. For dIndependent_Normal_Gamma the dispersion prior is two-sided truncated to prior_list$disp_lower/disp_upper (see rindepNormalGamma_reg and the dIndependent_Normal_Gamma branches in rglmb/rlmb/glmb/ lmb, which always populate these – even when left at their default NULL at prior-specification time – with the bounds the accept-reject envelope actually used); rIndependent_Normal_Gamma_prior() samples that exact truncated Inverse-Gamma via .glmbayes_rinvgamma_prior() (‘R/prior_simfunction.R’), the same inverse-CDF method ‘src/invgamma_ct.cpp’ uses internally. dNormal_Gamma's dispersion prior has no truncation concept at all (fully conjugate; disp_lower/disp_upper are absent from its prior_list), and dGamma's truncation is opt-in only (via explicit disp_lower/disp_upper arguments; the default NULL is never overwritten after fitting) – both fall back to the plain untruncated Inverse-Gamma via the same helper.

Usage

rNormal_prior(n, prior_list, params = NULL, ...)

rGamma_prior(n, prior_list, params = NULL, ...)

rGamma_Conjugate_prior(n, prior_list, params = NULL, ...)

rNormal_Gamma_prior(n, prior_list, params = NULL, ...)

rIndependent_Normal_Gamma_prior(n, prior_list, params = NULL, ...)

rBeta_prior(n, prior_list, params = NULL, ...)

Arguments

n

Number of prior draws to generate.

prior_list

A list with prior parameters (mu, Sigma, shape, rate, shape1, shape2, beta, disp_lower, disp_upper, etc., as relevant), of the same form stored in a pfamily object's prior_list.

params

Optional character vector of coefficient names for the output columns. Defaults to rownames(prior_list$mu) when NULL (as set by Prior_Setup and the pfamily constructors when given named input); falls back to "V1", "V2", ... if neither is available.

...

Additional arguments; currently unused, present so all six functions share an identical signature and so extra arguments passed by a generic caller are silently ignored.

Value

A data.frame with n rows. rGamma_prior() (dGamma(Inv_Dispersion = TRUE)) returns a single dispersion column and no coefficient columns, since that prior is on the inverse dispersion only. The other five return one column per coefficient, named from params; rNormal_Gamma_prior() and rIndependent_Normal_Gamma_prior() additionally append a dispersion column.

See Also

pfamily, dNormal, dGamma, dNormal_Gamma, dIndependent_Normal_Gamma, dBeta; simfuncs for the analogous posterior-simulation functions; glmbayes_bayestestR_prior_methods for simulate_prior on fitted glmb objects.


glmbayes documentation built on Aug. 5, 2026, 1:07 a.m.

Related to prior_simfuncs in glmbayes...