Generate n random matrices, distributed according
to the inverse Wishart distribution with parameters Sigma
and
df
, \(W_p(Sigma, df)\).
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\).
rInvWishart(n, df, Sigma)
a numeric array, say R
, of dimension
\(p \times p \times n\),
where each R[,,i]
is a realization of the inverse Wishart distribution
\(IW_p(Sigma, df)\).
Based on a modification of the existing code for the rWishart
function.
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(20180221)
A <- rInvWishart(1L, 10, 5 * diag(5L))[, , 1]
set.seed(20180221)
B <- stats::rWishart(1L, 10, .2 * diag(5L))[, , 1]
A %*% B
#> [,1] [,2] [,3] [,4] [,5]
#> [1,] 1.000000e+00 4.780710e-17 -5.775969e-17 1.270195e-16 4.441151e-17
#> [2,] 2.076917e-17 1.000000e+00 -4.028034e-17 2.642691e-16 7.929804e-17
#> [3,] -8.992634e-17 -5.322340e-17 1.000000e+00 -1.298779e-16 2.514746e-17
#> [4,] 7.787488e-17 1.338887e-16 2.715793e-17 1.000000e+00 9.171614e-19
#> [5,] 1.938556e-16 2.752030e-16 7.210773e-17 3.054895e-16 1.000000e+00