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 |
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 |
alpha |
an alternative way to specify the probability. Default value is |
Details
is a
category vector. Given the parameter vector
,
,
and
,
, the negative multinomial probability mass function is
where . Here,
, often read as "
choose
",
refers the number of
combinations from a set of
elements.
alpha
is an alternative way to specify the probability:
for and
.
The parameter prob
can be a vector and beta
is a scalar; prob
can also
be a matrix with rows, and
beta
is a vector of length
like the estimate from the regression function
multiplied by the covariate matrix.
Value
dnegmn
returns the value of
. When
Y
is a matrix of rows, the function
returns a vector of length
.
rnegmn
returns a 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)