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

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

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

android - How to create dynamically Fragment pager adapter -