Compute the density of an observation of a random Wishart distributed matrix
(dWishart
) or an observation
from the inverse Wishart distribution (dInvWishart
).
dWishart(x, df, Sigma, log = TRUE) dInvWishart(x, df, Sigma, log = TRUE)
x | positive definite \(p \times p\) observations for density estimation - either one matrix or a 3-D array. |
---|---|
df | numeric parameter, "degrees of freedom". |
Sigma | positive definite \(p \times p\) "scale" matrix, the matrix parameter of the distribution. |
log | logical, whether to return value on the log scale. |
Density or log of density
Note there are different ways of parameterizing the Inverse Wishart distribution, so check which one you need. Here, If \(X \sim IW_p(\Sigma, \nu)\) then \(X^{-1} \sim W_p(\Sigma^{-1}, \nu)\). Dawid (1981) has a different definition: if \(X \sim W_p(\Sigma^{-1}, \nu)\) and \(\nu > p - 1\), then \(X^{-1} = Y \sim IW(\Sigma, \delta)\), where \(\delta = \nu - p + 1\).
dInvWishart
: density for the inverse Wishart distribution.
Dawid, A. (1981). Some Matrix-Variate Distribution Theory: Notational Considerations and a Bayesian Application. Biometrika, 68(1), 265-274. doi: 10.2307/2335827
Gupta, A. K. and D. K. Nagar (1999). Matrix variate distributions. Chapman and Hall.
Mardia, K. V., J. T. Kent, and J. M. Bibby (1979) Multivariate Analysis, London: Academic Press.
set.seed(20180222) A <- rWishart(1, 10, diag(4))[, , 1] A #> [,1] [,2] [,3] [,4] #> [1,] 8.70459209 -0.21410794 -0.05424324 8.81416710 #> [2,] -0.21410794 10.66557858 5.22611563 -0.09148444 #> [3,] -0.05424324 5.22611563 12.65126374 1.50127740 #> [4,] 8.81416710 -0.09148444 1.50127740 16.84890844 dWishart(x = A, df = 10, Sigma = diag(4L), log = TRUE) #> [1] -28.14864 dInvWishart(x = solve(A), df = 10, Sigma = diag(4L), log = TRUE) #> [1] 16.26773