[R] using abline and a fitted 2nd degree formula

2005-11-09 Thread CG Pettersson
Hello all,

R2.1.1, Wk2

I am doing some two-step plotting, first using plot() to illustrate the
datapoints and then using abline() to place a trend line from a fitted
model into the plot.

Everything works well as long as the formula of the fitted model i of the
type:

m1 - lm(Dependent ~ Independent)
then abline(m1) puts the proper straight line into the plot.

But if I use:

m2 - lm(Dependent ~ Independent + I(Independent^2))
abline(m2) produces a straight line, only from the first order term.

Why, and what should I do about it?

Cheers
/CG




-- 
CG Pettersson, MSci, PhD Stud.
Swedish University of Agricultural Sciences (SLU)
Dep. of Crop Production Ekology. Box 7043.
SE-750 07 Uppsala, Sweden
[EMAIL PROTECTED]

__
R-help@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


Re: [R] using abline and a fitted 2nd degree formula

2005-11-09 Thread Prof Brian Ripley
On Wed, 9 Nov 2005, CG Pettersson wrote:

 Hello all,

 R2.1.1, Wk2
   ^^^  week 2?
 I am doing some two-step plotting, first using plot() to illustrate the
 datapoints and then using abline() to place a trend line from a fitted
 model into the plot.

 Everything works well as long as the formula of the fitted model i of the
 type:

 m1 - lm(Dependent ~ Independent)
 then abline(m1) puts the proper straight line into the plot.

 But if I use:

 m2 - lm(Dependent ~ Independent + I(Independent^2))
 abline(m2) produces a straight line, only from the first order term.

 Why, and what should I do about it?

Why: because that is what it is documented to do:

  'reg' is a regression object which contains 'reg$coef'.  If it is
  of length 1 then the value is taken to be the slope of a line
  through the origin, otherwise, the first 2 values are taken to be
  the intercept and slope.

What to do about it: first, read the help page and second, use predict and 
lines.  There is an example of the latter on ?cars.

-- 
Brian D. Ripley,  [EMAIL PROTECTED]
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 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
R-help@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