# How to judge a series of linear regressions are parallel?

Assume there are three groups of data:

x1 = [1, 2, 3, 4, 5]; y1 = [2.1, 4.3, 6.7, 8.2, 10.3]

x2 = [2, 4, 6, 8, 10]; y2 = [4.1, 8.25, 12.21, 16.33, 20.47]

x3 = [1, 3, 5, 7, 9]; y4 = [2.08, 6.23, 10.11, 14.27, 18.63]


We could get three linear equations from such data by using python or R:

y1 = 2.03x1+0.23

y2 = 2.04x2+0.027

y3 = 2.057x3-0.021


It seems we could conclude that these three linear regressions are parallel because their slope is fairly close to 2. But I have no idea whether or not there is a convenient approach to prove my guess.

I have tried to use chow-test, but chow-test is always used in time-series data. I have also tried to use ANCOVA, but I'm not sure whether or not it is valid.

Can someone provide me another method to test such linear regressions are parallel? Or give me some advice about how to use the chow-test or ANCOVA to prove my guess? Thank you for your helping.

• You already figured out that the factor before the x defines the slope and therefore linear functions with the same factor are parralel. So, what else do you want to prove? – Klaus D. Dec 25 '18 at 3:56
• @KlausD. "It seems we could conclude that these three linear regressions are parallel because their slope is fairly close to 2. But I have no idea whether or not there is a convenient approach to prove my guess." - I think that's the question really – Vivek Kalyanarangan Dec 25 '18 at 5:26
• Yes, the Chow test is fine. – DavidPM Dec 25 '18 at 11:46

You can do an F-test and compare

• the residuals when you use the three different models with different slopes

versus

• the residuals when you use a single model (single same equation, slope 2.0469, for all three groups of data).

This is basically the same answer as Artem, but more explicit. The F-test is the test performed. This also relates to the Chow test that is mentioned in the question. In Chow's article

To test the equality between sets of coefficients in two linear regressions, we obtain the sum of squares of the residuals assuming the equality, and the sum of squares without assuming the equality. The ratio of the difference between these two sums to the latter sum, adjusted for the corresponding degrees of freedom, will be distributed as the F ratio under the null hypothesis.

an important distinction with Chow's test and a plain ANCOVA for finding difference between two or more models is

This latter sum of squares will be computed only from the first sample of $$n$$ observations when the second sample is not large enough

This is not your case as you have samples of size 5 to estimate 1 parameter.

The case with more than two regressions is just a generalization, which Chow mentioned himself as well.

While we have dealt with the comparison of coefficients in only two regressions, the proofs of (29) and (50) can obviously be generalized to the case of many regressions.

code example

x = c(1,    2,      3,      4,      5,
2,    4,      6,      8,     10,
1,    3,      5,      7,      9)
y = c(2.1,  4.30,   6.70,   8.20,  10.30,
4.1,  8.25,  12.21,  16.33,  20.47,
2.08, 6.23,  10.11,  14.27,  18.63)
t = as.factor(
c(  1,    1,     1,       1,      1,
2,    2,     2,       2,      2,
3,    3,     3,       3,      3))

# model 1 (different slopes)
mod_complete <- lm(y~0+t+x:t)
mod_complete
# model 2 (same slope)
mod_simple <- lm(y~0+t+x)
mod_simple

# compare whether it improves
anova(mod_simple, mod_complete)
# the fit does not improve sufficiently
#
# RSS (sum of squared residuals) only decrease from from 0.279 to 0.271
# this is considered not siginficant
# (siginficance is tested by F-test
#     which includes
#         degrees of freedom into the comparison or RSS)
#
# Thus there is no reason to reject
# the (null / no effect) hypothesis that the lines have the same slope
#


outputs:

> anova(mod_simple, mod_complete)
Analysis of Variance Table

Model 1: y ~ 0 + t + x
Model 2: y ~ 0 + t + x:t
Res.Df     RSS Df Sum of Sq      F Pr(>F)
1     11 0.27933
2      9 0.27100  2 0.0083289 0.1383 0.8727

Model 1: y ~ 0 + t + x Model 2: y ~ 0 + t + x:t   Res.Df     RSS Df Sum of Sq      F Pr(>F) 1     11 0.27933                            2  9 0.27100  2 0.0083289 0.1383 0.8727

> mod_complete

Call:
lm(formula = y ~ 0 + t + x:t)

Coefficients:
t1      t2      t3    t1:x    t2:x    t3:x
0.230   0.026  -0.021   2.030   2.041   2.057

> mod_simple

Call:
lm(formula = y ~ 0 + t + x)

Coefficients:
t1         t2         t3          x
0.179333  -0.009333   0.029556   2.046889


You can make use of separate regression for each group and linear hypothesis test in car package as follows:

• pool the data into one data frame;
• assign for each group id value;
• make linear model with x nested withinid (/ in lm formula);
• check linear hypothesys that regression coefficients equal each other.

x1 <- c(1, 2, 3, 4, 5)
y1 <- c(2.1, 4.3, 6.7, 8.2, 10.3)
x2 <- c(2, 4, 6, 8, 10)
y2 <- c(4.1, 8.25, 12.21, 16.33, 20.47)
x3 <- c(1, 3, 5, 7, 9)
y3 <- c(2.08, 6.23, 10.11, 14.27, 18.63)

df <- data.frame(id = unlist(lapply(letters[1:3], rep, 5)), x = c(x1, x2, x3), y = c(y1, y2, y3))
m <- lm(y ~ id / x, data = df)

library(car)
linearHypothesis(m, c("ida:x = idb:x", "idb:x =idc:x"))


Output:

Linear hypothesis test

Hypothesis:
ida:x - idb:x = 0
idb:x - idc:x = 0

Model 1: restricted model
Model 2: y ~ id/x

Res.Df     RSS Df Sum of Sq      F Pr(>F)
1     11 0.27933
2      9 0.27100  2 0.0083289 0.1383 0.8727

# Not rejected