dIW: Inverse Wishart (co)variance density.

View source: R/priors.R

dIWR Documentation

Inverse Wishart (co)variance density.

Description

Density generating function for the inverse Wishart distribution.

Usage

dIW(x, V = 1, nu = 1, marginal = FALSE)

Arguments

x

Vector of quantiles.

V

Numeric matrix of the expected (co)variances

nu

Numeric for the degree of belief parameter for the inverse- Wishart.

marginal

Logical indicating whether the densities for a single variance (FALSE) or the marginal densities of the first variance in a covariance matrix V[1, 1] (TRUE) are to be returned.

Details

When V = 1, the inverse Wishart distribution is equivalent to an inverse Gamma distribution with shape and scale parameters set to nu / 2. In other words, the inverse Gamma is a special case of the inverse Wishart (Hadfield 2015, p. 12), where the inverse Wishart is the multivariate generalization of the inverse Gamma distribution.

As nu goes to infinity, the point mass moves towards V. The mode of the distributions is calculated by (V * nu) / (nu + 2) (Hadfield 2015, p. 12).

Value

A list containing

x

Numeric vector of quantiles originally passed to the function.

y

Numeric vector of densities.

Author(s)

matthewwolak@gmail.com

References

Hadfield, J. 2015. MCMCglmm Course Notes. June 20, 2015.

See Also

MCMCglmm, rIW, rpeIW

Other prior functions: rpeIW()

Examples

xseq <- seq(from = 1e-16, to = 5, length = 1000)
# Plot range of prior distributions
## start with inverse Gamma with small degree of belief and point mass ~ 0
IG0.002 <- dIW(xseq, V = 1, nu = 0.002)
IG0.02 <- dIW(xseq, V = 1, nu = 0.02)
IG0.2 <- dIW(xseq, V = 1, nu = 0.2)
## end with point mass near V
IG1 <- dIW(xseq, V = 1, nu = 1)
plot(IG0.002, type = "n",
  main = "Inverse Gamma\nV = 1",
  xlab = "Variance", ylab = "Density",
  xlim = c(0, max(xseq)),
  ylim = c(0, max(c(IG0.002$y, IG0.02$y, IG0.2$y, IG1$y))))
 lines(IG0.02, lwd = 2, col = "red")
 lines(IG0.2, lwd = 2, col = "blue")
 lines(IG1, lwd = 2, col = "grey40")
 lines(IG0.002, lwd = 3, col = "black")
 legend("topright", lwd = 2, col = c("black", "red", "blue", "grey40"),
	title = "nu", legend = as.character(c(0.002, 0.02, 0.2, 1)),
	inset = 0.01)

#######################
# Marginal variance
#######################
mar1 <- dIW(xseq, V = diag(2), nu = 1.002, marginal = TRUE)
# compare to IG0.002 above
plot(mar1, type = "n",
  main = "Marginal prior for a variance:\n IW(V = diag(2), nu = 1.002)",
  xlab = "Variance", ylab = "Density",
  xlim = c(0, max(xseq)), ylim = c(0, max(c(mar1$y, IG0.002$y))))
 lines(mar1, lwd = 2, col = "red")
 lines(IG0.002, lwd = 2, col = "black")
 legend("topright", col = c("red", "black"), lwd = 2,
	legend = c("marginal prior",
		"univariate prior\nIG(V=1, nu=0.002)"),
	inset = 0.01)

matthewwolak/wolakR documentation built on May 10, 2023, 1:27 p.m.