R/priors-methods-joint.R, R/priors-methods-marginal.R
prior_functions.RdDensity (pdf / lpdf), distribution
function (cdf / ccdf), quantile function (quant),
random generation (rng), mean, standard deviation (sd),
and marginal variants of the functions (mpdf, mlpf, mcdf,
mccdf, mquant) for prior distributions.
Joint quantiles are unavailable for vector factor priors; use
mquant() for their marginal quantiles.
The marginal methods and var()/sd() of a bound orthonormal or
mean-difference mnormal/mt factor prior describe its
continuous levels: they take the scale of each level from the declared
factor design, a level whose design row vanishes identically (the reference
level of a treatment factor inside an interaction) is the atom at zero that
the cell declares and does not enter the common scale, and levels whose
non-zero rows differ in norm have no common marginal and refuse.
Missing evaluation values NA_real_ and NaN propagate distinctly
through density, distribution and quantile methods for moment, inverse-moment
and inverse-gamma scalar priors, including their marginal methods. Generic
scalar CDF and complementary CDF methods also retain this distinction under
truncation. This statement does not cover truncated Normal quantiles.
Continuous truncation uses logarithmic interval masses, including separate
signed radial intervals for nonlocal priors. An unresolved positive
normalizer stops with BayesTools_numerical_unavailable before a
cached density evaluator or bridge calculation is constructed. Existing
Normal-only rounding adjustments are retained; other truncated quantiles
never clip an unavailable result into their bounds.
Ordinary Gamma normalization is unavailable for a numeric subnormal shape
when truncation cuts its positive support: finite base R log tails can be
wrong in this floating-point regime. Constructors retain their supported
parameter domain and whole-positive-support mass remains exactly one.
Raw untruncated base R Gamma extreme calculations are not certified by this
normalization guard.
Valid interior numerical failures give NaN with one
BayesTools_numerical_unavailable warning per vector. Established
inverse-gamma or nonlocal natural density or quantile range limits retain
their raw zero or infinite result with BayesTools_numerical_range_limit.
Ordinary family density range results retain their existing behavior when
their log density is available. Both numerical classes inherit
BayesTools_numerical_condition, warning, and condition.
Conditions record operation, family, requested_scale,
indices, and reason, with call = NULL. Exact support
endpoints and rounded natural probabilities with available log tails do
not warn. Sampling failures are errors additionally inheriting
BayesTools_prior_rng_unavailable; all original uniforms are consumed
before signaling. Finite-required consumers and JAGS refuse unavailable
draws, density values, and normalization, without redraw or model repair.
# S3 method for class 'prior'
rng(x, n, ...)
# S3 method for class 'prior'
cdf(x, q, ...)
# S3 method for class 'prior'
ccdf(x, q, ...)
# S3 method for class 'prior'
lpdf(x, y, ...)
# S3 method for class 'prior'
pdf(x, y, ...)
# S3 method for class 'prior'
quant(x, p, ...)
# S3 method for class 'prior'
mcdf(x, q, ...)
# S3 method for class 'prior'
mccdf(x, q, ...)
# S3 method for class 'prior'
mlpdf(x, y, ...)
# S3 method for class 'prior'
mpdf(x, y, ...)
# S3 method for class 'prior'
mquant(x, p, ...)prior distribution
number of observations
additional arguments of rng(); the other functions
ignore them. transform_factor_samples (default TRUE):
whether the samples of orthonormal, mean-difference and ordered factor
priors are transformed to the level scale (FALSE: the raw
coefficients); sample_components (default FALSE): whether
mixture and spike-and-slab priors return the sampled component (or
inclusion indicator) instead of the values;
quantity (ordered priors only, default "level"): the
draws returned, one of "level" (the transformed level samples),
"coefficient" and "increment" (the raw coefficients),
"total" (the totals of the ordered sums) or "allocation"
(the allocation shares).
vector or matrix of quantiles
vector of observations
vector of probabilities
pdf (mpdf) and lpdf (mlpdf) give
the (marginal) density and the log of (marginal) density,
cdf (mcdf) and ccdf (mccdf) give the
(marginal) distribution and the complement of (marginal) distribution function,
quant (mquant) give the (marginal) quantile function,
and rng generates random deviates for an object of class 'prior'.
Numeric Dirichlet concentrations must be finite and at least
0.01. This supported-input minimum does not guarantee representable
draws for every accepted specification. Dirichlet and cumulative
weight-function rng() calls stop with class
BayesTools_dirichlet_rng_unavailable, parent class
BayesTools_prior_rng_unavailable, and classes error and
condition if sampling produces non-finite entries, entries outside
[0, 1], or a simplex row with zero total. The condition has
call = NULL and message: "Dirichlet draws are unavailable because
sampling produced non-finite or degenerate simplex draws. Use a less extreme
'alpha' specification." There is no retry or repair. Individual rounded
zero or one entries are retained and do not represent new prior atoms.
Ordinary expression-valued Dirichlet priors retain their JAGS-only support;
R random generation refuses priors containing parameter expressions.
# create a standard normal prior distribution
p1 <- prior(distribution = "normal", parameters = list(mean = 1, sd = 1))
# generate a random sample from the prior
rng(p1, 10)
#> [1] -1.5923277 2.3140022 0.3644570 0.5700212 0.8306817 1.6122182
#> [7] 1.6783402 1.5679520 0.4274574 -0.3632913
# compute cumulative density function
cdf(p1, 0)
#> [1] 0.1586553
# obtain quantile
quant(p1, .5)
#> [1] 1
# compute probability density
pdf(p1, c(0, 1, 2))
#> [1] 0.2419707 0.3989423 0.2419707