rmvnorm: Random Multivariate Normal Generation

View source: R/RcppExports.R

rmvnormR Documentation

Random Multivariate Normal Generation

Description

Generates random samples from a multivariate normal distribution with a specified mean vector and covariance matrix.

Usage

rmvnorm(n, mean, sigma)

Arguments

n

The number of samples to generate.

mean

A numeric vector representing the mean of the distribution.

sigma

A numeric matrix representing the covariance matrix.

Details

This function generates samples from a multivariate normal distribution using the Cholesky decomposition method. It first computes the Cholesky factorization of the covariance matrix, then generates standard normal random variables, and finally transforms them to the desired multivariate normal distribution.

Value

A numeric matrix where each row represents a sample from the multivariate normal distribution.

Author(s)

Kaifeng Lu, kaifenglu@gmail.com

Examples

# Generate 5 samples from a bivariate normal distribution with mean (0,0)
# and covariance matrix [[1, 0.5], [0.5, 1]]

set.seed(314159)
rmvnorm(5, c(0, 0), matrix(c(1, 0.5, 0.5, 1), nrow=2))


lrstat documentation built on Aug. 8, 2025, 7:36 p.m.