Learn R Programming

bbricks (version 0.1.4)

sufficientStatistics.CatDirichlet: Sufficient statistics of a "CatDirichlet" object

Description

For following Categorical-Dirichlet model structure: $$pi|alpha \sim Dir(alpha)$$ $$x|pi \sim Categorical(pi)$$ Where Dir() is the Dirichlet distribution, Categorical() is the Categorical distribution. See ?dDir and dCategorical for the definitions of these distribution. The sufficient statistics of a set of samples x is:

  • the effective counts of each unique label in x. i.e. T(x)[i] = sum(uniqueLabels[i]

Usage

# S3 method for CatDirichlet
sufficientStatistics(obj, x, foreach = FALSE, ...)

Arguments

obj

A "CatDirichlet" object.

x

numeric,integer or character, samples of the Categorical distribution.

foreach

logical, specifying whether to return the sufficient statistics for each observation. Default FALSE.

...

Additional arguments to be passed to other inherited types.

Value

An object of class "ssCat", the sufficient statistics of a set of categorical samples. Or an object of the same class as x if foreach=TRUE.

References

Murphy, Kevin P. Machine learning: a probabilistic perspective. MIT press, 2012.

See Also

CatDirichlet, sufficientStatistics_Weighted.CatDirichlet

Examples

Run this code
# NOT RUN {
obj <- CatDirichlet(gamma=list(alpha=runif(26,1,2),uniqueLabels = letters))
x <- sample(letters,size = 20,replace = TRUE)
w <- runif(20)
sufficientStatistics(obj=obj,x=x)       #return the counts of each unique label
sufficientStatistics_Weighted(obj=obj,x=x,w=w) #return the weighted counts of each unique lable
sufficientStatistics(obj=obj,x=x,foreach = TRUE) #return the sample itself
# }

Run the code above in your browser using DataLab