Tell me more ×
Cross Validated is a question and answer site for statisticians, data analysts, data miners and data visualization experts. It's 100% free, no registration required.

So, I struggle with Regression a lot. I just found out how to get 2 lines with the same slope, but I cannot manage to get 2 lines with the same intercept. I read about ANCOVA a lot (because I thought this was what I needed), but no one uses the same intercepts; just the same slope. Can someone help out with this?

share|improve this question
what have you tried? – Justin Oct 11 '12 at 16:39
3  
lm(y~x+f:x) ... – Ben Bolker Oct 11 '12 at 16:51
how do I plot this? – cups Oct 11 '12 at 17:24

migrated from stackoverflow.com Oct 11 '12 at 19:31

1 Answer

up vote 3 down vote accepted
library(ggplot2)
set.seed(1)
x <-  1:10
dd <- rbind(data.frame(x=x,fac="a", y=x+rnorm(10)),
            data.frame(x=2*x,fac="b", y=x+rnorm(10)))
coef <- lm(y~x:fac, data=dd)$coefficients
qplot(data=dd, x=x, y=y, color=fac)+
  geom_abline(slope=coef["x:faca"], intercept=coef["(Intercept)"])+
  geom_abline(slope=coef["x:facb"], intercept=coef["(Intercept)"])

enter image description here

share|improve this answer
I have a indicator variable ky which takes values 1 and 2, but if I try to do ["x:ky1"] it says that object does not exist. What am I missing? – cups Oct 12 '12 at 1:17
look at the names of lm(y~x:fac, data=dd)$coefficients – jem77bfp Oct 12 '12 at 6:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.