| niw.mom | R Documentation |
This function computes the mean and variance of the Normal-Inverse-Wishart (NIW) distribution. Can be used to very quickly compute Bayesian point estimates for the conjugate NIW prior.
niw.mom(lambda, kappa, Psi, nu)
lambda |
Location parameter. See 'Details'. |
kappa |
Scale parameter. See 'Details'. |
Psi |
Scale matrix. See 'Details'. |
nu |
Degrees of freedom. See 'Details'. |
The NIW distribution p(\mu, \Sigma | \lambda, \kappa, \Psi, \nu) is defined as
\Sigma \sim W^{-1}(\Psi, \nu), \quad \mu | \Sigma \sim N(\lambda, \Sigma/\kappa).
Note that cov(\mu, \Sigma) = 0.
Returns a list with elements mu and Sigma, each containing lists with elements mean and var. For mu these elements are of size length(lambda) and c(length(lambda),length(lambda)). For Sigma they are of size dim(Psi) and c(dim(Psi), dim(Psi)), such that cov(\Sigma_{ij}, \Sigma_{kl})=Sigma$var[i,j,k,l].
rniw(), niw.coeffs(), niw.post().
# NIW parameters
d <- 3 # number of dimensions
lambda <- rnorm(d)
kappa <- 2
Psi <- crossprod(matrix(rnorm(d^2), d, d))
nu <- 10
# simulate data
niw.sim <- rniw(n = 1e4, lambda, kappa, Psi, nu)
# check moments
niw.mV <- niw.mom(lambda, kappa, Psi, nu)
# mean of mu
ii <- 1
c(true = niw.mV$mu$mean[ii], sim = mean(niw.sim$mu[,ii]))
# variance of Sigma
II <- c(1,2)
JJ <- c(2,3)
c(true = niw.mV$var[II[1],II[2],JJ[1],JJ[2]],
sim = cov(niw.sim$Sigma[II[1],II[2],], niw.sim$Sigma[JJ[1],JJ[2],]))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.