# sufficientStatistics_Weighted.DP: Weighted sufficient statistics of a "DP" object In bbricks: Bayesian Methods and Graphical Model Structures for Statistical Modeling

## Description

For following model structure:

pi|alpha \sim DP(alpha,U)

z|pi \sim Categorical(pi)

theta_z|psi \sim H0(psi)

x|theta_z,z \sim F(theta_z)

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. The choice of F() and H0() can be described by an arbitrary "BasicBayesian" object such as "GaussianGaussian","GaussianInvWishart","GaussianNIW", "GaussianNIG", "CatDirichlet", and "CatDP". See `?BasicBayesian` for definition of "BasicBayesian" objects, and see for example `?GaussianGaussian` for specific "BasicBayesian" instances. As a summary, An "DP" object is simply a combination of a "CatDP" object (see `?CatDP`) and an object of any "BasicBayesian" type.
The sufficient statistics of a set of samples x in a "DP" object is the same sufficient statistics of the "BasicBayesian" inside the "DP", see examples.

## Usage

 ```1 2``` ```## S3 method for class 'DP' sufficientStatistics_Weighted(obj, x, w, ...) ```

## Arguments

 `obj` A "DP" object. `x` Random samples of the "BasicBayesian" object. `w` numeric, sample weights. `...` Additional arguments to be passed to other inherited types.

## Value

Return the sufficient statistics of the corresponding BasicBayesian type, see examples.

## References

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

`DP`, `sufficientStatistics.DP`
 ```1 2 3 4 5 6 7 8``` ```obj1 <- DP(gamma=list(alpha=1,H0aF="GaussianNIW",parH0=list(m=1,k=1,v=1,S=1))) obj2 <- DP(gamma=list(alpha=1,H0aF="CatDirichlet",parH0=list(alpha=1,uniqueLabels=letters))) x1 <- rnorm(100) x2 <- sample(letters,100,replace = TRUE) w <- runif(100) sufficientStatistics_Weighted(obj = obj1,x=x1,w=w) sufficientStatistics_Weighted(obj = obj2,x=x2,w=w) sufficientStatistics_Weighted(obj = obj1,x=x1,w=w,foreach = TRUE) ```