[R] How to get predicted values of y for different x values?
David Winsemius
dwinsemius at comcast.net
Tue Jul 19 21:14:58 CEST 2011
On Jul 19, 2011, at 2:36 PM, Jeff Newmiller wrote:
> ?predict
>
> Use data.frame() to generate input vectors (newdata) for which you
> want predicted values.
The OP probably needs to use expand.grid to generate the spanning
combinations of x values. He will in addition need to include values
for "control" variables.
dfrm <- expand.grid(x1 = 0: 6, x2 = 0: 5, x3 = 0 : 4)
dfrm$control1 <- <some value of same class as original control1 data>
repeat x 2
--
David.
> ---------------------------------------------------------------------------
> Jeff Newmiller The ..... ..... Go Live...
> DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go...
> Live: OO#.. Dead: OO#.. Playing
> Research Engineer (Solar/Batteries O.O#. #.O#. with
> /Software/Embedded Controllers) .OO#. .OO#. rocks...1k
> ---------------------------------------------------------------------------
> Sent from my phone. Please excuse my brevity.
>
> halptekin <halptekin at gmail.com> 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
> scenarios I guess)?
> (b) How can I see the predicted value of y for the minimum and maximum
> values of x1, x2, and x3 (8 scenarios)?
> (c) How can I see the predicted value of y for x1=6; x2=5; and x3=4 (1
> scenario)?
>
> --
> View this message in context: http://r.789695.n4.nabble.com/How-to-get-predicted-values-of-y-for-different-x-values-tp3678662p3678662.html
> Sent from the R help mailing list archive at Nabble.com.
>
> _____________________________________________
>
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
David Winsemius, MD
West Hartford, CT
More information about the R-help
mailing list