Hi,

I've made a research about how to compare two regression line slopes (of y versus x for 2 groups, "group" being a factor ) using R.

I knew the method based on the following statement :
t = (b1 - b2) / sb1,b2
where b1 and b2 are the two slope coefficients and sb1,b2 the pooled standard error of the slope (b)

which can be calculated in R this way:
> df1 <- data.frame(x=1:3, y=1:3+rnorm(3))
> df2 <- data.frame(x=1:3, y=1:3+rnorm(3))
> fit1 <- lm(y~x, df1)
> s1 <- summary(fit1)$coefficients
> fit2 <- lm(y~x, df2)
> s2 <- summary(fit2)$coefficients
> db <- (s2[2,1]-s1[2,1])
> sd <- sqrt(s2[2,2]^2+s1[2,2]^2)
> df <- (fit1$df.residual+fit2$df.residual)
> td <- db/sd
> 2*pt(-abs(td), df)
[1] 0.9510506

However, I also found a procedure in Wonnacott & Wonnacott, that is based on the use of a mute variable D that will have a binary value according to the group to which a given point belongs (group : D=0; group 2: D=1). Then the equation that is computed is as follow:
y = b0 + b1.x + D.b2.x

which can be computed in R with:
> fit <- lm(y ~ group + x + x:group)
where y is the response of the 2 groups.
The p-value of x:group gives the probability for the two slopes to be different, and the estimated values of parameters are these of both populations.

These two methods have already been described in the mailing list but not confronted and discussed.
So, my questions are:
- are these methods different ?
- which one should be preferentially used ?

This is not really a question about R but more about statistics…

I don't think I'm really clear and I know I'm not rigorous at all in my descriptions, but I hope someone will understand me.

Thanks,

Etienne

-------------------------------------------------------------------
Etienne Toffin, PhD Student
Unit of Social Ecology
Université Libre de Bruxelles, CP 231
Boulevard du Triomphe
B-1050 Brussels
Belgium

Tel: +32(0)2/650.55.30
Fax: +32(0)/650.59.87
Skype: etienne_titou
http://www.ulb.ac.be/sciences/use/toffin.html

______________________________________________
R-help@r-project.org 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.

Reply via email to