Learn R Programming

distr6 (version 1.3.6)

Categorical: Categorical Distribution Class

Description

Mathematical and statistical functions for the Categorical distribution, which is commonly used in classification supervised learning.

Value

Returns an R6 object inheriting from class SDistribution.

Constructor

Categorical$new(..., probs, decorators = NULL, verbose = FALSE)

Constructor Arguments

Argument Type Details
... ANY elements in the support Set. See details.
probs numeric vector of probabilities. See details.

decorators Decorator decorators to add functionality. See details.

Constructor Details

The Categorical distribution is parameterised with a series of elements for the support set and probs determining the probability of each category occurring. The length of the probability list should equal the number of elements. The probability vector is automatically normalised with $$probs = probs/sum(probs)$$ If no arguments are given, then defaults to one element '1' with probability one.

Public Variables

Variable Return
name Name of distribution.
short_name Id of distribution.
description Brief description of distribution.

Public Methods

Accessor Methods Link
decorators decorators
traits traits
valueSupport valueSupport
variateForm variateForm
type type
properties properties
support support
symmetry symmetry
sup sup
inf inf
dmax dmax
dmin dmin
skewnessType skewnessType
kurtosisType kurtosisType

Statistical Methods Link pdf(x1, ..., log = FALSE, simplify = TRUE) pdf cdf(x1, ..., lower.tail = TRUE, log.p = FALSE, simplify = TRUE) cdf quantile(p, ..., lower.tail = TRUE, log.p = FALSE, simplify = TRUE) quantile.Distribution rand(n, simplify = TRUE) rand mean() mean.Distribution variance() variance stdev() stdev prec() prec cor() cor skewness() skewness kurtosis(excess = TRUE) kurtosis entropy(base = 2) entropy mgf(t) mgf cf(t) cf pgf(z) pgf median() median.Distribution iqr() iqr mode(which = "all") mode

Parameter Methods Link parameters(id) parameters getParameterValue(id, error = "warn") getParameterValue setParameterValue(..., lst = NULL, error = "warn") setParameterValue

Validation Methods Link liesInSupport(x, all = TRUE, bound = FALSE) liesInSupport liesInType(x, all = TRUE, bound = FALSE) liesInType

Representation Methods Link strprint(n = 2) strprint print(n = 2) print summary(full = T) summary.Distribution

Details

The Categorical distribution parameterised with a given support set, \(x_1,...,x_k\), and respective probabilities, \(p_1,...,p_k\), is defined by the pmf, $$f(x_i) = p_i$$ for \(p_i, i = 1,\ldots,k; \sum p_i = 1\).

The distribution is supported on \(x_1,...,x_k\).

Only the mode, pdf, cdf, quantile and rand are available for this Distribution, all other methods return NaN. Sampling from this distribution is performed with the sample function with the elements given as the support set and the probabilities from the probs parameter. The cdf and quantile assumes that the elements are supplied in an indexed order (otherwise the results are meaningless).

References

McLaughlin, M. P. (2001). A compendium of common probability distributions (pp. 2014-01). Michael P. McLaughlin.

See Also

listDistributions for all available distributions. sample for the sampling function.

Examples

Run this code
# NOT RUN {
# Note probabilities are automatically normalised
x = Categorical$new("Bapple","Banana",2,probs=c(0.2,0.4,1))

# Only the probabilities can be changed and must the same length as in construction
x$setParameterValue(probs = c(0.1,0.2,0.7))

# d/p/q/r
x$pdf(c("Bapple", "Carrot", 1, 2))
x$cdf("Banana") # Assumes ordered in construction
x$quantile(0.42) # Assumes ordered in construction
x$rand(10)

# Statistics
x$mode()

summary(x)

# }

Run the code above in your browser using DataLab