categorical: The Categorical Distribution

Description Usage Arguments Details Value Author(s) See Also

Description

Density and random generation functions for the categorical distribution.

Usage

1
2
dcategorical(x, prob, log=FALSE)
rcategorical(n, prob)

Arguments

x

vector of integers between 1 and some integer K, inclusive.

prob

vector of probabilities such that sum(prob) = 1 and length(prob) = K.

log

logical; if TRUE, density is given as the log-density.

n

number of observations.

Details

The categorical distribution is a special case of the multinomial distribution with size 1. Values may be between 1 and some integer K, inclusive. If the random variable X is categorical with probability vector p of length K, then P(X=x) = p_x. The density is

f(x) = prod_k p_k^I(x=k) = p_x

where I(.) is the indicator function and k = 1,…,K.

Value

dcategorical gives the density and rcategorical generates random deviates.

Author(s)

Daniel Dvorkin

See Also

Multinom in package stats.


lcmix documentation built on May 31, 2017, 5 a.m.

Search within the lcmix package
Search all R packages, documentation and source code