# [R] How to get predicted values of y for different x values?

Daniel Malter daniel at umd.edu
Tue Jul 19 23:12:44 CEST 2011

```Please read the posting guide (requires a self-contained example of code) and
consult the help pages before posting. If you type ?predict.lm the help page
clearly states that the argument 'newdata' takes "[a]n optional data frame
in which to look for variables with which to predict..."

x1<-rnorm(100)
x2<-rnorm(100)
e<-rnorm(100)
y<-x1+x2+x1*x2+e
reg<-lm(y~x1*x2)
summary(reg)
predict(reg,newdata=data.frame(x1=2,x2=2))

HTH,
Daniel

halptekin wrote:
>
> Here is my model with interaction terms and control variables (I changed
> variables names for easy read):
>
> reg1 <- lm(y ~ x1*x2*x3 +control1 + control2 + control3)
>
> x1 ranges from 0 to 6; x2 from 0 to 5; and x3 from 0 to 4. All three are
> discrete ordinal variables; but I will treat them as continuous variables.
> (a) How can I see the predicted values of y for each of these scenarios
> (210 y values I guess)?
> (b) How can I see the predicted value of y for the minimum and maximum
> values of x1, x2, and x3 (8 y values)?
> (c) How can I see the predicted value of y for x1=6; x2=5; and x3=4 (only
> one y value)?
>

--
View this message in context: http://r.789695.n4.nabble.com/How-to-get-predicted-values-of-y-for-different-x-values-tp3678658p3679351.html
Sent from the R help mailing list archive at Nabble.com.

```