% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/utils_simul.R
\name{rmatnorm}
\alias{rmatnorm}
\title{Matrix-variate Normal distribution}
\usage{
rmatnorm(n = 1, M, U, V, pivot = c(U = "auto", V = "auto"))
}
\arguments{
\item{n}{number of observations}

\item{M}{mean matrix; if missing, will be replaced by a matrix of zeroes; if \code{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}

\item{U}{between-row covariance matrix}

\item{V}{between-column covariance matrix}

\item{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 \code{\link[base]{chol}}); useful when U and/or V are singular; with "auto", this will be automatically determined}
}
\value{
array
}
\description{
Random generation for the matrix-variate Normal distribution.
See \url{https://en.wikipedia.org/wiki/Matrix_normal_distribution}.
}
\examples{
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
}
\author{
Timothee Flutre
}
