[R] how to extrac one coef from lm at a time

ripley@stats.ox.ac.uk ripley at stats.ox.ac.uk
Tue May 21 18:59:28 CEST 2002


On 21 May 2002, Douglas Bates wrote:

> Thomas Lumley <tlumley at u.washington.edu> writes:
>
> > On Tue, 21 May 2002, Jonathan Baron wrote:
> >
> > > On 05/21/02 12:07, Antonio Olinto wrote:
> > > >How to extract the elevation and the slope values from a linear model (lm)
> > > >separately?
> > > >
> > > >coef(model.lm) gives both of them.
> > >
> > > One way is
> > > model.lm$coef[1]
> > > for the intercept
> > > and
> > > model.lm$coef[2]
> > > for the slope of the first predictor, and so on.
> >
> > coef(model.lm)[2]
> > or
> > coef(model.lm)["x"]
> >
> > are preferred -- the point of accessor functions like coef() is to hide
> > the inner structure of the model object. For coef() it doesn't matter a
> > lot, but there are plenty of models for which model$resid is not the same
> > as resid(model).
>
> For an nls model it matters whether you use coef(model.nls) or
> model.nls$coef.

And for an aov one.

-- 
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