# [R] problem with abline for x.y

Peter Dalgaard p.dalgaard at biostat.ku.dk
Fri Feb 20 16:02:46 CET 2004

```Michael Friendly <friendly at yorku.ca> writes:

> The data is read in grouped form( galton), and then ungrouped (galton2):
>
> # 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

Not precisely, though.

> 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 thing that you need in the x.y case  is that

x = a + by

implies

y = 1/b x  -  a/b

so you need

cc <- coef(x.y)
abline(-cc/cc, 1/cc, ....)

--
O__  ---- Peter Dalgaard             Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics     2200 Cph. N
(*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907

```