rwish function

Sampling from Wishart distribution

Sampling from Wishart distribution

Generates random matrices, distributed according to the Wishart distribution with parameters bb and DD, W(b,D)W(b, D).

rwish( n = 1, p = 2, b = 3, D = diag( p ) )

Arguments

  • n: number of samples required.
  • p: number of variables (nodes).
  • b: degree of freedom for Wishart distribution, W(b,D)W(b, D).
  • D: positive definite (p×p)(p \times p) "scale" matrix for Wishart distribution, W(b,D)W(b, D). The default is an identity matrix.

Details

Sampling from Wishart distribution, KW(b,D)K \sim W(b, D), with density:

Pr(K)K(b2)/2exp{12\mboxtrace(K×D)}, Pr(K) \propto |K| ^ {(b - 2) / 2} \exp \left\{- \frac{1}{2} \mbox{trace}(K \times D)\right\},

which b>2b > 2 is the degree of freedom and DD is a symmetric positive definite matrix.

Returns

A numeric array, say AA, of dimension (p×p×n)(p \times p \times n), where each A[,,i]A[,,i] is a positive definite matrix, a realization of the Wishart distribution W(b,D)W(b, D). Note, for the case n=1n=1, the output is a matrix.

References

Lenkoski, A. (2013). A direct sampler for G-Wishart variates, Stat, 2:119-128, tools:::Rd_expr_doi("10.1002/sta4.23")

Mohammadi, R. and Wit, E. C. (2019). BDgraph: An R Package for Bayesian Structure Learning in Graphical Models, Journal of Statistical Software, 89(3):1-30, tools:::Rd_expr_doi("10.18637/jss.v089.i03")

Author(s)

Reza Mohammadi a.mohammadi@uva.nl

See Also

gnorm, rgwish

Examples

sample <- rwish( n = 3, p = 5, b = 3, D = diag( 5 ) ) round( sample, 2 )