rwishart: Generate Random Wishart Distribution

View source: R/RcppExports.R

rwishartR Documentation

Generate Random Wishart Distribution

Description

Creates a random wishart distribution when given degrees of freedom and a sigma matrix.

Usage

rwishart(df, S)

Arguments

df

An int, which gives the degrees of freedom of the Wishart. (> 0)

S

A matrix with dimensions m x m that provides Sigma, the covariance matrix.

Value

A matrix that is a Wishart distribution, aka the sample covariance matrix of a Multivariate Normal Distribution

Author(s)

James J Balamuta

See Also

riwishart

Examples

#Call with the following data:
rwishart(3, diag(2))

# Validation
set.seed(1337)
S = toeplitz((10:1)/10)
n = 10000
o = array(dim = c(10,10,n))
for(i in 1:n){
o[,,i] = rwishart(20, S)
}
mR = apply(o, 1:2, mean)
Va = 20*(S^2 + tcrossprod(diag(S)))
vR = apply(o, 1:2, var)
stopifnot(all.equal(vR, Va, tolerance = 1/16))


coatless/r-to-armadillo documentation built on Nov. 16, 2023, 5:32 a.m.