Generate samples from the Matrix-Normal Inverse-Wishart distribution.

rMNIW(n, Lambda, Sigma, Psi, nu, prec = FALSE)

rmniw(n, Lambda, Omega, Psi, nu)

Arguments

n

number of samples.

Lambda

A mean matrix of size p x q or an array of size p x q x n. Defaults to matrix of zeros when missing.

Sigma

A row-wise variance or precision matrix of size p x p, or an array of size p x p x n. Defaults to the identity matrix when missing.

Psi

A scale matrix of size q x q, or an array of size q x q x n. Defaults to identity matrix when missing.

nu

Scalar degrees-of-freedom parameter.

prec

Logical; whether or not Sigma is on the variance or precision scale.

Omega

A between-row precision matrix of size p x p, or an array of size p x p x n. Defaults to the identity matrix when missing.

Value

A list with elements:

X

Array of size p x q x n random samples from the Matrix-Normal component (see Details).

V

Array of size q x q x n of random samples from the Inverse-Wishart component.

Details

The Matrix-Normal Inverse-Wishart (MNIW) distribution \((\boldsymbol{X}, \boldsymbol{V}) \sim \textrm{MNIW}(\boldsymbol{\Lambda}, \boldsymbol{\Sigma}, \boldsymbol{\Psi}, \nu)\) on random matrices \(\boldsymbol{X}_{p \times q}\) and symmetric positive-definite \(\boldsymbol{V}_{q\times q}\) is defined as $$ \begin{array}{rcl} \boldsymbol{V} & \sim & \textrm{Inverse-Wishart}(\boldsymbol{\Psi}, \nu) \\ \boldsymbol{X} \mid \boldsymbol{V} & \sim & \textrm{Matrix-Normal}(\boldsymbol{\Lambda}, \boldsymbol{\Sigma}, \boldsymbol{V}), \end{array} $$ where the Matrix-Normal distribution is defined as the multivariate normal $$ \textrm{vec}(\boldsymbol{X}) \sim \mathcal{N}(\textrm{vec}(\boldsymbol{\Lambda}), \boldsymbol{V} \otimes \boldsymbol{\Sigma}), $$ where \(\textrm{vec}(\boldsymbol{X})\) is a vector stacking the columns of \(\boldsymbol{X}\), and \(\boldsymbol{V} \otimes \boldsymbol{\Sigma}\) denotes the Kronecker product.

rmniw() is a convenience wrapper to rMNIW(Sigma = Omega, prec = TRUE), for the common situation in Bayesian inference with conjugate priors when between-row variances are naturally parametrized on the precision scale.

Examples

