[R] Comparing two regression lines

Christoph Scherber
Wed, 04 Jun 2008 11:37:03 -0000

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

lm(y~x*FACTOR),

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!

Best wishes,
Christoph

##

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

model3=lm(y~x*FACTOR)
summary(model3)

sxx1=sum((y1-mean(y1))^2)
sxx2=sum((y2-mean(y2))^2)

s.pooled=(4805.2+6946.6)/20

SED=sqrt(s.pooled*(1/sxx1+1/sxx2))

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)