[R] problem with abline for x.y

John Fox jfox at mcmaster.ca
Fri Feb 20 16:12:50 CET 2004

Dear Mike,

I believe that the following is the problem: For the regression of x on y, 
you have to move y to the left-hand-side of the equation to plot the line 
in {x, y}; so if the regression equation from the model x.y is x = a + b y, 
you need abline(-a/b, 1/b).

I hope that this helps,

At 09:17 AM 2/20/2004 -0500, Michael Friendly wrote:
>I'm trying to do a sunflowerplot of Galton's data, with both regression 
>lines and data ellipses,
>and I must be doing something wrong, because the lines do not intersect at 
>\bar{x}, \bar{y}.
>The problem is likely in the line for x.y, but I don't know how to specify 
>that correctly.
>The data is read in grouped form( galton), and then ungrouped (galton2):
>galton <- read.table("~/sasuser/data/galton.txt", header=TRUE)
># ungroup
>galton2<-galton[rep(1:nrow(galton), galton$frequency), 1:2]
>sunflowerplot(child, parent, number=frequency, xlim=c(61,75), ylim=c(61,75),
>    xlab="Child height", ylab="Mid Parent height")
># both attempts plot the same, wrong regression lines
>y.x <- lm(parent ~ child, weights=frequency)
>x.y <- lm(child ~ parent, weights=frequency)
>abline(x.y, col="gray")
>y.x <- lm(parent ~ child)
>abline(y.x, lwd=2)
>x.y <- lm(child ~ parent)
>abline(x.y, col="gray", lwd=2)
>data.ellipse(child, parent, plot.points=FALSE, levels=c(0.40, 0.68), lty=2)
>The resulting figure may be seen at
>Michael Friendly     Email: friendly at yorku.ca Professor, Psychology Dept.
>York University      Voice: 416 736-5115 x66249 Fax: 416 736-5814
>4700 Keele Street    http://www.math.yorku.ca/SCS/friendly.html
>Toronto, ONT  M3J 1P3 CANADA
>R-help at stat.math.ethz.ch mailing list
>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

John Fox
Department of Sociology
McMaster University
Hamilton, Ontario, Canada L8S 4M4
email: jfox at mcmaster.ca
phone: 905-525-9140x23604
web: www.socsci.mcmaster.ca/jfox

More information about the R-help mailing list