Re: [R] testing for significantly different slopes

From: <>
Date: Thu, 06 Mar 2008 09:38:07 +1000

Generically, let y be the response, f the factor and x the covariate. Then

pModel <- lm(y ~ f + x, data) # parallel regressions sModel <- lm(y ~ f/x, data) # separate regressions (the '-1' is optional)
anova(pModel, sModel) # tests whether there are differences in slopes.

In the example you quote below (which seems oddly familiar...) there are only two classes so you get only 1 degree of freedom. Since the tail area is 0.064, a strict 5% straight-up-and-down frequentist would say you retain the null hypothesis of parallel regressions (i.e. equal slopes) at the 0.05 level, but a cautious fence sitter would keep a watchful eye on the evidence.

The same logic applies however many classes the factor has, (or for that matter however many covariates). You just get more degrees of freedom for the test, and more ways things can depart from parallelism.

What's the problem?

Bill Venables
CSIRO Laboratories
PO Box 120, Cleveland, 4163

Office Phone (email preferred): +61 7 3826 7251
Fax (if absolutely necessary):  +61 7 3826 7304
Mobile:                         +61 4 8819 4402
Home Phone:                     +61 7 3286 7700

-----Original Message-----
From: [] On Behalf Of Dylan Beaudette
Sent: Thursday, 6 March 2008 9:28 AM
Subject: [R] testing for significantly different slopes


How would one go about determining if the slope terms from an analysis of
covariance model are different from eachother?

Based on the example from MASS:


# parallel slope model

l.para <- lm(Temp ~ Gas + Insul, data=whiteside)

# multiple slope model

l.mult <- lm(Temp ~ Insul/Gas -1, data=whiteside)

# compare nested models:
anova(l.para, l.mult)
Analysis of Variance Table

Model 1: Temp ~ Gas + Insul
Model 2: Temp ~ Insul/Gas - 1

  Res.Df    RSS Df Sum of Sq      F  Pr(>F)  
1     53 52.045                              
2     52 48.704  1     3.341 3.5673 0.06451 .

It seems like this approach would yield insight into whether or not the two
slope terms (InsulBefore:Gas and InsulAfter:Gas) were different. However, is
there a formal test for this sort of question, and can it be generalized to
differences between more than 2 slope terms?



Dylan Beaudette
Soil Resource Laboratory
University of California at Davis

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Wed 05 Mar 2008 - 23:53:30 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 06 Mar 2008 - 00:30:19 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive