rmn {MGLM}R Documentation

The Multinomial Distribution

Description

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.

Usage

rmn(n, size, alpha)

dmn(Y, prob)

Arguments

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×dn \times d, where n=1,2,n = 1,2,\ldots is number of observations and d=2,d=2,\ldots is number of categories.

prob

the probability parameter of the multinomial distribution. prob can be either a vector of length dd 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. If the sum(s) of prob is not 1, it will be automatically scaled to have sum 1.

Details

A multinomial distribution models the counts of dd possible outcomes. The counts of categories are negatively correlated. y=(y1,,yd)y=(y_1, \ldots, y_d) is a dd category count vector. Given the parameter vector p=(p1,,pd)p = (p_1, \ldots, p_d), 0<pj<10 < p_j < 1, j=1dpj=1\sum_{j=1}^d p_j = 1, the function calculates the log of the multinomial pmf

P(yp)=Cy1,,ydmj=1dpjyj, P(y|p) = C_{y_1, \ldots, y_d}^{m} \prod_{j=1}^{d} p_j^{y_j},

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.

The parameter pp can be one vector, like the result from the distribution fitting function; or, pp can be a matrix with nn rows, like the estimate from the regression function,

pj=exp(Xβj)1+sumj=1d1exp(Xβj),p_j = \frac{exp(X \beta_j)}{1 + sum_{j'=1}^{d-1} exp(X\beta_{j'})},

where j=1,,d1j=1,\ldots,d-1 and pd=11+j=1d1exp(Xβj)p_d = \frac{1}{1 + \sum_{j'=1}^{d-1} exp(X\beta_{j'})}. The dd-th column of the coefficient matrix β\beta is set to 00 to avoid the identifiability issue.

Value

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

The function rmn returns multinomially distributed random number vectors

Author(s)

Yiwen Zhang and Hua Zhou

Examples

m <- 20
prob <- c(0.1, 0.2)
dm.Y <- rdirmn(n=10, m, prob)	
pdfln <- dmn(dm.Y, prob)

[Package MGLM version 0.2.1 Index]