# Re: [R] Regression lines

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Fri 12 Jan 2007 - 10:01:47 GMT

On Fri, 12 Jan 2007, Tom Backer Johnsen wrote:

> My simpleminded understanding of simple regression is that when
> plotting regression lines for x on y and y on x in the same plot, the
> lines should cross each other at the respective means. But, given the
> R function below, abline (lm(y~x)) works fine, but abline (lm(x~y))
> does not. Why?

reg is a regression object with a coef method. If this returns a vector    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.

There are some changes in R-devel, but not to recognize names of coefficients.

> function () {
> attach (attitude)
> x <- rating
> y <- learning
> detach (attitude)
> plot (x, y)
> abline(v=mean(x))
> abline(h=mean(y))
> abline (lm(y~x))
> abline (lm(x~y))
> }
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> and provide commented, minimal, self-contained, reproducible code.
>

```--
Brian D. Ripley,                  ripley@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 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
and provide commented, minimal, self-contained, reproducible code.
```
Received on Fri Jan 12 21:13:56 2007

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 Fri 12 Jan 2007 - 11:30:27 GMT.

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