Draw outcomes from a distribution
Source:R/distribution.R, R/mixing.R, R/dirichlet.R, and 1 more
draw.RdA finite distribution draws its atoms with probability equal to
their weights; a dirac() does so without changing the state of the
pseudorandom number generator.
Rejection sampling from Dir(alpha), keeping the proposals the
region contains.
Arguments
- dist
A distribution.
- n
Number of draws.
Examples
set.seed(1)
fam <- multinomial_family(n_trials = 4L, k = 3L)
draw(fam(c(0.5, 0.3, 0.2)), n = 3L)
#> [,1] [,2] [,3]
#> [1,] 1 1 2
#> [2,] 2 2 0
#> [3,] 2 0 2