rmatnorm: Matrix-variate Normal distribution

View source: R/stats.R

rmatnormR Documentation

Matrix-variate Normal distribution

Description

Random generation for the matrix-variate Normal distribution. See https://en.wikipedia.org/wiki/Matrix_normal_distribution.

Usage

rmatnorm(n = 1, M, U, V, pivot = c(U = "auto", V = "auto"))

Arguments

n

number of observations

M

mean matrix; if dimnames(M) is not NULL, the column and row names will be compared to those of U and V (if any) and, in the absence of conflict, propagated to the output

U

between-row covariance matrix

V

between-column covariance matrix

pivot

2-element vector with values TRUE/FALSE/"auto", where TRUE (FALSE) means using pivoting (or not) for Choleski decomposition of U and/or V (see chol); useful when U and/or V are singular; with "auto", this will be automatically determined

Value

array

Author(s)

Timothee Flutre

Examples

## Not run: set.seed(1859)
Sigma <- matrix(c(3,2,2,4), nrow=2, ncol=2)
rho <- Sigma[2,1] / prod(sqrt(diag(Sigma)))
samples <- rmatnorm(n=100, M=matrix(0, nrow=10^3, ncol=2),
                    U=diag(10^3), V=Sigma)
tmp <- t(apply(samples, 3, function(mat){
  c(var(mat[,1]), var(mat[,2]), cor(mat[,1], mat[,2]))
}))
summary(tmp) # corresponds well to Sigma

## End(Not run)

timflutre/rutilstimflutre documentation built on Feb. 7, 2024, 8:17 a.m.