generating correlated summated scales from random normal variables in r -


i want generate 5 random normal variables in r each given mean , sd

x1 <- rnorm(100,20,5) x2 <- rnorm(100,22,4) y1 <- rnorm(100,21,3) y2 <- rnorm(100,23,4) y3 <- rnorm(100,22,5) 

and summated scales x , y having predefined correlation as

x <- rowsums(cbind(x1,x2)) y <- rowsums(cbind(y1,y2,y3)) cor(x,y) # must 0.6 

i think using loop should inefficient solution this. y=r*x+sqrt(1-r*r)*rnorm(n) not applicable. i'm bit confused how start. suggestion appreciated.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -