rmvnorm | R Documentation |
Generates random samples from a multivariate normal distribution with a specified mean vector and covariance matrix.
rmvnorm(n, mean, sigma)
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. |
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.
A numeric matrix where each row represents a sample from the multivariate normal distribution.
Kaifeng Lu, kaifenglu@gmail.com
# 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))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.