[R] Regression on non linear model

Prof Brian D Ripley ripley at stats.ox.ac.uk
Thu Oct 14 08:38:39 CEST 1999


On 13 Oct 1999, Douglas Bates wrote:

> Peppy <s.adi.purnomo at EnergyLink.co.nz> writes:
> 
> > I have a model that I believe to be non linear.  The relationship is
> > something like:
> > 
> > Response = Var1 + Var1^2 + Var1^3
> 
> In terms of the way the parameters enter the model, this is still a
> linear model, even though it is nonlinear in terms of the variable.
> 
> > Can I examine this relationship using glm or lm?  However, glm or lm gives
> > out pnly 1 coeficient for the model which is on Var1,  unless I created some
> > dummy var like (Var2 = Var1^2 and Var3 = Var1^3).
> 
> You are correct.  This is a deficiency in the model formula language
> used in R.  The meaning of the ^2 operator in formulas is appropriate
> for factors but not the expected meaning for numeric variables.
> 
> > Is there any other function handling this relationship?  
> 
> The preferred way to do this is to use the I() function to protect
> the ^2 and ^3 from being evaluated as part of the linear model
> formula.  That is, write the call to lm with
> 
>  formula = Response ~ Var1 + I(Var1^2) + I(Var1^3)

I was doing this in a practical class yesterday. There is another way,

Response ~ poly(Var1, 3)

which fits the same cubic model by using orthogonal polynomials, and
that has a number of numerical and statistical advantages. The fitted
values will be the same, but the coefficients are those of the orthogonal
polynomials, not the terms in the polynomial.  As I was telling my
students, you might like to compare the two approaches.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list