rinvwishart {matrixsampling} | R Documentation |
Inverse-Wishart sampler
Description
Samples the inverse-Wishart distribution.
Usage
rinvwishart(n, nu, Omega, epsilon = 0, checkSymmetry = TRUE)
Arguments
n |
sample size, a positive integer |
nu |
degrees of freedom, must satisfy |
Omega |
scale matrix, a positive definite real matrix |
epsilon |
threshold to force invertibility in the algorithm; see Details |
checkSymmetry |
logical, whether to check the symmetry of |
Details
The inverse-Wishart distribution with scale matrix
Ω is
defined as the inverse of the Wishart distribution with scale matrix
Ω-1
and same number of degrees of freedom.
The argument epsilon
is a threshold whose role is to guarantee
the invertibility of the sampled Wishart distributions.
See Details in rwishart
.
Value
A numeric three-dimensional array; simulations are stacked along the third dimension (see example).
Examples
nu <- 6
p <- 3
Omega <- toeplitz(p:1)
IWsims <- rinvwishart(10000, nu, Omega)
dim(IWsims) # 3 3 10000
apply(IWsims, 1:2, mean) # approximately Omega/(nu-p-1)
# the epsilon argument:
IWsims <- tryCatch(rinvwishart(10000, nu=p+0.001, Omega),
error=function(e) e)
IWsims <- tryCatch(rinvwishart(10000, nu=p+0.001, Omega, epsilon=1e-8),
error=function(e) e)