[R] Using lm with quadratic term

Achim Zeileis Achim.Zeileis at wu-wien.ac.at
Thu Jan 20 03:33:36 CET 2005


On Wed, 19 Jan 2005 21:20:22 -0500 K Fernandes wrote:

> Hello,
> I would like to use lm to model the equation y=x^2.
> 
> However, when I use
> 
> z<-lm(formula=y~x^2)
> summary(z)
> 
> I obtain results that are equivalent to when I use 
> 
> z<-lm(formula=y~x)
> summary(z)

In formulas "^" specifies interactions. "^2" selects all second order
interactions from the preceeding term.

If you want the arithmetic function "^" you have to insulate the term in
I(), i.e., try to fit
  lm(y ~ I(x^2))

See ?formula for more details.
Z

> That is, using x instead of x^2.
> 
> However, I do get different results when I use
> 
> z<-lm(formula=y~log(x))
> summary(z)
> 
> Does anyone know why this might be the case?  Any ideas are
> appreciated.
> 
> Thank you,
> K
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>




More information about the R-help mailing list