Function generates data in the form of symmetric matrices from the inverse Wishart distribution given a covariance matrix and degrees of freedom.

rinvWishart(n = 1, df, sigma)

Arguments

n

number of matrix observations to generate. By default n = 1, which returns a single symmetric matrix. If n > 1 then a list of n symmetric matrices are returned instead

df

degrees of freedom

sigma

positive definite covariance matrix

Value

a numeric matrix with columns equal to ncol(sigma) when n = 1, or a list of n matrices with the same properties

References

Chalmers, R. P., & Adkins, M. C. (2020). Writing Effective and Reliable Monte Carlo Simulations with the SimDesign Package. The Quantitative Methods for Psychology, 16(4), 248-280. doi:10.20982/tqmp.16.4.p248

Sigal, M. J., & Chalmers, R. P. (2016). Play it again: Teaching statistics with Monte Carlo simulation. Journal of Statistics Education, 24(3), 136-156. doi:10.1080/10691898.2016.1246953

See also

Author

Phil Chalmers rphilip.chalmers@gmail.com

Examples


# random inverse Wishart matrix given variances [3,6], covariance 2, and df=15
sigma <- matrix(c(3,2,2,6), 2, 2)
x <- rinvWishart(sigma = sigma, df = 15)
x
#>            [,1]       [,2]
#> [1,] 0.13543636 0.07963835
#> [2,] 0.07963835 0.33615182

# list of matrices
x <- rinvWishart(20, sigma = sigma, df = 15)
x
#> [[1]]
#>           [,1]      [,2]
#> [1,] 0.2295383 0.1668944
#> [2,] 0.1668944 0.3103311
#> 
#> [[2]]
#>           [,1]      [,2]
#> [1,] 0.2451360 0.1043367
#> [2,] 0.1043367 0.2327082
#> 
#> [[3]]
#>           [,1]      [,2]
#> [1,] 0.2372281 0.1700588
#> [2,] 0.1700588 0.4592184
#> 
#> [[4]]
#>           [,1]      [,2]
#> [1,] 0.1897932 0.1986964
#> [2,] 0.1986964 0.4763723
#> 
#> [[5]]
#>           [,1]      [,2]
#> [1,] 0.2961771 0.2101903
#> [2,] 0.2101903 0.4457419
#> 
#> [[6]]
#>            [,1]       [,2]
#> [1,] 0.20712354 0.08245683
#> [2,] 0.08245683 0.39818001
#> 
#> [[7]]
#>           [,1]      [,2]
#> [1,] 0.1253428 0.1237987
#> [2,] 0.1237987 0.4092931
#> 
#> [[8]]
#>            [,1]       [,2]
#> [1,] 0.17509635 0.03126645
#> [2,] 0.03126645 0.27069185
#> 
#> [[9]]
#>           [,1]      [,2]
#> [1,] 0.5432412 0.4282939
#> [2,] 0.4282939 0.7519928
#> 
#> [[10]]
#>            [,1]       [,2]
#> [1,] 0.11311930 0.05432718
#> [2,] 0.05432718 0.39363138
#> 
#> [[11]]
#>           [,1]      [,2]
#> [1,] 0.2130090 0.1274582
#> [2,] 0.1274582 0.3060374
#> 
#> [[12]]
#>           [,1]      [,2]
#> [1,] 0.3098325 0.2499661
#> [2,] 0.2499661 0.6363222
#> 
#> [[13]]
#>           [,1]      [,2]
#> [1,] 0.1242213 0.0631768
#> [2,] 0.0631768 0.3443811
#> 
#> [[14]]
#>           [,1]      [,2]
#> [1,] 0.4275060 0.2879198
#> [2,] 0.2879198 0.5902773
#> 
#> [[15]]
#>           [,1]      [,2]
#> [1,] 0.3093765 0.1630539
#> [2,] 0.1630539 0.2796718
#> 
#> [[16]]
#>            [,1]       [,2]
#> [1,] 0.11046516 0.02646219
#> [2,] 0.02646219 0.34872737
#> 
#> [[17]]
#>            [,1]       [,2]
#> [1,] 0.11632594 0.02074906
#> [2,] 0.02074906 0.30345385
#> 
#> [[18]]
#>           [,1]      [,2]
#> [1,] 0.2470951 0.1609995
#> [2,] 0.1609995 0.6436081
#> 
#> [[19]]
#>           [,1]      [,2]
#> [1,] 0.1766255 0.2190138
#> [2,] 0.2190138 0.6149394
#> 
#> [[20]]
#>           [,1]      [,2]
#> [1,] 0.1951444 0.0698632
#> [2,] 0.0698632 0.3893907
#>