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

rwishart

Random Wishart matrix


Description

Generate a draw from a Wishart distribution.

Usage

rwishart(df, p = nrow(SqrtSigma), Sigma, SqrtSigma = diag(p))

Arguments

df

degrees of freedom. It has to be integer.

p

dimension of the matrix to simulate.

Sigma

the matrix parameter Sigma of the Wishart distribution.

SqrtSigma

a square root of the matrix parameter Sigma of the Wishart distribution. Sigma must be equal to crossprod(SqrtSigma).

Details

The Wishart is a distribution on the set of nonnegative definite symmetric matrices. Its density is

p(W) = c|W|^((n-p-1)/2) / |Sigma|^(n/2) exp(-tr(Sigma^(-1)W)/2)

where n is the degrees of freedom parameter df and c is a normalizing constant. The mean of the Wishart distribution is n Sigma and the variance of an entry is

Var(W[i,j]) = n (Sigma[i,j]^2 + Sigma[i,i] Sigma[j,j])

The matrix parameter, which should be a positive definite symmetric matrix, can be specified via either the argument Sigma or SqrtSigma. If Sigma is specified, then SqrtSigma is ignored. No checks are made for symmetry and positive definiteness of Sigma.

Value

The function returns one draw from the Wishart distribution with df degrees of freedom and matrix parameter Sigma or crossprod(SqrtSigma)

Warning

The function only works for an integer number of degrees of freedom.

Note

From a suggestion by B.Venables, posted on S-news

Author(s)

Giovanni Petris GPetris@uark.edu

References

Press (1982). Applied multivariate analysis.

Examples

rwishart(25, p = 3)
a <- matrix(rnorm(9), 3)
rwishart(30, SqrtSigma = a)
b <- crossprod(a)
rwishart(30, Sigma = b)

dlm

Bayesian and Likelihood Analysis of Dynamic Linear Models

v1.1-5
GPL (>= 2)
Authors
Giovanni Petris [aut, cre], Wally Gilks [ctb] (Author of original C code for ARMS)
Initial release
2018-05-30

We don't support your browser anymore

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