MatrixNormal: The Matrix-Normal distribution.

MatrixNormalR 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 p x q matrix or a p x q x n array.

Lambda

Mean parameter Either a p x q matrix or a p x q x n array.

SigmaR

Between-row covariance matrix. Either a p x p matrix or a p x p x n array.

SigmaC

Between-column covariance matrix Either a q x q matrix or a q x q x n array.

log

Logical; whether or not to compute the log-density.

n

Integer number of random samples to generate.

Details

The Matrix-Normal distribution X ~ Matrix-Normal(Λ, Σ_R, Σ_C) on the random matrix X_(p x q) is defined as

vec(X) ~ N(vec(Λ), Σ_C %x% Σ_R),

where vec(X) is a vector stacking the columns of X, and Σ_C %x% Σ_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)

mniw documentation built on Aug. 22, 2022, 5:05 p.m.