[R] fittin a regression line

Douglas Bates bates at stat.wisc.edu
Tue Mar 14 15:01:14 CET 2000


sht103 <sht103 at york.ac.uk> writes:

> I have tried to find a command to fit(plot) a regression line but I
> haven't found any command on the html.help.  My question is if I am
> using a regression for instance reg<-lm(y~x) and I would like to
> make a regression line, to see how well my data is fit.  Can you
> please help me with this??

A simple linear regression line can be added to a plot with abline.
For more complicated models, you should generate a sequence of x
values at which you wish to evaluate the model and use the predict
method to get the y values.

The simple case looks like

 plot( y ~ x )
 fm <- lm( y ~ x)
 abline( fm )
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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