rWishart {stats} | R Documentation |
Generate n
random matrices, distributed according to the
Wishart distribution with parameters Sigma
and df
,
W_p(Sigma, df).
rWishart(n, df, Sigma)
n |
integer sample size. |
df |
numeric parameter, “degrees of freedom”. |
Sigma |
positive definite (p * p) “scale” matrix, the matrix parameter of the distribution. |
If X1,...,Xm, Xi in R^p is a sample of m independent multivariate Gaussians with mean (vector) 0, and covariance matrix Σ, the distribution of M = X'X is W_p(Σ, m).
Consequently, the expectation of M is
E[M] = m * Sigma.
Further, if Sigma
is scalar (p = 1), the Wishart
distribution is a scaled chi-squared (chi^2)
distribution with df
degrees of freedom,
W_1(sigma^2, m) = sigma^2 chi[m]^2.
The component wise variance is
Var(M[i,j]) = m*(S[i,j]^2 + S[i,i] * S[j,j]), where S=Sigma.
a numeric array
, say R
, of dimension
p * p * n, where each R[,,i]
is a
positive definite matrix, a realization of the Wishart distribution
W_p(Sigma, df).
Douglas Bates
Mardia, K. V., J. T. Kent, and J. M. Bibby (1979) Multivariate Analysis, London: Academic Press.
## 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))