# dNIW: Density function for Normal-Inverse-Wishart (NIW)... In bbricks: Bayesian Methods and Graphical Model Structures for Statistical Modeling

## Description

Get the density of a NIW sample. For a random vector mu, and a random matrix Sigma, the density function is defined as:

sqrt(2 pi^p |Sigma/k|)^{-1} exp(-1/2 (mu-m )^T (Sigma/k)^{-1} (mu-m)) (2^{(v p)/2} Gamma_p(v/2) |S|^{-v/2})^{-1} |Sigma|^{(-v-p-1)/2} exp(-1/2 tr(Sigma^{-1} S))

Where p is the dimension of mu and Sigma.

## Usage

 `1` ```dNIW(mu, Sigma, m, k, v, S, LOG = TRUE) ```

## Arguments

 `mu` numeric, the Gaussian sample. `Sigma` matrix, a symmetric positive definite matrix, the Inverse-Wishart sample. `m` numeric, mean of mu. `k` numeric, precision of mu. `v` numeric, degree of freedom of Sigma. `S` numeric, a symmetric positive definite scale matrix of Sigma, S is proportional to E(Sigma). `LOG` logical, return log density of LOG=TRUE, default TRUE.

## Value

A numeric vector, the probability density of (mu,Sigma).

## References

O'Hagan, Anthony, and Jonathan J. Forster. Kendall's advanced theory of statistics, volume 2B: Bayesian inference. Vol. 2. Arnold, 2004.

MARolA, K. V., JT KBNT, and J. M. Bibly. Multivariate analysis. AcadeInic Press, Londres, 1979.

`rNIW`
 ```1 2 3 4 5``` ```S <- crossprod(matrix(rnorm(15),5,3)) Sigma <- crossprod(matrix(rnorm(15),5,3)) mu <- runif(3) m <- runif(3) dNIW(mu=mu,Sigma=Sigma,m=m,k=2,v=4,S=S,LOG = TRUE) ```