rnegmn | R Documentation |
dnegmn
calculates the log of the negative multinomial probability mass function.
rnegmn
generates random observations from the negative multinomial distribution.
rnegmn(n, beta, prob) dnegmn(Y, beta, prob = alpha/(rowSums(alpha) + 1), alpha = NULL)
n |
number of random vectors to generate. When |
beta |
the over dispersion parameter of the negative multinomial distribution. |
prob |
the probability parameter of the negative multinomial distribution. Should be a numerical non-negative vector or matrix. For For |
Y |
the multivariate response matrix of dimension nxd, where n = 1, 2, … is number of observations and d=2,3,… is number of categories. |
alpha |
an alternative way to specify the probability. Default value is |
y=(y_1, …, y_d) is a d category vector. Given the parameter vector p= (p_1, …, p_d), p_{d+1} = 1/(1 + sum_{j'=1}^d p_{j'}), and β, β>0, the negative multinomial probability mass function is
P(y|p,β) = C_{m}^{β+m-1} C_{y_1, …, y_d}^{m} prod_{j=1}^d p_j^{y_j} p_{d+1}^β = (β_m)/(m!) C_{y_1, …, y_d}^{m} prod_{j=1}^d p_j^{y_j} p_{d+1}^β,
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.
alpha
is an alternative way to specify the probability:
p_j = α_j / (1+sum_{k=1}^{d} α_k)
for j=1,…,d and p_{d+1} = 1 / (1+sum_{k=1}^{d} α_k).
The parameter prob
can be a vector and beta
is a scalar; prob
can also
be a matrix with n rows, and beta
is a vector of length n
like the estimate from the regression function
multiplied by the covariate matrix.
dnegmn
returns the value of
logP(y|p, β). When Y
is a matrix of n rows, the function
returns a vector of length n.
rnegmn
returns a nxd matrix of the generated random observations.
Yiwen Zhang and Hua Zhou
###-----------------------### set.seed(128) n <- 100 d <- 4 p <- 5 a <- -matrix(1,p,d) X <- matrix(runif(n*p), n, p ) alpha <- exp(X%*%a) prob <- alpha/(rowSums(alpha)+1) beta <- exp(X%*%matrix(1,p)) Y <- rnegmn(n, beta, prob) ###-----------------------### m <- 20 n <- 10 p <- 5 d <- 6 a <- -matrix(1,p,d) X <- matrix(runif(n*p), n, p ) alpha <- exp(X%*%a) prob <- alpha/(rowSums(alpha)+1) b <- exp(X%*%rep(0.3,p)) Y <- rnegmn(prob=prob, beta=rep(10, n)) dnegmn(Y, b, prob)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.