rgdirmn {MGLM} | R Documentation |
The Generalized Dirichlet Multinomial Distribution
Description
rgdirmn
generates random observations from the generalized Dirichlet multinomial distribution.
dgdirmn
computes the log of the generalized Dirichlet multinomial probability mass function.
Usage
rgdirmn(n, size, alpha, beta)
dgdirmn(Y, alpha, beta)
Arguments
n |
the number of random vectors to generate. When |
size |
a number or vector specifying the total number of objects that are put into d categories in the generalized Dirichlet multinomial distribution. |
alpha |
the parameter of the generalized Dirichlet multinomial distribution.
For For |
beta |
the parameter of the generalized Dirichlet multinomial distribution. For |
Y |
the multivariate count matrix with dimensions |
Details
Y=(y_1, \ldots, y_d)
are the d
category count vectors. Given the parameter vector \alpha = (\alpha_1, \ldots, \alpha_{d-1}),
\alpha_j>0
, and \beta=(\beta_1, \ldots, \beta_{d-1}), \beta_j>0
,
the generalized Dirichlet multinomial probability mass function is
P(y|\alpha,\beta)
=C_{y_1, \ldots, y_d}^{m} \prod_{j=1}^{d-1}
\frac{\Gamma(\alpha_j+y_j)}{\Gamma(\alpha_j)}
\frac{\Gamma(\beta_j+z_{j+1})}{\Gamma(\beta_j)}
\frac{\Gamma(\alpha_j+\beta_j)}{\Gamma(\alpha_j+\beta_j+z_j)} ,
where z_j = \sum_{k=j}^d y_k
and m = \sum_{j=1}^d y_j
.
Here, C_k^n
, often read as "n
choose k
",
refers the number of k
combinations from a set of n
elements.
The \alpha
and \beta
parameters can be vectors, like the results from the
distribution
fitting function, or they can be matrices with n
rows,
like the estimate
from the regression function multiplied by the covariate matrix
exp(X\alpha)
and exp(X\beta)
Value
dgdirmn
returns the value of
\log(P(y|\alpha, \beta))
.
When Y
is a matrix of n
rows, the function dgdirmn
returns a vector of length n
.
rgdirmn
returns a n\times d
matrix of the generated random observations.
Examples
# example 1
m <- 20
alpha <- c(0.2, 0.5)
beta <- c(0.7, 0.4)
Y <- rgdirmn(10, m, alpha, beta)
dgdirmn(Y, alpha, beta)
# example 2
set.seed(100)
alpha <- matrix(abs(rnorm(40)), 10, 4)
beta <- matrix(abs(rnorm(40)), 10, 4)
size <- rbinom(10, 10, 0.5)
GDM.rdm <- rgdirmn(size=size, alpha=alpha, beta=beta)
GDM.rdm1 <- rgdirmn(n=20, size=10, alpha=abs(rnorm(4)), beta=abs(rnorm(4)))