dIW | R Documentation |
Density generating function for the inverse Wishart distribution.
dIW(x, V = 1, nu = 1, marginal = FALSE)
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 ( |
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).
A list
containing
Numeric vector of quantiles originally passed to the function.
Numeric vector of densities.
Hadfield, J. 2015. MCMCglmm Course Notes. June 20, 2015.
MCMCglmm
, rIW
,
rpeIW
Other prior functions:
rpeIW()
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.