rnegmn {MGLM}R Documentation

The Negative Multinomial Distribution

Description

dnegmn calculates the log of the negative multinomial probability mass function. rnegmn generates random observations from the negative multinomial distribution.

Usage

rnegmn(n, beta, prob)

dnegmn(Y, beta, prob = alpha/(rowSums(alpha) + 1), alpha = NULL)

Arguments

n

number of random vectors to generate. When beta is a scalar and prob is a vector, must specify n. When beta is a vector and prob is a matrix, n is optional. The default value of n is the length of beta. If given, n should be equal to the length of beta.

beta

the over dispersion parameter of the negative multinomial distribution. beta can be either a scalar or a vector of length nn.

prob

the probability parameter of the negative multinomial distribution. Should be a numerical non-negative vector or matrix.

For dnegmn, prob can be either a vector of length dd (d2)(d \ge 2) or a matrix with matching size of Y. If prob is a vector, it will be replicated nn times to match the dimension of Y. The sum of each row of prob should be smaller than 1.

For rnegmn, If prob is a vector, beta must be a scalar. All the n random vectors will be drawn from the same prob and beta. If prob is a matrix, the number of rows should match the length of beta. Each random vector will be drawn from the corresponding row of prob and the corresponding element of beta. Each row of prob should have sum less than 1.

Y

the multivariate response matrix of dimension n×dn \times d, where n=1,2,n = 1, 2, \ldots is number of observations and d=2,3,d=2,3,\ldots is number of categories.

alpha

an alternative way to specify the probability. Default value is NULL. See details.

Details

y=(y1,,yd)y=(y_1, \ldots, y_d) is a dd category vector. Given the parameter vector p=(p1,,pd)p= (p_1, \ldots, p_d), pd+1=1/(1+j=1dpj)p_{d+1} = 1/(1 + \sum_{j'=1}^d p_{j'}), and β\beta, β>0\beta>0, the negative multinomial probability mass function is

P(yp,β)=Cmβ+m1Cy1,,ydmj=1dpjyjpd+1β=βmm!(my1,,yd)j=1dpjyjpd+1β, P(y|p,\beta) = C_{m}^{\beta+m-1} C_{y_1, \ldots, y_d}^{m} \prod_{j=1}^d p_j^{y_j} p_{d+1}^\beta = \frac{\beta_m}{m!} {m \choose y_1, \ldots, y_d} \prod_{j=1}^d p_j^{y_j} p_{d+1}^\beta,

where m=j=1dyjm = \sum_{j=1}^d y_j. Here, CknC_k^n, often read as "nn choose kk", refers the number of kk combinations from a set of nn elements.

alpha is an alternative way to specify the probability:

pj=αj(1+k=1dαk)p_j = \frac{\alpha_j}{(1+\sum_{k=1}^{d} \alpha_k)}

for j=1,,dj=1,\ldots,d and pd+1=1(1+k=1dαk)p_{d+1} = \frac{1}{(1+\sum_{k=1}^{d} \alpha_k)}.

The parameter prob can be a vector and beta is a scalar; prob can also be a matrix with nn rows, and beta is a vector of length nn like the estimate from the regression function multiplied by the covariate matrix.

Value

dnegmn returns the value of log(P(yp,β))\log(P(y|p, \beta) ). When Y is a matrix of nn rows, the function returns a vector of length nn.

rnegmn returns a n×dn\times d matrix of the generated random observations.

Author(s)

Yiwen Zhang and Hua Zhou

Examples

###-----------------------###
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)


[Package MGLM version 0.2.1 Index]