Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

niw.mom

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

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

(Niche) (R)egion and Niche (Over)lap Metrics for Multidimensional Ecological Niches

v1.0
GPL-2
Authors
Martin Lysy [aut, cre], Ashley D. Stasko [aut, ctb], Heidi K. Swanson [aut, ctb]
Initial release
2014-07-21

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.