rmatrixnormal {matrixsampling}R Documentation

Matrix normal sampler

Description

Samples the matrix normal distribution.

Usage

rmatrixnormal(n, M, U, V, checkSymmetry = TRUE, keep = TRUE)

Arguments

n

sample size, a positive integer

M

mean matrix, without constraints

U

columns covariance matrix, a positive semidefinite matrix of order equal to nrow(M)

V

rows covariance matrix, a positive semidefinite matrix of order equal to ncol(M)

checkSymmetry

logical, whether to check the symmetry of U and V

keep

logical, whether to return an array with class keep

Value

A numeric three-dimensional array; simulations are stacked along the third dimension (see example).

Examples

m <- 3
p <- 2
M <- matrix(1, m, p)
U <- toeplitz(m:1)
V <- toeplitz(p:1)
MNsims <- rmatrixnormal(10000, M, U, V)
dim(MNsims) # 3 2 10000
apply(MNsims, 1:2, mean) # approximates M
vecMNsims <- t(apply(MNsims, 3, function(X) c(t(X))))
round(cov(vecMNsims)) # approximates kronecker(U,V)

[Package matrixsampling version 2.0.0 Index]