dpostNIW | R Documentation |
dpostNIW evalutes the posterior Normal-IWishart density at (mu,Sigma). rpostNIW draws independent samples. This posterior corresponds to a Normal model for the data
x[i,] ~ N(mu,Sigma) iid i=1,...,n
under conjugate priors
mu | Sigma ~ N(mu0, g Sigma) Sigma ~ IW(nu0, S0)
dpostNIW(mu, Sigma, x, g=1, mu0=rep(0,length(mu)), nu0=nrow(Sigma)+1, S0,
logscale=FALSE)
rpostNIW(n, x, g=1, mu0=0, nu0, S0, precision=FALSE)
mu |
Vector of length p |
Sigma |
p x p positive-definite covariance matrix |
x |
n x p data matrix (individuals in rows, variables in columns) |
g |
Prior dispersion parameter for mu |
mu0 |
Prior mean for mu |
nu0 |
Prior degrees of freedom for Sigma |
S0 |
Prior scale matrix for Sigma, by default set to I/nu0 |
logscale |
set to TRUE to get the log-posterior density |
n |
Number of samples to draw |
precision |
If set to |
dpostNIW
returns the Normal-IW posterior density evaluated at
(mu,Sigma).
rpostNIW
returns a list with two elements. The first element are
posterior draws for the mean. The second element are posterior draws for
the covariance (or its inverse if precision==TRUE
). Only
lower-diagonal elements are returned (Sigma[lower.tri(Sigma,diag=TRUE)]
).
David Rossell
diwish
for the inverse Wishart prior density,
marginalNIW
for the integrated likelihood under a
Normal-IW prior
#Simulate data
x= matrix(rnorm(100),ncol=2)
#Evaluate posterior at data-generating truth
mu= c(0,0)
Sigma= diag(2)
dpostNIW(mu,Sigma,x=x,g=1,nu0=4,log=FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.