rWishart {stats}R Documentation

Random Wishart Distributed Matrices

Description

Generate n random matrices, distributed according to the Wishart distribution with parameters Sigma and df, Wp(Σ,m), m=df, Σ=SigmaW_p(\Sigma, m),\ m=\code{df},\ \Sigma=\code{Sigma}.

Usage

rWishart(n, df, Sigma)

Arguments

n

integer sample size.

df

numeric parameter, “degrees of freedom”.

Sigma

positive definite (p×pp\times p) “scale” matrix, the matrix parameter of the distribution.

Details

If X1,,Xm, XiRpX_1,\dots, X_m, \ X_i\in\mathbf{R}^p is a sample of mm independent multivariate Gaussians with mean (vector) 0, and covariance matrix Σ\Sigma, the distribution of M=XXM = X'X is Wp(Σ,m)W_p(\Sigma, m).

Consequently, the expectation of MM is

E[M]=m×Σ.E[M] = m\times\Sigma.

Further, if Sigma is scalar (p=1p = 1), the Wishart distribution is a scaled chi-squared (χ2\chi^2) distribution with df degrees of freedom, W1(σ2,m)=σ2χm2W_1(\sigma^2, m) = \sigma^2 \chi^2_m.

The component wise variance is

Var(Mij)=m(Σij2+ΣiiΣjj).\mathrm{Var}(M_{ij}) = m(\Sigma_{ij}^2 + \Sigma_{ii} \Sigma_{jj}).

Value

a numeric array, say R, of dimension p×p×np \times p \times n, where each R[,,i] is a positive definite matrix, a realization of the Wishart distribution Wp(Σ,m),  m=df, Σ=SigmaW_p(\Sigma, m),\ \ m=\code{df},\ \Sigma=\code{Sigma}.

Author(s)

Douglas Bates

References

Mardia, K. V., J. T. Kent, and J. M. Bibby (1979) Multivariate Analysis, London: Academic Press.

See Also

cov, rnorm, rchisq.

Examples

## Artificial
S <- toeplitz((10:1)/10)
set.seed(11)
R <- rWishart(1000, 20, S)
dim(R)  #  10 10  1000
mR <- apply(R, 1:2, mean)  # ~= E[ Wish(S, 20) ] = 20 * S
stopifnot(all.equal(mR, 20*S, tolerance = .009))

## See Details, the variance is
Va <- 20*(S^2 + tcrossprod(diag(S)))
vR <- apply(R, 1:2, var)
stopifnot(all.equal(vR, Va, tolerance = 1/16))

[Package stats version 4.4.1 Index]