| rmn | R Documentation |
rmn generates random number vectors given alpha.
The function rmn(n, size, alpha) calls rmultinom(n, size, prob) after converting alpha to probability.
dmn computes the log of multinomial probability mass function.
rmn(n, size, alpha) dmn(Y, prob)
n |
number of random vectors to generate. |
size |
a scalar or a vector. |
alpha |
a vector or a matrix. |
Y |
the multivariate count matrix with dimension n x d, where n = 1,2,… is number of observations and d=2,… is number of categories. |
prob |
the probability parameter of the multinomial distribution. |
A multinomial distribution models the counts of d possible outcomes. The counts of categories are negatively correlated. y=(y_1, …, y_d) is a d category count vector. Given the parameter vector p = (p_1, …, p_d), 0 < p_j < 1, sum_{j=1}^d p_j = 1, the function calculates the log of the multinomial pmf
P(y|p) = C_{y_1, …, y_d}^{m} prod_{j=1}^{d} p_j^{y_j},
where 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 parameter p can be one vector, like the result from the distribution fitting function; or, p can be a matrix with n rows, like the estimate from the regression function,
p_j = (exp(X β_j)) / (1 + sum_{j'=1}^{d-1} exp(Xβ_{j'})),
where j=1,…,d-1 and p_d = 1/(1 + sum_{j'=1}^{d-1} exp(Xβ_{j'})). The d-th column of the coefficient matrix β is set to 0 to avoid the identifiability issue.
The function dmn returns the value of logP(y|p).
When Y is a matrix of n rows, the function returns a
vector of length n.
The function rmn returns multinomially distributed random number vectors
Yiwen Zhang and Hua Zhou
m <- 20 prob <- c(0.1, 0.2) dm.Y <- rdirmn(n=10, m, prob) pdfln <- dmn(dm.Y, prob)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.