JWH2006
JWH2006

Reputation: 239

Is there an elegant way to generate correlated simulated variables in R?

I would like to generate 10 values per observation, on different scales, but have these values be correlated with each other.

My initial thinking was to generate an initial vector of values using a normal distribution and then using this as a "weight" to generate the remaining 9 values.

For example use rnorm to generate the values then have that value be a weight on the mean used for the remaining nine values generated using rnorm.

What I would like to know is if there is a more elegant way to do this.

To give an example of what I would like to do, imagine grades on tests: a student observation is assigned a 1400 on their SAT and using that I would generate an ACT score, IQ score, etc using the corresponding means and modified standard deviations.

Upvotes: 0

Views: 142

Answers (1)

Anders Ellern Bilgrau
Anders Ellern Bilgrau

Reputation: 10223

I think your approach is fairly elegant and simple:

n <- 10
x <- rnorm(n, mean = 0, sd = 1)
y <- 2.7*x + rnorm(n, mean = 0, sd = 0.6)
plot(x,y)

enter image description here

Why is that not OK?

Upvotes: 1

Related Questions