An expansion of R's 'stats' random wishart matrix generation. This package allows the user to generate singular, Uhlig and Harald (1994) <doi:10.1214/aos/1176325375>, and pseudo wishart, Diaz-Garcia, et al.(1997) <doi:10.1006/jmva.1997.1689>, matrices. In addition the user can generate wishart matrices with fractional degrees of freedom, Adhikari (2008) <doi:10.1061/(ASCE)0733-9399(2008)134:12(1029)>, commonly used in volatility modeling. Users can also use this package to create random covariance matrices.

Generate n random matrices, distributed according to the Wishart distribution with parameters Sigma and df, W_p(Sigma, df).

rWishart(n, df, Sigma, covariance = FALSE, simplify = "array")

Arguments

n

integer: the number of replications.

df

numeric parameter, “degrees of freedom”.

Sigma

positive definite (\(p\times p\)) “scale” matrix, the matrix parameter of the distribution.

covariance

logical on whether a covariance matrix should be generated

simplify

logical or character string; should the result be simplified to a vector, matrix or higher dimensional array if possible? For sapply it must be named and not abbreviated. The default value, TRUE, returns a vector or matrix if appropriate, whereas if simplify = "array" the result may be an array of “rank” (\(=\)length(dim(.))) one higher than the result of FUN(X[[i]]).

Value

A numeric array of dimension p * p * n, where each array is a positive semidefinite matrix, a realization of the Wishart distribution W_p(Sigma, df)

Details

If X_1, ..., X_m is a sample of m independent multivariate Gaussians with mean vector 0, and covariance matrix Sigma, the distribution of M = X'X is W_p(Sigma, m).

Examples

