rwish: Sampling from Wishart distribution

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/rwish.R

Description

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

Usage

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

Arguments

n

The number of samples required.

p

The number of variables (nodes).

b

The degree of freedom for Wishart distribution, W(b, D).

D

The positive definite (p \times p) "scale" matrix for Wishart distribution, W(b, D). The default is an identity matrix.

Details

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

Pr(K) \propto |K| ^ {(b - 2) / 2} \exp ≤ft\{- \frac{1}{2} \mbox{trace}(K \times D)\right\},

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

Value

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

Author(s)

Reza Mohammadi a.mohammadi@uva.nl

References

Lenkoski, A. (2013). A direct sampler for G-Wishart variates, Stat, 2:119-128

Mohammadi, A. and Wit, E. C. (2015). Bayesian Structure Learning in Sparse Gaussian Graphical Models, Bayesian Analysis, 10(1):109-138

Letac, G., Massam, H. and Mohammadi, R. (2018). The Ratio of Normalizing Constants for Bayesian Graphical Gaussian Model Selection, arXiv preprint arXiv:1706.04416v2

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

See Also

gnorm, rgwish

Examples

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

round( sample, 2 )  

Example output

, , 1

      [,1]  [,2]  [,3]  [,4]  [,5]
[1,]  2.17  1.49 -3.40  0.82  0.39
[2,]  1.49  4.91 -2.79  3.43  0.10
[3,] -3.40 -2.79 10.36 -1.14 -0.85
[4,]  0.82  3.43 -1.14  5.85 -1.64
[5,]  0.39  0.10 -0.85 -1.64  3.90

, , 2

      [,1]  [,2]  [,3]  [,4]  [,5]
[1,]  5.22  1.03  1.51 -5.22  1.34
[2,]  1.03  2.09 -0.33  0.07 -0.39
[3,]  1.51 -0.33 10.50  2.18  5.97
[4,] -5.22  0.07  2.18 10.72  1.12
[5,]  1.34 -0.39  5.97  1.12  5.35

, , 3

      [,1]  [,2]  [,3]  [,4] [,5]
[1,] 20.12 -1.82 -2.21  8.17 0.76
[2,] -1.82  4.42  0.06 -2.63 1.65
[3,] -2.21  0.06  8.83  1.39 2.73
[4,]  8.17 -2.63  1.39  6.26 0.66
[5,]  0.76  1.65  2.73  0.66 6.41

BDgraph documentation built on May 3, 2021, 9:08 a.m.