# dPosteriorPredictive.HDP2: Posterior predictive density function of a "HDP2" object In bbricks: Bayesian Methods and Graphical Model Structures for Statistical Modeling

## Description

Generate the the density value of the posterior predictive distribution of the following structure:

G |eta \sim DP(eta,U)

G_m|gamma,G \sim DP(gamma,G), m = 1:M

pi_{mj}|G_m,alpha \sim DP(alpha,G_m), j = 1:J_m

z|pi_{mj} \sim Categorical(pi_{mj})

k|z,G_m \sim Categorical(G_m),\textrm{ if z is a sample from the base measure }G_{mj}

u|k,G \sim Categorical(G),\textrm{ if k is a sample from the base measure G}

theta_u|psi \sim H0(psi)

x|theta_u,u \sim F(theta_u)

where DP(eta,U) is a Dirichlet Process on positive integers, eta is the "concentration parameter", U is the "base measure" of this Dirichlet process, U is an uniform distribution on all positive integers. DP(gamma,G) is a Dirichlet Process on integers with concentration parameter gamma and base measure G. DP(alpha,G_m) is a Dirichlet Process on integers with concentration parameter alpha and base measure G_m. 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 "HDP2" object is simply a combination of a "CatHDP2" object (see `?CatHDP2`) and an object of any "BasicBayesian" type.
In the case of HDP2, u, z and k can only be positive integers.
The model structure and prior parameters are stored in a "HDP2" object.
Posterior predictive density = p(u,z,k,x|eta,gamma,alpha,psi) when x is not NULL, or p(u,z,k|eta,gamma,alpha,psi) when x is NULL.

## Usage

 ```1 2``` ```## S3 method for class 'HDP2' dPosteriorPredictive(obj, x = NULL, u, k, z, m, j, LOG = TRUE, ...) ```

## Arguments

 `obj` A "HDP2" object. `x` Random samples of the "BasicBayesian" object. `u` integer, the partition label of the parameter space where the observation x is drawn from. `k` integer. `z` integer. `m` integer, group label. `j` integer, subgroup label. `LOG` Return the log density if set to "TRUE". `...` Additional arguments to be passed to other inherited types.

## Value

A numeric vector, the posterior predictive density.

## References

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

`HDP2`, `dPosteriorPredictive.HDP2`, `marginalLikelihood.HDP2`