Draw random samples from multiple Dirichlet distributions for use in transition probability matrices.
rdirichlet_mat(
n,
alpha,
output = c("array", "matrix", "data.frame", "data.table")
)
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.
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.
alpha <- matrix(c(100, 200, 500, 50, 70, 75), ncol = 3, nrow = 2, byrow = TRUE)
samp <- rdirichlet_mat(100, alpha)
print(samp[, , 1:2])
#> , , 1
#>
#> [,1] [,2] [,3]
#> [1,] 0.1131831 0.2561972 0.6306197
#> [2,] 0.2636402 0.3881489 0.3482110
#>
#> , , 2
#>
#> [,1] [,2] [,3]
#> [1,] 0.1426024 0.2262479 0.6311497
#> [2,] 0.2976925 0.3570395 0.3452680
#>