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

Description Usage Arguments Details Value See Also Examples

View source: R/niw.mom.R

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

1
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(μ, Σ | λ, κ, Ψ, ν) is defined as

Σ \sim W^{-1}(Ψ, ν), \quad μ | Σ \sim N(λ, Σ/κ).

Note that cov(μ, Σ) = 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(Σ_{ij}, Σ_{kl})=Sigma$var[i,j,k,l].

See Also

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

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 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],]))

Example output

Loading required package: mvtnorm
       true         sim 
-0.04494216 -0.04225873 
        sim 
-0.02887313 

nicheROVER documentation built on June 4, 2021, 1:09 a.m.