We've covered how to generate random numbers in R before, but what if you want to go beyond generating one random number at a time? What if you want to generate two, or three or more random numbers, and what's more, you want them to be correlated?

JD Long lays out the way in a couple of posts at his Cerebral Mastication blog. If you want to generate bivariate (or trivariate, or more) random multivariate Normal variates, it's pretty easy, as JD points out. Just use the mvrnorm function from the MASS package in R, specify the covariance matrix, and you're all set.

But what if the random variables need to follow some other marginal distribution than Normal? This is a common task for simulations, where you may know the distributions you want for each variable, but need a way to specify the covariance structure. This is where copulas come in handy, as explained in JD's second post, complete with R code implementing a simulation.

Cerebral Mastication: Even Simpler Multivariate Correlated Simulations

## Comments

You can follow this conversation by subscribing to the comment feed for this post.