[R] generate two sets of random numbers that are correlated

Albyn Jones jones at reed.edu
Thu Aug 11 19:38:14 CEST 2011


Here is a simple method

z1 <- rpois(n,mu1)
z2 <- rpois(n,mu1)
z3 <- rpois(n,mu2)

Y <- z1 + z3
X <- z2 + z3

Cov(X,Y) = mu2, so Cor(X,Y) = mu2/(mu1+mu2)

albyn

On Thu, Aug 11, 2011 at 09:01:50AM -0700, Kathie wrote:
> almost forgot. In fact, I want to generate correlated Poisson random vectors.
> Thank you anyway
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/generate-two-sets-of-random-numbers-that-are-correlated-tp3736161p3736287.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> 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.
> 

-- 
Albyn Jones
Reed College
jones at reed.edu



More information about the R-help mailing list