[Rd] abline for intercept-only simple lm models (with and without offset)

From: Tobias Verbeke <tobias.verbeke_at_telenet.be>
Date: Sat 09 Dec 2006 - 21:42:38 GMT

The abline function can be used to draw the regression line when one passes the lm object as an argument.

However, if it's an intercept-only model, it appears to use the intercept
as the slope of the abline:

mod <- lm(dist ~ 1, data = cars)
plot(dist ~ speed, data = cars)
abline(reg = mod) # nothing appears

This behaves as documented, but might catch someone. Would it be an improvement
if this situation was detected so as to plot the appropriate horizontal line, i.e.

abline(a = coef(mod), b = 0) ?

Would it also be an improvement if for
a model like

mod2 <- lm(dist ~ 1 + offset(speed), data = cars)

abline(reg = mod2) would be equivalent to

abline(a = coef(mod2), b = 1) ?

For models through the origin, the current function works fine, but one might even
consider models through the origin and
having the independent variable in an offset() to be fully fool-proof, i.e.

abline(a = 0, b = 1)

Kind regards,

R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Sun Dec 10 12:55:17 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Mon 11 Dec 2006 - 21:30:59 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.