[R] Generating random numbers satisfying specific regression equation

John Sorkin JSorkin at grecc.umaryland.edu
Sat May 25 14:18:57 CEST 2013

(1) you need to examine the rnorm function, enter 
(2) when you review the documentation produced by entering the command
above, you will see that the rnorm function needs three parameter, the
number of values to generate, the mean of the numbers to be generated,
and the SD (standard deviation) of the numbers to be generated. Two of
these values have default values, mean defaults to zero, SD to one.
(3) You then use rnorm in your formula:
x <- rnorm(10)
y <- rnorm(10)
z <- 0.3 + 0.05*x + 1.5*y + 3*x*y

>>> "Tobias Kisch" <tobiaskisch at hotmail.com> 5/25/2013 5:50 AM >>>
Hello everybody

Sorry if such a question has already been posted somewhere, but I
wasn’t able to find an answer yet.
I’m trying to generate random numbers for illustration purposes.

The random numbers should satisfy a multiple regression equation, for

z = 0.3 + 0.05 * x + 1.5 * y + 3 * xy

I was playing around with mvrnorm (MASS), but since I’m still a newbie
to R and not an educated statistician and wasn’t able to solve this.

Thanks for any suggestions or hints.

[[alternative HTML version deleted]]

Confidentiality Statement:
This email message, including any attachments, is for the sole use of
the intended recipient(s) and may contain confidential and privileged
information.  Any unauthorized use, disclosure or distribution is
prohibited.  If you are not the intended recipient, please contact the
sender by reply email and destroy all copies of the original message. 

More information about the R-help mailing list