Learn R Programming

SDGLM (version 0.4.0)

rinvwishart: Generate Random Samples from the Inverse Wishart Distribution

Description

Implements Bartlett decomposition to sample from the inverse Wishart distribution IW(v, S), where v = degrees of freedom and S = scale matrix.

Usage

rinvwishart(n = 1, v, S)

Value

If n=1: p x p inverse Wishart sample matrix. If n>1: 3D array (p x p x n) of independent inverse Wishart samples.

Arguments

n

Integer (>=1). Number of inverse Wishart samples to generate (default = 1).

v

Numeric (scalar). Degrees of freedom; must satisfy v > p - 1 (where p = ncol(S)).

S

Numeric matrix (p x p). Positive-definite scale matrix.

Examples

Run this code
# 1 sample from IW(v=5, S=diag(2))
set.seed(123)
Sigma <- rinvwishart(n = 1, v = 5, S = diag(2))

# 10 samples (3D array)
Sigma_arr <- rinvwishart(n = 10, v = 5, S = diag(2))

Run the code above in your browser using DataLab