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

niw.coeffs

Posterior coefficients of the Normal-Inverse-Wishart distribution with its conjugate prior.


Description

Given iid d-dimensional niche indicators X = (X_1,…,X_N) with X_i \sim N(μ, Σ), this function calculates the coefficients of the Normal-Inverse-Wishart (NIW) posterior p(μ, Σ | X) for a conjugate NIW prior. Together with niw.mom, this can be used to rapidly compute the point estimates E[μ | X] and E[Σ | X].

Usage

niw.coeffs(X, lambda, kappa, Psi, nu)

Arguments

X

a data matrix with observations along the rows.

lambda

location parameter. See Details.

kappa

scale parameter. Defaults to kappa = 0. See Details.

Psi

scale matrix. Defaults to Psi = 0. See Details.

nu

degrees of freedom. Defaults to nu = ncol(X)+1. See Details.

Details

The NIW distribution p(μ, Σ | λ, κ, Ψ, ν) is defined as

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

The default value kappa = 0 uses the Lebesque prior on μ: p(μ) \propto 1. The default value Psi = 0 uses the scale-invariant prior on Σ: p(Σ) \propto |Σ|^{-(ν+d+1)/2}. The default value nu = ncol(X)+1 for kappa = 0 and Psi = 0 makes E[μ|X]=\code{colMeans(X)} and E[Σ | X]=\code{var(X)}.

Value

Returns a list with elements lambda, kappa, Psi, nu corresponding to the coefficients of the NIW posterior distribution p(μ, Σ | X).

See Also

Examples

# NIW prior coefficients
d <- 3
lambda <- rnorm(d)
kappa <- 5
Psi <- crossprod(matrix(rnorm(d^2), d, d))
nu <- 10

# data
data(fish)
X <- fish[fish$species == "ARCS",2:4]

# NIW posterior coefficients
post.coef <- niw.coeffs(X, lambda, kappa, Psi, nu)

# compare
mu.mean <- niw.mom(post.coef$lambda, post.coef$kappa, post.coef$Psi, post.coef$nu)$mu$mean
mu.est <- rbind(prior = niw.mom(lambda, kappa, Psi, nu)$mu$mean,
               data = colMeans(X),
               post = mu.mean)
round(mu.est, 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.