rWishart(2, 5, diag(1, 20))
#> , , 1 #> #> [,1] [,2] [,3] [,4] [,5] [,6] #> [1,] 0.50982295 0.6446431 0.33376241 0.7702879 -0.414971489 -0.01706761 #> [2,] 0.64464309 3.8484893 -4.83075880 1.0737758 -0.203897970 -0.24204741 #> [3,] 0.33376241 -4.8307588 10.45951810 -0.1513977 0.068048259 1.80255819 #> [4,] 0.77028789 1.0737758 -0.15139768 4.1878242 -0.540593665 -0.71192073 #> [5,] -0.41497149 -0.2038980 0.06804826 -0.5405937 1.553755845 0.98294440 #> [6,] -0.01706761 -0.2420474 1.80255819 -0.7119207 0.982944403 1.84193473 #> [7,] 0.85555846 2.9907096 -2.80946946 1.5463194 -1.170509038 -0.06804196 #> [8,] 0.17837157 0.4985672 -1.95494292 2.0833371 -1.716436672 -1.90581181 #> [9,] 0.43926346 0.1445636 1.20598930 0.3211217 -1.121936154 0.51808055 #> [10,] -0.04678891 -1.2022210 3.35604564 1.0684358 1.193458342 1.82826914 #> [11,] 0.06940922 -2.3894342 4.73864670 -1.3309241 0.108809389 0.62875617 #> [12,] -0.25804703 -0.6593582 0.75630680 -0.8394469 0.146597719 0.54789651 #> [13,] 0.13757865 1.3937264 -2.64542325 -0.8848601 -0.945752235 -0.76497133 #> [14,] -0.46950342 -1.4661485 1.05411069 -0.9000038 -0.002915795 -0.06233037 #> [15,] -0.04618774 1.2661542 -0.52749358 0.4935821 1.035188264 2.33001123 #> [16,] 0.39544950 2.8097594 -5.05066925 3.5307165 -0.505326693 -1.94416627 #> [17,] -0.30882672 1.3624539 -3.38911503 -1.7323398 -0.068099820 -0.22356017 #> [18,] -0.49706844 -1.7952391 1.39854011 -1.0585358 1.122676894 -0.57894389 #> [19,] -0.06962647 0.1197260 0.72052208 -1.2594325 0.779872758 1.43292722 #> [20,] 0.87379133 -0.9400735 4.58001063 -0.5768829 0.027651826 0.50644454 #> [,7] [,8] [,9] [,10] [,11] [,12] #> [1,] 0.85555846 0.17837157 0.439263463 -0.04678891 0.06940922 -0.25804703 #> [2,] 2.99070959 0.49856719 0.144563589 -1.20222105 -2.38943415 -0.65935819 #> [3,] -2.80946946 -1.95494292 1.205989304 3.35604564 4.73864670 0.75630680 #> [4,] 1.54631938 2.08333711 0.321121671 1.06843583 -1.33092408 -0.83944690 #> [5,] -1.17050904 -1.71643667 -1.121936154 1.19345834 0.10880939 0.14659772 #> [6,] -0.06804196 -1.90581181 0.518080554 1.82826914 0.62875617 0.54789651 #> [7,] 3.69040221 1.47442515 1.798597470 -0.59969552 -2.01599735 -0.27444819 #> [8,] 1.47442515 3.46506110 0.827797399 -1.23236664 -1.63050414 -0.39403256 #> [9,] 1.79859747 0.82779740 2.232915596 0.44180015 -0.05377761 0.43421280 #> [10,] -0.59969552 -1.23236664 0.441800153 3.30619278 0.59843262 0.46184951 #> [11,] -2.01599735 -1.63050414 -0.053777609 0.59843262 2.89585542 0.29473588 #> [12,] -0.27444819 -0.39403256 0.434212796 0.46184951 0.29473588 0.46082836 #> [13,] 1.35206532 0.79427385 0.477802030 -2.04855963 -0.79575209 -0.09319864 #> [14,] -1.11876602 0.05729291 -0.005682689 0.08416976 0.58717534 0.39797508 #> [15,] 1.93026295 -0.91434868 1.548542913 2.71641546 -1.54811296 0.75933558 #> [16,] 1.96481085 2.80722199 -0.871866685 -1.12838344 -3.09618292 -1.23092920 #> [17,] 0.77287209 -0.08336509 -0.075201059 -1.64659560 -1.06445001 0.16259428 #> [18,] -3.38734901 -1.50100264 -2.634700043 -0.42962821 1.78643570 -0.37477295 #> [19,] 0.02054228 -1.76407231 0.315888159 0.89899492 0.45536467 0.46872623 #> [20,] -1.30175167 -2.29453092 -0.505051929 0.01077451 3.27025678 -0.43565742 #> [,13] [,14] [,15] [,16] [,17] [,18] #> [1,] 0.13757865 -0.469503424 -0.04618774 0.39544950 -0.30882672 -0.4970684 #> [2,] 1.39372640 -1.466148483 1.26615421 2.80975940 1.36245388 -1.7952391 #> [3,] -2.64542325 1.054110686 -0.52749358 -5.05066925 -3.38911503 1.3985401 #> [4,] -0.88486014 -0.900003817 0.49358213 3.53071651 -1.73233985 -1.0585358 #> [5,] -0.94575223 -0.002915795 1.03518826 -0.50532669 -0.06809982 1.1226769 #> [6,] -0.76497133 -0.062330366 2.33001123 -1.94416627 -0.22356017 -0.5789439 #> [7,] 1.35206532 -1.118766020 1.93026295 1.96481085 0.77287209 -3.3873490 #> [8,] 0.79427385 0.057292912 -0.91434868 2.80722199 -0.08336509 -1.5010026 #> [9,] 0.47780203 -0.005682689 1.54854291 -0.87186669 -0.07520106 -2.6347000 #> [10,] -2.04855963 0.084169757 2.71641546 -1.12838344 -1.64659560 -0.4296282 #> [11,] -0.79575209 0.587175340 -1.54811296 -3.09618292 -1.06445001 1.7864357 #> [12,] -0.09319864 0.397975083 0.75933558 -1.23092920 0.16259428 -0.3747729 #> [13,] 1.71215688 -0.199077340 -0.62914757 0.46834975 1.49134177 -0.9435422 #> [14,] -0.19907734 0.768544581 -0.41759060 -1.11872491 -0.03350775 0.4750526 #> [15,] -0.62914757 -0.417590601 5.36540436 -0.45223584 0.22705954 -3.1997485 #> [16,] 0.46834975 -1.118724909 -0.45223584 5.57403918 0.04348013 -0.6306952 #> [17,] 1.49134177 -0.033507750 0.22705954 0.04348013 1.96836125 -0.5932829 #> [18,] -0.94354224 0.475052585 -3.19974854 -0.63069517 -0.59328294 4.2236720 #> [19,] -0.16603503 -0.064271548 1.67867915 -1.78315584 0.37867133 -0.3982702 #> [20,] -0.55451842 -0.438496823 -2.54953337 -2.27921178 -1.30890218 2.4122050 #> [,19] [,20] #> [1,] -0.06962647 0.87379133 #> [2,] 0.11972598 -0.94007349 #> [3,] 0.72052208 4.58001063 #> [4,] -1.25943245 -0.57688290 #> [5,] 0.77987276 0.02765183 #> [6,] 1.43292722 0.50644454 #> [7,] 0.02054228 -1.30175167 #> [8,] -1.76407231 -2.29453092 #> [9,] 0.31588816 -0.50505193 #> [10,] 0.89899492 0.01077451 #> [11,] 0.45536467 3.27025678 #> [12,] 0.46872623 -0.43565742 #> [13,] -0.16603503 -0.55451842 #> [14,] -0.06427155 -0.43849682 #> [15,] 1.67867915 -2.54953337 #> [16,] -1.78315584 -2.27921178 #> [17,] 0.37867133 -1.30890218 #> [18,] -0.39827021 2.41220504 #> [19,] 1.30955269 0.45428523 #> [20,] 0.45428523 5.79144222 #> #> , , 2 #> #> [,1] [,2] [,3] [,4] [,5] [,6] #> [1,] 21.3978200 0.84358017 3.4988653 9.8061228 5.0837112 -1.36378530 #> [2,] 0.8435802 3.26224413 -1.4155125 -1.0204168 -0.6368311 4.86834267 #> [3,] 3.4988653 -1.41551247 4.9215826 3.6600690 -0.1340923 -3.00861308 #> [4,] 9.8061228 -1.02041683 3.6600690 5.8404440 2.4950634 -3.26613553 #> [5,] 5.0837112 -0.63683115 -0.1340923 2.4950634 7.4427957 -0.77009108 #> [6,] -1.3637853 4.86834267 -3.0086131 -3.2661355 -0.7700911 8.48147089 #> [7,] 8.8559106 3.84621512 0.9652545 3.6068565 -1.9502741 2.73677403 #> [8,] 5.3608540 -0.99122881 -0.3017111 2.1750958 0.4777018 -2.13131691 #> [9,] -4.9384703 1.46388632 -0.4958084 -2.8578556 -3.2069478 3.02981468 #> [10,] -1.4994447 -0.19392140 -1.8407541 -0.6926660 4.4474780 -0.07481626 #> [11,] -1.5174859 -1.67131816 -1.0308272 0.0340639 4.6399829 -2.47794217 #> [12,] -4.5280046 0.32930623 -4.2203398 -3.3493524 2.8581191 1.74598019 #> [13,] -5.3304470 -2.89774983 0.6663954 -2.0410219 -5.7875553 -3.27677394 #> [14,] 4.4000695 -0.14356702 -0.5564267 1.9026770 6.1472383 -0.11390642 #> [15,] -4.6920059 2.75198142 -1.4146535 -3.0842115 -0.8485498 4.89939387 #> [16,] -5.1497606 1.81485643 -6.9875750 -5.1410692 -2.3973403 3.20953900 #> [17,] 5.6050275 -0.13431476 0.1776689 1.9973382 1.3183758 -0.13793441 #> [18,] -3.2969762 -1.77032622 -1.2860239 -1.3903121 1.1838739 -1.86897420 #> [19,] -8.8413498 1.23453430 -4.2540802 -6.7722042 -3.5763678 5.29182526 #> [20,] -2.6630558 -0.04385885 -0.7147163 -1.2957436 2.9888530 1.05260293 #> [,7] [,8] [,9] [,10] [,11] [,12] #> [1,] 8.8559106 5.3608540 -4.938470291 -1.49944468 -1.5174859 -4.5280046 #> [2,] 3.8462151 -0.9912288 1.463886322 -0.19392140 -1.6713182 0.3293062 #> [3,] 0.9652545 -0.3017111 -0.495808361 -1.84075412 -1.0308272 -4.2203398 #> [4,] 3.6068565 2.1750958 -2.857855583 -0.69266597 0.0340639 -3.3493524 #> [5,] -1.9502741 0.4777018 -3.206947755 4.44747803 4.6399829 2.8581191 #> [6,] 2.7367740 -2.1313169 3.029814680 -0.07481626 -2.4779422 1.7459802 #> [7,] 12.3745721 1.0840363 -0.242858590 -1.98543124 -3.2327299 -3.7117763 #> [8,] 1.0840363 3.2250615 -1.980305191 -0.90085846 -0.3670491 -0.6640398 #> [9,] -0.2428586 -1.9803052 2.865521413 -1.52485501 -2.2905662 -0.3238855 #> [10,] -1.9854312 -0.9008585 -1.524855011 4.56774828 4.5801573 3.9558237 #> [11,] -3.2327299 -0.3670491 -2.290566234 4.58015732 5.2947744 3.5656527 #> [12,] -3.7117763 -0.6640398 -0.323885522 3.95582369 3.5656527 5.4098362 #> [13,] -4.8545241 1.2849375 1.712671789 -4.47255376 -3.2788249 -2.2158761 #> [14,] -1.0614021 0.4670821 -2.618824532 3.78747175 3.7784282 2.6150761 #> [15,] 0.7434927 -3.0645225 2.574683941 0.80109764 -0.5598919 1.4447716 #> [16,] 0.5862932 1.2913740 0.906391445 1.10673277 0.1881508 4.7295742 #> [17,] 0.3948918 2.1787162 -1.230131717 -0.91670903 -0.8879856 -0.6931410 #> [18,] -4.3808226 0.2340841 -0.684650325 1.61899253 2.2821240 2.3076060 #> [19,] -6.4495305 -1.0401359 4.010760813 -1.89552784 -2.9944276 2.8918734 #> [20,] -3.5266378 -1.6873245 0.005595696 2.67969951 2.4988486 2.6086812 #> [,13] [,14] [,15] [,16] [,17] [,18] #> [1,] -5.3304470 4.4000695 -4.6920059 -5.1497606 5.6050275 -3.2969762 #> [2,] -2.8977498 -0.1435670 2.7519814 1.8148564 -0.1343148 -1.7703262 #> [3,] 0.6663954 -0.5564267 -1.4146535 -6.9875750 0.1776689 -1.2860239 #> [4,] -2.0410219 1.9026770 -3.0842115 -5.1410692 1.9973382 -1.3903121 #> [5,] -5.7875553 6.1472383 -0.8485498 -2.3973403 1.3183758 1.1838739 #> [6,] -3.2767739 -0.1139064 4.8993939 3.2095390 -0.1379344 -1.8689742 #> [7,] -4.8545241 -1.0614021 0.7434927 0.5862932 0.3948918 -4.3808226 #> [8,] 1.2849375 0.4670821 -3.0645225 1.2913740 2.1787162 0.2340841 #> [9,] 1.7126718 -2.6188245 2.5746839 0.9063914 -1.2301317 -0.6846503 #> [10,] -4.4725538 3.7874718 0.8010976 1.1067328 -0.9167090 1.6189925 #> [11,] -3.2788249 3.7784282 -0.5598919 0.1881508 -0.8879856 2.2821240 #> [12,] -2.2158761 2.6150761 1.4447716 4.7295742 -0.6931410 2.3076060 #> [13,] 10.0502841 -5.1959279 -2.3763871 0.9815852 0.3171474 1.3769852 #> [14,] -5.1959279 5.1531460 -0.4873605 -1.2961597 1.1225557 0.8622552 #> [15,] -2.3763871 -0.4873605 4.1824621 1.2056363 -1.8059614 -0.8571975 #> [16,] 0.9815852 -1.2961597 1.2056363 11.4755524 -0.4929140 1.4402955 #> [17,] 0.3171474 1.1225557 -1.8059614 -0.4929140 2.4372956 -0.2559607 #> [18,] 1.3769852 0.8622552 -0.8571975 1.4402955 -0.2559607 2.1843434 #> [19,] 5.8966728 -2.8519030 2.6563849 5.4969210 0.3277429 1.4915554 #> [20,] -2.2173743 2.4030486 1.4579507 -0.8522281 -0.6255003 1.1577149 #> [,19] [,20] #> [1,] -8.8413498 -2.663055766 #> [2,] 1.2345343 -0.043858851 #> [3,] -4.2540802 -0.714716285 #> [4,] -6.7722042 -1.295743572 #> [5,] -3.5763678 2.988853010 #> [6,] 5.2918253 1.052602926 #> [7,] -6.4495305 -3.526637819 #> [8,] -1.0401359 -1.687324520 #> [9,] 4.0107608 0.005595696 #> [10,] -1.8955278 2.679699511 #> [11,] -2.9944276 2.498848567 #> [12,] 2.8918734 2.608681213 #> [13,] 5.8966728 -2.217374289 #> [14,] -2.8519030 2.403048592 #> [15,] 2.6563849 1.457950667 #> [16,] 5.4969210 -0.852228069 #> [17,] 0.3277429 -0.625500329 #> [18,] 1.4915554 1.157714854 #> [19,] 13.1781080 1.077606113 #> [20,] 1.0776061 2.773713441 #>