[R] problem with abline for x.y

Michael Friendly friendly at yorku.ca
Fri Feb 20 15:17:37 CET 2004


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]

attach(galton)
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)
abline(y.x)
x.y <- lm(child ~ parent, weights=frequency)
abline(x.y, col="gray")

attach(galton2)
y.x <- lm(parent ~ child)
abline(y.x, lwd=2)
x.y <- lm(child ~ parent)
abline(x.y, col="gray", lwd=2)

library(car)
data.ellipse(child, parent, plot.points=FALSE, levels=c(0.40, 0.68), lty=2)

The resulting figure may be seen at
http://euclid.psych.yorku.ca/SCS/Gallery/Private/galton.jpg

-Michael

-- 
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




More information about the R-help mailing list