This is the density and random deviates function for the categorical distribution with probabilities parameter \(p\).
dcat(x, p, log=FALSE)
qcat(pr, p, lower.tail=TRUE, log.pr=FALSE)
rcat(n, p)
This is a vector of discrete data with \(k\) discrete
categories, and is of length \(n\). This function also accepts
\(x\) after it has been converted to an \(n \times k\)
indicator matrix, such as with the as.indicator.matrix
function.
This is the number of observations, which must be a positive
integer that has length 1. When p
is supplied to rcat
as a matrix, n
must equal the number of rows in p
.
This is a vector of length \(k\) or \(n \times k\)
matrix of probabilities. The qcat
function requires a
vector.
This is a vector of probabilities, or log-probabilities.
Logical. If log=TRUE
, then the logarithm of the
density is returned.
Logical. if TRUE
, probabilities \(pr\) are
given as \(\log(pr)\).
Logical. if TRUE
(default), probabilities
are \(Pr[X \le x]\), otherwise,
\(Pr[X > x]\).
dcat
gives the density and
rcat
generates random deviates.
Application: Discrete Univariate
Density: \(p(\theta) = \sum \theta p\)
Inventor: Unknown (to me, anyway)
Notation 1: \(\theta \sim \mathcal{CAT}(p)\)
Notation 2: \(p(\theta) = \mathcal{CAT}(\theta | p)\)
Parameter 1: probabilities \(p\)
Mean: \(E(\theta)\) = Unknown
Variance: \(var(\theta)\) = Unknown
Mode: \(mode(\theta)\) = Unknown
Also called the discrete distribution, the categorical distribution describes the result of a random event that can take on one of \(k\) possible outcomes, with the probability \(p\) of each outcome separately specified. The vector \(p\) of probabilities for each event must sum to 1. The categorical distribution is often used, for example, in the multinomial logit model. The conjugate prior is the Dirichlet distribution.
# NOT RUN {
library(LaplacesDemon)
dcat(x=1, p=c(0.3,0.3,0.4))
rcat(n=10, p=c(0.1,0.3,0.6))
# }
Run the code above in your browser using DataLab