From: ken knoblauch <knoblauch_at_lyon.inserm.fr>

Date: Fri 12 Jan 2007 - 09:47:40 GMT

cc <- coef(lm(x ~ y))

abline (-cc[1]/cc[2], 1/cc[2])

}

R-help@stat.math.ethz.ch mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Fri Jan 12 20:53:42 2007

Date: Fri 12 Jan 2007 - 09:47:40 GMT

Try this version of your function and then think about it

tst <- function () {

attach (attitude)

x <- rating

y <- learning

detach (attitude)

plot (x, y)

abline(v=mean(x)) abline(h=mean(y)) abline (lm(y~x))

cc <- coef(lm(x ~ y))

abline (-cc[1]/cc[2], 1/cc[2])

}

> 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?
**>
**> 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))
**> }
*

[[alternative text/enriched version deleted]]

R-help@stat.math.ethz.ch mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Fri Jan 12 20:53:42 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 - 10:30:28 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.
*