Density and random generation for the Wishart distribution.
dWishart(W, Sigma, nu, logscale = FALSE)
rWishart(nu, scale.matrix, inverse = FALSE)
dWishart
returns the density of the Wishart distribution. It
is not vectorized, so only one random variable (matrix) can be
evaluated at a time.
rWishart
returns one or more draws from the Wishart or inverse
Wishart distributions. If n > 0
the result is a 3-way array.
Unlike the rWishart
function from the stats
package, the first index corresponds to draws. This is in keeping
with the convention of other models from the Boom package.
Argument (random variable) for the Wishart density. A symmetric positive definite matrix.
Scale or "variance" parameter of the Wishart distribution. See the "details" section below.
The "degrees of freedom" parameter of the Wishart
distribution. The distribution is only defined for nu >=
nrow(W) - 1
.
Logical. If TRUE
then the density is returned
on the log scale. Otherwise the density is returned on the density
scale.
For the Wishart distribution the
scale.matrix
parameter means the same thing as the
Sigma
parameter in dWishart
. It is the variance
parameter of the generating multivariate normal distribution.
If simulating from the inverse Wishart, scale.matrix
is the
INVERSE of the "sum of squares" matrix portion of the multivariate
normal sufficient statistics.
Logical. If TRUE then simulate from the inverse Wishart distribution. If FALSE then simulate from the Wishart distribution.
Steven L. Scott steve.the.bayesian@gmail.com
If nu
is an integer then a \(W(\Sigma, \nu)\)
random variable can be thought of as the sum of nu
outer
products: \(y_iy_i^T\), where \(y_i\) is a zero-mean
multivariate normal with variance matrix Sigma
.
The Wishart distribution is
$$ \frac{|W|^{\frac{\nu - p - 1}{2}} \exp(-tr(\Sigma^{-1}W) / 2)}{
2^{\frac{\nu p}{2}}|\Sigma|^{\frac{\nu}{2}}\Gamma_p(\nu / 2)}%
$$
where p == nrow(W)
and \(\Gamma_p(\nu)\) is the
multivariate gamma function (see lmgamma
).