rdirichlet_mat {hesim} | R Documentation |
Random generation for multiple Dirichlet distributions
Description
Draw random samples from multiple Dirichlet distributions for use in transition probability matrices.
Usage
rdirichlet_mat(
n,
alpha,
output = c("array", "matrix", "data.frame", "data.table")
)
Arguments
n |
Number of samples to draw. |
alpha |
A matrix where each row is a separate vector of shape parameters. |
output |
The class of the object returned by the function. Either an
|
Details
This function is meant for representing the distribution of
transition probabilities in a transition matrix. The (i,j)
element of
alpha
is a transition from state i
to state j
. It is vectorized and
written in C++
for speed.
Value
If output = "array"
, then an array of matrices is returned
where each row of each matrix is a sample from the Dirichlet distribution.
If output
results in a two dimensional object (i.e., a matrix
,
data.frame
, or data.table
, then each row contains
all elements of the sampled matrix from the Dirichlet distribution
ordered rowwise; that is, each matrix is flattened. In these cases,
the number of rows must be less than or equal to the number of columns.
Examples
alpha <- matrix(c(100, 200, 500, 50, 70, 75), ncol = 3, nrow = 2, byrow = TRUE)
samp <- rdirichlet_mat(100, alpha)
print(samp[, , 1:2])