# dPosterior: Get the density from the posterior distribution. In bbricks: Bayesian Methods and Graphical Model Structures for Statistical Modeling

## Description

This is a generic function that will generate the the density value of the posterior distribution. i.e. for the model structure:

theta|gamma \sim H(gamma)

x|theta \sim F(theta)

get the probability density/mass from the distribution theta \sim H(gamma). For a given Bayesian bricks object obj and an observation of theta, `dPosterior()` will calculate the density value for different model structures:

#### class(obj)="LinearGaussianGaussian"

Where

x \sim Gaussian(A z + b, Sigma)

z \sim Gaussian(m,S)

`dPosterior()` will return p(theta|m,S) See `?dPosterior.LinearGaussianGaussian` for details.

#### class(obj)="GaussianGaussian"

Where

x \sim Gaussian(mu,Sigma)

mu \sim Gaussian(m,S)

Sigma is known. `dPosterior()` will return p(mu|m,S) See `?dPosterior.GaussianGaussian` for details.

#### class(obj)="GaussianInvWishart"

Where

x \sim Gaussian(mu,Sigma)

Sigma \sim InvWishart(v,S)

mu is known. `dPosterior()` will return p(Sigma|v,S) See `?dPosterior.GaussianInvWishart` for details.

#### class(obj)="GaussianNIW"

Where

x \sim Gaussian(mu,Sigma)

Sigma \sim InvWishart(v,S)

mu \sim Gaussian(m,Sigma/k)

`dPosterior()` will return p(mu,Sigma|m,k,v,S) See `?dPosterior.GaussianNIW` for details.

#### class(obj)="GaussianNIG"

Where

x \sim Gaussian(X beta,sigma^2)

sigma^2 \sim InvGamma(a,b)

beta \sim Gaussian(m,sigma^2 V)

X is a row vector, or a design matrix where each row is an obervation. `dPosterior()` will return p(beta,sigma^2|m,V,a,b) See `?dPosterior.GaussianNIG` for details.

#### class(obj)="CatDirichlet"

Where

x \sim Categorical(pi)

pi \sim Dirichlet(alpha)

`dPosterior()` will return p(pi|alpha) See `?dPosterior.CatDirichlet` for details.

## Usage

 `1` ```dPosterior(obj, ...) ```

## Arguments

 `obj` A "BayesianBrick" object used to select a method. `...` further arguments passed to or from other methods.

## Value

numeric, the density value

`dPosterior.LinearGaussianGaussian` for Linear Gaussian and Gaussian conjugate structure, `dPosterior.GaussianGaussian` for Gaussian-Gaussian conjugate structure, `dPosterior.GaussianInvWishart` for Gaussian-Inverse-Wishart conjugate structure, `dPosterior.GaussianNIW` for Gaussian-NIW conjugate structure, `dPosterior.GaussianNIG` for Gaussian-NIG conjugate structure, `dPosterior.CatDirichlet` for Categorical-Dirichlet conjugate structure ...