niw.mom: Mean and variance of the Normal-Inverse-Wishart distribution.

View source: R/niw.mom.R

niw.momR Documentation

Mean and variance of the Normal-Inverse-Wishart distribution.

Description

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.

Usage

niw.mom(lambda, kappa, Psi, nu)

Arguments

lambda

Location parameter. See 'Details'.

kappa

Scale parameter. See 'Details'.

Psi

Scale matrix. See 'Details'.

nu

Degrees of freedom. See 'Details'.

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.

Value

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].

See Also

rniw(), niw.coeffs(), niw.post().

Examples

# 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],]))

nicheROVER documentation built on Oct. 13, 2023, 5:10 p.m.