Hello R users,
I've used the following help two compare two regression line slopes.
Wanted to test if they differ significantly:
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)
My value I get by running this test is :[1] 2.305553e-07
Does it mean the two slopes differ significantly, because this value is in
the alpha area, so that I have to reject the null- hypothesis and accept
the alternative hypothesis?
Is the null-hypothesis: slope1=slope2?
Thanks for your help, Benedikt
--