[R] Problem with LM
Bert Gunter
bgunter@4567 @ending from gm@il@com
Wed Dec 19 05:19:33 CET 2018
... Perhaps worth adding is the use of poly() rather than separately
created terms for (non/orthogonal) polynomials:
lm(y ~ poly(x, degree =2) #orthogonal polyomial of degree 2
see ?poly for details.
-- Bert
Bert Gunter
"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
On Tue, Dec 18, 2018 at 6:14 PM rsherry8 <rsherry8 using comcast.net> wrote:
> Richard,
>
> It is now working.
>
> Thank you very much.
>
> Bob
> On 12/18/2018 7:10 PM, Richard M. Heiberger wrote:
> > ## This example, with your variable names, works correctly.
> >
> > z2 <- data.frame(y=1:5, x=c(1,5,2,3,5), x2=c(1,5,2,3,5)^2)
> > z2
> > class(z2)
> > length(z2)
> > dim(z2)
> >
> > lm(y ~ x + x2, data=z2)
> >
> > ## note that that variable names y, x, x2 are column names of the
> > ## data.frame z2
> >
> > ## please review the definitions and examples of data.frame in
> ?data.frame
> > ## also the argument requirements for lm in ?lm
> >
> > On Tue, Dec 18, 2018 at 6:32 PM rsherry8 <rsherry8 using comcast.net> wrote:
> >> The values read into z2 came from a CSV file. Please consider this R
> >> session:
> >>
> >> > length(x2)
> >> [1] 1632
> >> > length(x)
> >> [1] 1632
> >> > length(z2)
> >> [1] 1632
> >> > head(z2)
> >> [1] 28914.0 28960.5 28994.5 29083.0 29083.0 29083.0
> >> > tail(z2)
> >> [1] 32729.65 32751.85 32386.05 32379.75 32379.15 31977.15
> >> > lm ( y ~ x2 + x, z2 )
> >> Error in eval(predvars, data, env) :
> >> numeric 'envir' arg not of length one
> >> > lm ( y ~ x2 + x, as.data.frme(z2) )
> >> Error in as.data.frme(z2) : could not find function "as.data.frme"
> >> > lm ( y ~ x2 + x, as.data.frame(z2) )
> >> Error in eval(predvars, data, env) :
> >> numeric 'envir' arg not of length one
> >> lm(formula = y ~ x2 + x, data = as.data.frame(z2))
> >>
> >> Coefficients:
> >> (Intercept) x2 x
> >> -1.475e-09 1.000e+00 6.044e-13
> >>
> >> > min(z2)
> >> [1] 24420
> >> > max(z2)
> >> [1] 35524.85
> >> > class(z2)
> >> [1] "numeric"
> >> >
> >>
> >> where x is set to x = seq(1:1632)
> >> and x2 is set to x^2
> >>
> >> I am looking for an interpolating polynomial of the form:
> >> Ax^2 + Bx + C
> >> I do not think the results I got make sense. I believe that I have a
> >> data type error. I do not understand why
> >> I need to convert z2 to a data frame if it is already numeric.
> >>
> >> Thanks,
> >> Bob
> >>
> >> ______________________________________________
> >> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >> 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.
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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]]
More information about the R-help
mailing list