[R] Comparing two regression lines
Christoph.Scherber at agr.uni-goettingen.de
Wed Jun 4 13:37:03 CEST 2008
Dear R users,
Suppose I have two different response variables y1, y2 that I regress separately on the same
explanatory variable, x; sample sizes are n1=n2.
Is it legitimate to compare the regression slopes (equal variances assumed) by using
where FACTOR gets "y1" if y1 is the response, and "y2" if y2 is the response?
The problem I see here is that the residual degrees of freedom obviously go up (n1-1+n2-1) although
there were only n1=n2 "true" replications.
On the other hand, Zar (1984) and some other statistics textbooks base their calculations on a
modified version of the t test (mainly using the residual SS from the two regressions), but when I
calculated these tests by hand I found that the t-values are almost identical to the one I get using
the lm(...) approach.
Part of the R script is appended below.
How would you proceed?
Many thanks for your help!
lm1=lm(y1~x) # y1 and y2 are different response variables, scaled to [0;1] using a ranging transform
lm2=lm(y2~x) # n is 12 for each regression
t=(528.54-446.004)/SED #residual SS from lm1 and lm2 divided by SED
qt(0.025,20) #compare with t distribution at 20 d.f.
#(using R 2.6.2 on Windows XP)
More information about the R-help