smvrnorm | R Documentation |
smvrnorm()
simulates data from a multivariate normal distribution.
smvrnorm(
n = 1,
mu,
sigma,
tol = 1e-06,
empirical = FALSE,
eispack = FALSE,
seed
)
n |
the number of observations to simulate |
mu |
a vector of means |
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 |
empirical |
logical. If true, |
eispack |
logical. values other than FALSE result in an error |
seed |
set an optional seed |
This is a simple port and rename of mvrnorm()
from the MASS package. I elect
to plagiarize/port it because the MASS package conflicts with a lot of things in my workflow,
especially select()
. This is useful for "informal Bayes" approaches to generating quantities
of interest from a regression model.
The function returns simulated data from a multivariate normal distribution.
B. D. Ripley (1987) Stochastic Simulation. Wiley. Page 98.
M1 <- lm(mpg ~ disp + cyl, mtcars)
smvrnorm(100, coef(M1), vcov(M1))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.