Skip to contents

The multinomial distribution is a discrete probability distribution which models the probability of having x successes in n independent categorical trials with success probability vector p.

Usage

Multinom(size = 1, prob = c(0.5, 0.5))

# S4 method for class 'Multinom,numeric'
d(distr, x, log = FALSE)

# S4 method for class 'Multinom,numeric'
r(distr, n)

# S4 method for class 'Multinom'
mean(x)

# S4 method for class 'Multinom'
mode(x)

# S4 method for class 'Multinom'
var(x)

# S4 method for class 'Multinom'
entro(x)

# S4 method for class 'Multinom'
finf(x)

llmultinom(x, size, prob)

# S4 method for class 'Multinom,matrix'
ll(distr, x)

emultinom(x, type = "mle", ...)

# S4 method for class 'Multinom,matrix'
mle(distr, x, na.rm = FALSE)

# S4 method for class 'Multinom,matrix'
me(distr, x, na.rm = FALSE)

vmultinom(size, prob, type = "mle")

# S4 method for class 'Multinom'
avar_mle(distr)

# S4 method for class 'Multinom'
avar_me(distr)

Arguments

size

number of trials (zero or more).

prob

numeric. Probability of success on each trial.

distr

an object of class Multinom.

x

For the density function, x is a numeric vector of quantiles. For the moments functions, x is an object of class Multinom. For the log-likelihood and the estimation functions, x is the sample of observations.

log

logical. Should the logarithm of the probability be returned?

n

number of observations. If length(n) > 1, the length is taken to be the number required.

type

character, case ignored. The estimator type (mle or me).

...

extra arguments.

na.rm

logical. Should the NA values be removed?

Value

Each type of function returns a different type of object:

  • Distribution Functions: When supplied with one argument (distr), the d(), p(), q(), r(), ll() functions return the density, cumulative probability, quantile, random sample generator, and log-likelihood functions, respectively. When supplied with both arguments (distr and x), they evaluate the aforementioned functions directly.

  • Moments: Returns a numeric, either vector or matrix depending on the moment and the distribution. The moments() function returns a list with all the available methods.

  • Estimation: Returns a list, the estimators of the unknown parameters. Note that in distribution families like the binomial, multinomial, and negative binomial, the size is not returned, since it is considered known.

  • Variance: Returns a named matrix. The asymptotic covariance matrix of the estimator.

Details

The probability mass function (PMF) of the Multinomial distribution is: $$ P(X_1 = x_1, ..., X_k = x_k) = \frac{n!}{x_1! x_2! ... x_k!} \prod_{i=1}^k p_i^{x_i}, $$ subject to \( \sum_{i=1}^{k} x_i = n \).

See also

Functions from the stats package: dmultinom(), rmultinom()

Examples

# -----------------------------------------------------
# Multinomial Distribution Example
# -----------------------------------------------------

# Create the distribution
N <- 10 ; p <- c(0.1, 0.2, 0.7)
D <- Multinom(N, p)

# ------------------
# dpqr Functions
# ------------------

d(D, c(2, 3, 5)) # density function
#> [1] 0.03388291

# alternative way to use the function
df <- d(D) ; df(c(2, 3, 5)) # df is a function itself
#> [1] 0.03388291

x <- r(D, 100) # random generator function

# ------------------
# Moments
# ------------------

mean(D) # Expectation
#> [1] 1 2 7
mode(D) # Mode
#> [1] 3
var(D) # Variance
#>      [,1] [,2] [,3]
#> [1,]  0.9 -0.2 -0.7
#> [2,] -0.2  1.6 -1.4
#> [3,] -0.7 -1.4  2.1
entro(D) # Entropy
#> [1] 2.885135
finf(D) # Fisher Information Matrix
#>           prob1     prob2
#> prob1  85.71429 -14.28571
#> prob2 -14.28571  35.71429

# List of all available moments
mom <- moments(D)
mom$mean # expectation
#> [1] 1 2 7

# ------------------
# Point Estimation
# ------------------

ll(D, x)
#> [1] -292.1644
llmultinom(x, N, p)
#> [1] -292.1644

emultinom(x, type = "mle")
#> $prob
#> [1] 0.099 0.189 0.712
#> 
emultinom(x, type = "me")
#> $prob
#> [1] 0.099 0.189 0.712
#> 

mle(D, x)
#> $prob
#> [1] 0.099 0.189 0.712
#> 
me(D, x)
#> $prob
#> [1] 0.099 0.189 0.712
#> 
e(D, x, type = "mle")
#> $prob
#> [1] 0.099 0.189 0.712
#> 

mle("multinom", x) # the distr argument can be a character
#> $prob
#> [1] 0.099 0.189 0.712
#> 

# ------------------
# Estimator Variance
# ------------------

vmultinom(N, p, type = "mle")
#>        prob1 prob2
#> prob1 0.0125 0.005
#> prob2 0.0050 0.030
vmultinom(N, p, type = "me")
#>        prob1 prob2
#> prob1 0.0125 0.005
#> prob2 0.0050 0.030

avar_mle(D)
#>        prob1 prob2
#> prob1 0.0125 0.005
#> prob2 0.0050 0.030
avar_me(D)
#>        prob1 prob2
#> prob1 0.0125 0.005
#> prob2 0.0050 0.030

v(D, type = "mle")
#>        prob1 prob2
#> prob1 0.0125 0.005
#> prob2 0.0050 0.030