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
Hi Yue Yu, similar questions have been discussed several times on this list; you may want to search the archives. Do you mean linear correlation, or rank correlation? In general, a given linear correlation will not always be attainable (though in your case, it probably will). If _rank_ correlation is fine, you could do something like this: (1) create Gaussians X with a given linear correlation (which is almost identical to rank correlation in the Gaussian case, but you can even correct this*) (2) put X into the distribution function of the normal: you get uniforms U. Since the distribution function is monotone, the rank correlation will remain unaltered. Hence the U are (rank-)correlated just as the X. (3) put U into the inverse of the desired distribution function. The inverse is mononote as well, so the rank correlation remains the same. [This approach will only be practical if you can compute the inverse reasonably fast.] Regards, Enrico * see, eg, http://papers.ssrn.com/sol3/papers.cfm?abstract_id=1681917> -----Urspr?ngliche Nachricht----- > Von: r-help-bounces at r-project.org > [mailto:r-help-bounces at r-project.org] Im Auftrag von Yue Yu > Gesendet: Mittwoch, 27. Juli 2011 05:01 > An: r-help at r-project.org > Betreff: [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.
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.