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

2011-08-14 Thread Michael Dewey
At 17:01 11/08/2011, Kathie wrote: almost forgot. In fact, I want to generate correlated Poisson random vectors. Kathie Typing generate random poisson into the R Site Search gives a number of hits. Does any of them do what you require? Thank you anyway -- View this message in context: htt

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

2011-08-11 Thread Duncan Murdoch
On 11/08/2011 1:33 PM, Duncan Murdoch wrote: On 11/08/2011 12:01 PM, Kathie wrote: > almost forgot. In fact, I want to generate correlated Poisson random vectors. Saying you want two random variables to be correlated doesn't specify the joint distribution, so there will be a lot of solutions.

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

2011-08-11 Thread Albyn Jones
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. >

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

2011-08-11 Thread Duncan Murdoch
On 11/08/2011 12:01 PM, Kathie wrote: almost forgot. In fact, I want to generate correlated Poisson random vectors. Saying you want two random variables to be correlated doesn't specify the joint distribution, so there will be a lot of solutions. Here's one, for the case where both variables

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

2011-08-11 Thread Kathie
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. __

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

2011-08-11 Thread Ista Zahn
If you want random numbers sampled from the normal distribution, you can use the mvrnorm function in MASS. Best, Ista On Thu, Aug 11, 2011 at 8:23 AM, Kathie wrote: > Dear R users > > I'd like to generate two sets of random numbers with a fixed correlation > coefficient, say .4, using R. > > Any

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

2011-08-11 Thread R. Michael Weylandt
Well, without saying what sort of random numbers you mean, it's a little hard, but here's one straightforward way to do it for 2 normally distributed rvs. X1 = rnorm(100) X2 = rnorm(100) Y = X1 Z = 0.4*X1+sqrt(1-0.4)*X2 then cor(Y,Z) ~ 0.4 In function terms: CorrNorm <- function(n=100, rho =

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

2011-08-11 Thread Kathie
Dear R users I'd like to generate two sets of random numbers with a fixed correlation coefficient, say .4, using R. Any suggestion will be greatly appreciated. Regards, Kathryn Lord -- View this message in context: http://r.789695.n4.nabble.com/generate-two-sets-of-random-numbers-that-are-co