Reputation:
I want to find a way to randomly generate 100 Y values from a linear model where
Yi= 2−8Xi+ ei
I want the residuals (ei) to come from a normal distribution with a specified mean and variance and X to be a vector of values from 1:100.
I know how to generate random variates using rnorm() but I'm not sure how to approach this more advanced matter. Any ideas for how I can specify the parameters I need would be welcome.
Upvotes: 0
Views: 611
Reputation: 37879
This should work:
X <- 1:100
Y <- 2 − 8 * X + rnorm(100, mean = 0, sd = 2)
str(Y)
#num [1:100] -3.51 -12.03 -21.05 -31.38 -36.46 ...
Upvotes: 2