Mean and variance of the Normal-Inverse-Wishart distribution.
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(μ, Σ | λ, κ, Ψ, ν) is defined as
Σ \sim W^{-1}(Ψ, ν), \quad μ | Σ \sim N(λ, Σ/κ).
Note that cov(μ, Σ) = 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(Σ_{ij}, Σ_{kl})=Sigma$var[i,j,k,l]
.
# 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],]))
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.