posterior.CatDP: Update a "CatDP" object with sample sufficient statistics

Description Usage Arguments Value References See Also Examples

View source: R/Dirichlet_Process.r

Description

For the model structure:

pi|alpha \sim DP(alpha,U)

x|pi \sim Categorical(pi)

where DP(alpha,U) is a Dirichlet Process on positive integers, alpha is the "concentration parameter" of the Dirichlet Process, U is the "base measure" of this Dirichlet process, it is an uniform distribution on all positive integers.Categorical() is the Categorical distribution. See dCategorical for the definition of the Categorical distribution.
In the case of CatDP, x can only be positive integers.
Update prior knowledge by adding the information of newly observed samples x. The model structure and prior parameters are stored in a "CatDP" object, the prior parameters in this object will be updated after running this function.

Usage

1
2
## S3 method for class 'CatDP'
posterior(obj, ss, w = NULL, ...)

Arguments

obj

A "CatDP" object.

ss

Sufficient statistics of x. In Categorical-DP case the sufficient statistic of sample x can either be an object of type "ssCatDP" generated by sufficientStatistics(), or x itself(if x is a integer vector with all positive values).

w

Sample weights, default NULL.

...

Additional arguments to be passed to other inherited types.

Value

None. the model stored in "obj" will be updated based on "ss".

References

Teh, Yee W., et al. "Sharing clusters among related groups: Hierarchical Dirichlet processes." Advances in neural information processing systems. 2005.

See Also

CatDP,posteriorDiscard.CatDP,sufficientStatistics.CatDP

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
## generate some integer samples
x <- sample(1L:10L,size = 40,replace = TRUE)
obj <- CatDP()
obj2 <- CatDP()
obj3 <- CatDP()
## update CatDP object with sufficient statistics
ss <- sufficientStatistics(obj=obj,x=x)
posterior(obj = obj,ss = ss)
## or, update with x itself
posterior(obj = obj2,ss = x)
## or, update with x itself, one by one
for(xx in x) posterior(obj = obj3,ss = xx)
## obj, obj2, obj3 should be the same:
obj
obj2
obj3

bbricks documentation built on July 8, 2020, 7:29 p.m.