[R] How to generate multivariate uniform distribution random

G. Jay Kerns gkerns at ysu.edu
Sun Nov 7 01:05:00 CET 2010


Dear Michael,

On Sat, Nov 6, 2010 at 7:27 PM, michael <tufemichael at gmail.com> wrote:
> Ted,
>
>      Thanks for your help, it is right on the money!
>
> for your comments:
> 1. Yes I mean 100 by 2, each variable x1, x2 is 100 by 1.
> 2. The correlation is the only free parameter.
>
> Michael
>
>

I like Ted's solution.  If all you are looking for is unif(0,1), you
could use the Probability Integral Transform;  something like this:

set.seed(1)

library(MASS)
S <- matrix(c(1, 0.9, 0.9, 1), nrow = 2)
X <- mvrnorm(100, mu = c(0,0), Sigma = S)
Y <- pnorm(X)

var(Y)
cor(Y)

You could also use copulas, but those depend on contributed packages
(and you can read more about them on the CRAN Task View for
probability distributions).

Hope this helps,
Jay


__________________________
G. Jay Kerns, Ph.D.
Youngstown State University
http://people.ysu.edu/~gkerns/



More information about the R-help mailing list