Generates random samples from the \(w_1\) distribution by first sampling
\(\alpha \sim Gamma(a, b)\), then
\(w_1 \mid \alpha \sim Beta(1, \alpha)\).
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).
Value
Numeric vector of length n; random samples from the \(w_1\)
distribution.
Details
This function uses the hierarchical representation:
\(\alpha \sim Gamma(a, b)\)
\(w_1 \mid \alpha \sim Beta(1, \alpha)\)
Useful for Monte Carlo validation of the closed-form functions.
Examples
# Generate samples
set.seed(42)
samples <- rw1(10000, a = 2, b = 1)
# Compare empirical vs theoretical mean
mean(samples) # ~0.404
#> [1] 0.4023996
mean_w1(a = 2, b = 1) # 0.4037
#> [1] 0.4036526