[R] how to extrac one coef from lm at a time
Douglas Bates
bates at stat.wisc.edu
Tue May 21 18:47:50 CEST 2002
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.
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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