MatrixNormal {mniw} | R Documentation |
The Matrix-Normal distribution.
Description
Density and random sampling for the Matrix-Normal distribution.
Usage
dMNorm(X, Lambda, SigmaR, SigmaC, log = FALSE)
rMNorm(n, Lambda, SigmaR, SigmaC)
Arguments
X |
Argument to the density function. Either a |
Lambda |
Mean parameter Either a |
SigmaR |
Between-row covariance matrix. Either a |
SigmaC |
Between-column covariance matrix Either a |
log |
Logical; whether or not to compute the log-density. |
n |
Integer number of random samples to generate. |
Details
The Matrix-Normal distribution \boldsymbol{X} \sim \textrm{Matrix-Normal}(\boldsymbol{\Lambda}, \boldsymbol{\Sigma}_R, \boldsymbol{\Sigma}_C)
on the random matrix \boldsymbol{X}_{p \times q}
is defined as
\textrm{vec}(\boldsymbol{X}) \sim \mathcal{N}(\textrm{vec}(\boldsymbol{\Lambda}), \boldsymbol{\Sigma}_C \otimes \boldsymbol{\Sigma}_R),
where \textrm{vec}(\boldsymbol{X})
is a vector stacking the columns of \boldsymbol{X}
, and \boldsymbol{\Sigma}_C \otimes \boldsymbol{\Sigma}_R
denotes the Kronecker product.
Value
A vector length n
for density evaluation, or an array of size p x q x n
for random sampling.
Examples
# problem dimensions
p <- 4
q <- 2
n <- 10 # number of observations
# parameter values
Lambda <- matrix(rnorm(p*q),p,q) # mean matrix
# row-wise variance matrix (positive definite)
SigmaR <- crossprod(matrix(rnorm(p*p), p, p))
SigmaC <- rwish(n, Psi = diag(q), nu = q + 1) # column-wise variance (vectorized)
# random sample
X <- rMNorm(n, Lambda = Lambda, SigmaR = SigmaR, SigmaC = SigmaC)
# log-density at each sampled value
dMNorm(X, Lambda = Lambda, SigmaR = SigmaR, SigmaC = SigmaC, log = TRUE)