Log Marginal PMF of K_J under Gamma Hyperprior
log_pmf_K_marginal.RdComputes \(\log P(K_J = k \mid a, b)\) for \(k = 0, 1, \ldots, J\) using log-space mixing for numerical stability.
Usage
log_pmf_K_marginal(
J,
a,
b,
logS,
M = .QUAD_NODES_DEFAULT,
M_verify = NULL,
abs_tol = 1e-10,
rel_tol = 1e-08,
strict = FALSE
)Arguments
- J
Integer; sample size (must be >= 1).
- a
Numeric; shape parameter of Gamma prior (must be > 0).
- b
Numeric; rate parameter of Gamma prior (must be > 0).
- logS
Matrix; pre-computed log-Stirling matrix from
compute_log_stirling.- M
Integer; number of quadrature nodes (default:
.QUAD_NODES_DEFAULT).- M_verify
Optional independent quadrature order satisfying the package verification rule (at least
max(2*M, M+40), within the supported ceiling). When supplied, the selected PMF is compared with a fresh higher-order PMF.- abs_tol, rel_tol
Non-negative absolute and relative tolerances for the selected-versus-verification L1 discrepancy and the PMF-versus-direct- moment checks at both quadrature orders.
- strict
Logical; require successful higher-order verification when
TRUE; otherwise return the selected PMF with explicit approximation metadata.
Value
Numeric vector of length \(J+1\) containing log-probabilities
for \(k = 0, 1, \ldots, J\). Entry [1] corresponds to \(k=0\)
and is always -Inf.
Details
This routine normalizes \(P(K_J = \cdot \mid \alpha_m)\) at each quadrature
node before mixing, and then mixes in log-space via logsumexp_vec:
$$\log p_k \approx \log\sum_m \exp\{\log w_m + \log p_{k\mid m}\}.$$
The log-space computation is essential for numerical stability when:
J is large (tail probabilities become very small)
Alpha values span a wide range (extreme quadrature nodes)
Parameters lead to concentrated distributions
A verified result must pass both the selected-versus-verification PMF L1 budget and an independent cross-representation audit: at each order, the mean and variance represented by the PMF must agree with the direct marginal-moment quadrature. Thus two mutually agreeing but scientifically incorrect PMFs cannot be classified as converged.