Learn R Programming

evgam (version 1.0.2)

rmvnorm: Generate Random Multivariate Normal Draws via Pivoted Cholesky

Description

An internal utility to simulate from a MVN distribution. By using a pivoted Cholesky decomposition, the function can handle semi-definite covariance matrices by effectively reducing the dimensionality to the numerical rank of the matrix.

Usage

rmvnorm(n, mu, Sig)

Value

A matrix of dimension n x p where each row is a random draw from the specified MVN distribution.

Arguments

n

Integer; the number of samples to generate.

mu

Numeric vector; the mean vector of length p.

Sig

Numeric matrix; the p x p covariance matrix.

Details

The function extracts the pivoting index and the numerical rank from the result of chol(Sig, pivot = TRUE). It then generates independent standard normal draws of dimension r (the rank) and transforms them using the Cholesky factor to match the target covariance and mean.