[R] Correlated Multivariate Distribution Generator

Doran, Harold
Wed, 27 Jul 2011 16:31:45 -0000

Do you mean something like this?

> cors <- matrix(c(1, .9, .8, .8, .9, 1, .8, .8, .8, .8, 1, .9, .8, .8,
.9, 1), 4)
> L <- chol(cors)
> N <- 1000
> dat <- cbind(rnbinom(N, mu = 4, size = 1), rnbinom(N, mu = 4, size = 1),
rnbinom(N, mu = 4, size = 1), rnbinom(N, mu = 4, size = 1))
> result <- dat %*% L
> cor(dat)
           [,1]        [,2]        [,3]       [,4]
[1,] 1.00000000  0.04227103  0.00358846 0.02860722
[2,] 0.04227103  1.00000000 -0.03122457 0.03070221
[3,] 0.00358846 -0.03122457  1.00000000 0.04621639
[4,] 0.02860722  0.03070221  0.04621639 1.00000000

> cor(result)
          [,1]      [,2]      [,3]      [,4]
[1,] 1.0000000 0.9021538 0.8183199 0.8158886
[2,] 0.9021538 1.0000000 0.8114415 0.8152286
[3,] 0.8183199 0.8114415 1.0000000 0.9145778
[4,] 0.8158886 0.8152286 0.9145778 1.0000000



> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at
r-project.org] On
> Behalf Of Yue Yu
> Sent: Tuesday, July 26, 2011 11:01 PM
> To: r-help at r-project.org
> Subject: [R] Correlated Multivariate Distribution Generator
>
> Dear R User,
>
> I am wondering if there is a way to generate correlated multivariate
> non-normal distribution?
>
> For example, I want to generate four correlated negative binomial
> series with parameters r=10, p=0.2, based on the correlation
> coefficient matrix
> |   1   0.9  0.8  0.8 |
> | 0.9     1  0.8  0.8 |
> | 0.8  0.8     1  0.9 |
> | 0.8  0.8  0.9     1 |
>
> Thank a lot.
>
> Best,
>
> Yue Yu
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.