Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

mvrnorm

Simulate from a Multivariate Normal Distribution


Description

Produces one or more samples from the specified multivariate normal distribution.

Usage

mvrnorm(n = 1, mu, Sigma, tol = 1e-6, empirical = FALSE, EISPACK = FALSE)

Arguments

n

the number of samples required.

mu

a vector giving the means of the variables.

Sigma

a positive-definite symmetric matrix specifying the covariance matrix of the variables.

tol

tolerance (relative to largest variance) for numerical lack of positive-definiteness in Sigma.

empirical

logical. If true, mu and Sigma specify the empirical not population mean and covariance matrix.

EISPACK

logical: values other than FALSE are an error.

Details

The matrix decomposition is done via eigen; although a Choleski decomposition might be faster, the eigendecomposition is stabler.

Value

If n = 1 a vector of the same length as mu, otherwise an n by length(mu) matrix with one sample in each row.

Side Effects

Causes creation of the dataset .Random.seed if it does not already exist, otherwise its value is updated.

References

B. D. Ripley (1987) Stochastic Simulation. Wiley. Page 98.

See Also

Examples

Sigma <- matrix(c(10,3,3,2),2,2)
Sigma
var(mvrnorm(n = 1000, rep(0, 2), Sigma))
var(mvrnorm(n = 1000, rep(0, 2), Sigma, empirical = TRUE))

MASS

Support Functions and Datasets for Venables and Ripley's MASS

v7.3-54
GPL-2 | GPL-3
Authors
Brian Ripley [aut, cre, cph], Bill Venables [ctb], Douglas M. Bates [ctb], Kurt Hornik [trl] (partial port ca 1998), Albrecht Gebhardt [trl] (partial port ca 1998), David Firth [ctb]
Initial release
2021-04-17

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.