Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

wishart

Wishart Distribution


Description

Density and random generation for the Wishart distribution.

Usage

dWishart(W, Sigma, nu, logscale = FALSE)
rWishart(nu, scale.matrix, inverse = FALSE)

Arguments

W

Argument (random variable) for the Wishart density. A symmetric positive definite matrix.

Sigma

Scale or "variance" parameter of the Wishart distribution. See the "details" section below.

nu

The "degrees of freedom" parameter of the Wishart distribution. The distribution is only defined for nu >= nrow(W) - 1.

logscale

Logical. If TRUE then the density is returned on the log scale. Otherwise the density is returned on the density scale.

scale.matrix

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.

inverse

Logical. If TRUE then simulate from the inverse Wishart distribution. If FALSE then simulate from the Wishart distribution.

Details

If nu is an integer then a W(Sigma, nu) random variable can be thought of as the sum of nu outer products: outer(y), where y is a zero-mean multivariate normal with variance matrix Sigma.

The Wishart distribution is

det(W)^((nu-p-1)/2) * exp(-trace(solve(Sigma, W))) / (2^(nu * p / 2) * det(Sigma)^(nu / 2) * Gamma(nu/2, p))

where p == nrow(W) and Gamma(nu, p) is the multivariate gamma function (see lmgamma).

Value

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.

Author(s)


Boom

Bayesian Object Oriented Modeling

v0.9.7
LGPL-2.1 | file LICENSE
Authors
Steven L. Scott is the sole author and creator of the BOOM project. Some code in the BOOM libraries has been modified from other open source projects. These include Cephes (obtained from Netlib, written by Stephen L. Moshier), NEWUOA (M.J.D Powell, obtained from Powell's web site), and a modified version of the R math libraries (R core development team). Original copyright notices have been maintained in all source files. In these cases, copyright claimed by Steven L. Scott is limited to modifications made to the original code. Google claims copyright for code written while Steven L. Scott was employed at Google from 2008 - 2018, but BOOM is not an officially supported Google project.
Initial release
2021-02-15

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.