Random Generation from rho Distribution
rrho.RdGenerates random samples from the rho = sum w_h^2 distribution by stick-breaking simulation.
Arguments
- n
Integer; number of samples to generate.
- a
Numeric; shape parameter of the Gamma prior on alpha (a > 0).
- b
Numeric; rate parameter of the Gamma prior on alpha (b > 0).
- n_sticks
Integer; minimum number of sticks generated for each draw. The sampler continues adaptively when the remaining squared mass is above
remainder_tol. Default is 500.- remainder_tol
Numeric; maximum allowed deterministic upper bound on the omitted contribution to rho. Because all ungenerated weights sum to remainder \(R\), their contribution satisfies \(0 <= \sum_{\mathrm{tail}} w_h^2 <= R^2\). Default is
1e-10.- max_sticks
Integer; hard per-draw stick ceiling. Default is 100,000.
- strict
Logical; if
TRUE(the default), reachingmax_sticksbefore the remainder contract is met raises a typeddpprior_rho_truncation_error. IfFALSE, the finite lower approximation is returned with status"approximate"and its deterministic remainder bound in the"rrho_diagnostics"attribute.
Value
Numeric vector of length n. The "rrho_diagnostics" attribute
records the adaptive method, status, tolerance, sticks used, and the
per-draw deterministic omitted-rho bounds on both ordinary and log scales.
When a positive bound is smaller than the floating-point range, its
ordinary-scale representation is rounded upward to the smallest positive
double rather than silently reported as zero.
Details
Uses the hierarchical representation:
alpha ~ Gamma(a, b)
v_h | alpha ~ Beta(1, alpha) independently
w_1 = v_1, w_h = v_h * prod(1 - v_l) for l < h
Generate at least
n_sticksterms and continue until the unallocated remainder \(R\) obeys \(R^2 <= remainder_tol\)Return the partial sum; its omitted contribution is in \([0,R^2]\)
Thus finite-stick error is controlled draw by draw rather than being silently discarded. Useful for Monte Carlo validation of analytical formulas.
See also
rw1 for w1 random generation