# problem dimensions
p <- 2
q <- 3
n <- 10 # number of samples
# parameter specification
Lambda <- matrix(rnorm(p*q),p,q) # single argument
Sigma <- rwish(n, Psi = diag(p), nu = p + rexp(1)) # vectorized argument
Psi <- rwish(n = 1, Psi = diag(q), nu = q + rexp(1)) # single argument
nu <- q + rexp(1)
# simulate n draws
rMNIW(n, Lambda = Lambda, Sigma = Sigma, Psi = Psi, nu = nu)
#> $X
#> , , 1
#> 
#>          [,1]      [,2]     [,3]
#> [1,] 2.661391 -1.909531 4.412750
#> [2,] 2.902983  1.818653 3.911115
#> 
#> , , 2
#> 
#>           [,1]       [,2]      [,3]
#> [1,]  0.240254 -2.9655738 0.7286107
#> [2,] -1.589109  0.2515893 1.6015171
#> 
#> , , 3
#> 
#>            [,1]      [,2]      [,3]
#> [1,] -2.6303936  1.371739  1.219745
#> [2,] -0.5552421 13.301178 10.984983
#> 
#> , , 4
#> 
#>            [,1]      [,2]      [,3]
#> [1,] -5.3927217  3.050695 1.6612222
#> [2,] -0.2220309 -1.455947 0.9302721
#> 
#> , , 5
#> 
#>           [,1]      [,2]      [,3]
#> [1,] -17.68364 -3.357513 -5.992328
#> [2,]  38.21249  5.069097 20.622301
#> 
#> , , 6
#> 
#>            [,1]     [,2]     [,3]
#> [1,] -3.4742971 4.237395 2.067416
#> [2,] -0.4361215 4.494805 3.104061
#> 
#> , , 7
#> 
#>            [,1]      [,2]     [,3]
#> [1,]  -2.648543  2.558157 2.605792
#> [2,] -12.146567 10.380910 2.561797
#> 
#> , , 8
#> 
#>            [,1]      [,2]      [,3]
#> [1,] -1.8464454 -6.075555 -2.962528
#> [2,]  0.6158559  4.173347  5.869108
#> 
#> , , 9
#> 
#>            [,1]      [,2]      [,3]
#> [1,] -14.400646 2.6801814 -3.055404
#> [2,]   7.830769 0.1142781  6.904561
#> 
#> , , 10
#> 
#>            [,1]      [,2]      [,3]
#> [1,]   7.664228  4.192530  24.70999
#> [2,] -16.701571 -9.907306 -34.92823
#> 
#> 
#> $V
#> , , 1
#> 
#>            [,1]       [,2]       [,3]
#> [1,]  2.0068106 -0.6517546  1.3930033
#> [2,] -0.6517546  0.5852756 -0.2617833
#> [3,]  1.3930033 -0.2617833  1.1794343
#> 
#> , , 2
#> 
#>            [,1]       [,2]      [,3]
#> [1,]  4.8797276 -1.7243244 0.7490202
#> [2,] -1.7243244  1.4408142 0.5579743
#> [3,]  0.7490202  0.5579743 1.1077558
#> 
#> , , 3
#> 
#>           [,1]      [,2]     [,3]
#> [1,]  6.502038 -3.002241 1.427665
#> [2,] -3.002241  9.519850 5.254202
#> [3,]  1.427665  5.254202 4.770120
#> 
#> , , 4
#> 
#>              [,1]       [,2]         [,3]
#> [1,]  0.711747979 -0.7418222 -0.004904328
#> [2,] -0.741822213  4.0470280  2.112206115
#> [3,] -0.004904328  2.1122061  1.554254475
#> 
#> , , 5
#> 
#>           [,1]     [,2]     [,3]
#> [1,] 225.83029 45.15474 99.03709
#> [2,]  45.15474 10.84620 20.71505
#> [3,]  99.03709 20.71505 44.19729
#> 
#> , , 6
#> 
#>           [,1]       [,2]      [,3]
#> [1,] 2.6979870  0.1782743  3.497365
#> [2,] 0.1782743 15.3803083 11.603340
#> [3,] 3.4973647 11.6033405 13.392171
#> 
#> , , 7
#> 
#>            [,1]       [,2]       [,3]
#> [1,]  6.7912882 -4.3881487 -0.2626731
#> [2,] -4.3881487  3.7629832  0.5919128
#> [3,] -0.2626731  0.5919128  0.3420001
#> 
#> , , 8
#> 
#>            [,1]      [,2]      [,3]
#> [1,]   7.505598 -14.94931 -9.840805
#> [2,] -14.949315  31.83017 21.379616
#> [3,]  -9.840805  21.37962 14.683639
#> 
#> , , 9
#> 
#>           [,1]      [,2]     [,3]
#> [1,]  3.863770 -1.309139 1.044778
#> [2,] -1.309139  2.326412 0.436210
#> [3,]  1.044778  0.436210 1.219763
#> 
#> , , 10
#> 
#>           [,1]      [,2]     [,3]
#> [1,] 139.91457  82.59726 289.3931
#> [2,]  82.59726  59.44109 186.9368
#> [3,] 289.39305 186.93682 623.9063
#> 
#>