[R] Correlated Multivariate Distribution Generator

Yue Yu parn.yy at gmail.com
Wed Jul 27 21:17:39 CEST 2011


Thanks, Enrico and Harold.

I have searched the archives for this topic, but all I can find is
about the multivariate normal or uniform generator, which doesn't help
in my case.

Harold's transformation is good for getting the correlation, but the
negative binomial distribution will be changed after transformation,
won't keep the desired parameters r and p.

Enrico's method is brilliant for rank correlation, is there any
algorithm for linear correlation? Even some references for
multivariate negative binomial generator will help.

Your help are really appreciated

Best,

Yue Yu

On Wed, Jul 27, 2011 at 11:31, Doran, Harold <HDoran at air.org> wrote:
> 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.
>



More information about the R-help mailing list