Comparing the slopes for two independent samples

On this webpage, we show how to test whether the slopes for two independent populations are equal, i.e. we test the following null and alternative hypotheses:

H0:  β1 = β2 i.e. β1 – β2 = 0

H1:  β1 ≠ β2 i.e. β1 – β2 ≠ 0

The test statistic is

image3677

If the null hypothesis is true then

image3678

where
image3679

If the two error variances are equal, then as for the test for the differences in the means, we can pool the estimates of the error variances, weighing each by their degrees of freedom, and so

image3680

Now
image5066

Since we can replace the numerators of each by the pooled value s_{Res}^2, we have

image3684

Note that while the null hypothesis that β = 0 is equivalent to ρ = 0, the null hypothesis that  β1 = β2  is not equivalent to ρ1 = ρ2.

Example 1: We have two samples, each comparing life expectancy vs. smoking. The first sample is for males and the second for females. We want to determine whether there is any significant difference in the slopes for these two populations. We assume that the two samples have the values in Figure 1 (for men the data is the same as that in Example 1 of Regression Analysis):

Data comparing slopes regression

Figure 1 – Data for Example 1

As can be seen from the scatter diagrams in Figure 1, it appears that the slope for women is less steep than for that for men. In fact, as can be seen from Figure 2, the slope of the regression line for men is -0.6282 and the slope for women is -0.4679, but is this difference significant?

As can be seen from the calculations in Figure 2, using both pooled and unpooled values for sRes, the null hypothesis, H0: the slopes are equal, cannot be rejected. And so we cannot conclude that there is any significant difference between the life expectancy of males and females for any incremental amount of smoking.

t-test slopes comparison

 

Figure 2 – t-test to compare slopes of regression lines

Real Statistics Function: The following array function is provided by the Real Statistics Resource Pack. Here Rx1, Ry1 are ranges containing the X and Y values for one sample and Rx2, Ry2 are the ranges containing the X and Y values for a second sample.

SlopesTest(Rx1, Ry1, Rx2, Ry2, b, lab): outputs the standard error of the difference in slopes sb1–b2, t, df and p-value for the test described above for comparing the slopes of the regression lines for the two samples.

If b = True (the default) then the pooled standard error sb1–b2 is used (as in cell T10 of Figure 2); otherwise the non-pooled standard error is used (as in cell N10 of Figure 2).

If lab = True then the output is a 4 × 2 range where the first column contains labels and the second column contains the values described above and if lab = False (the default) only the data is outputted (in the form of a 4 × 1 range).

The SlopesTest function only produces the correct results if there are no missing data elements in Rx1, Ry1, Rx2, Ry2.

Observation: For Example 1, the formula

=SlopesTest(A5:A19,B5:B19,D5:D20,E5:E20,FALSE,TRUE)

generates the output in range M30:N33 of Figure 3, while the formula

=SlopesTest(A5:A19,B5:B19,D5:D20,E5:E20)

generates the output in range O30:O33.

Comparing slopes Excel formulas

Figure 3 – Comparing slopes using SlopesTest function

188 thoughts on “Comparing the slopes for two independent samples”

  1. Thank you for your work Charles. I have applied this data to the following values

    X. Y 1 X Y2
    1 38 1 5717089
    2 1345 2 5540247
    3 2428 3 5591382
    4 2751 4 5381358
    5 2510 5 5761455

    The slopes for these two independent samples are very different, but the p-value I keep getting is 0.89, thought the slopes for both are drastically different, 635 and -7015 respectively. Any real statistics test you recommend to address this?
    Th

    Reply
  2. Hello,

    I installed the package successfully, but when I tried to compute the function =SlopesTest(A5:A19,B5:B19,D5:D20,E5:E20), it only gave me a single value as an output, not a whole output range, as depicted above in figure 3. Do you have an idea of what went wrong?

    Best,
    Jana

    Reply
  3. Hello, I would like to ask a question about the application.
    I want to use this method to describe the difference between two calibration curves.
    These two calibration curves use the same concentration and instrument, but use different substrates.

    The results of my attempts so far show that none of the calibration lines are significantly different, even if the slopes differ by more than a factor of two. (N of calibration curve is 5)

    Reply
  4. Hi Charles,
    Thanks for all this great information. I just performed this test to determine the differences between slopes in two groups. Now I’m trying to figure out how best to report this in the methods. Is there a formula or a best practice on how to write this up in the results.
    Thank you,
    Manda

    Reply
  5. Hi, Charles.
    I want to compare slopes between different levels of a 2 x 2 factorial design. One of the factor is Exersice (YES/NO) and the other factor is Diet (1/2).
    For each combination of factor’s levels, I have measured Height (Y, dependent variable); X (age). I want to know if the slopes of the linear regression aplied to Y vs X, depend on the Exersice factor, or on the Diet factor, or may be on the interaction Exercise*Diet.
    Is there a method for testing that?
    Thank!
    Leonardo

    Reply
  6. Dear Charles,

    I was wondering how you would describe this test in your methods. I can see that you are using two unequal samples, therefore, I was wondering whether you are using the Welch t-test?

    Best,

    Amanda

    Reply
  7. Dear Charles,
    I have a question that seems related to the test of the slopes of two independent populations.

    I have two independent time-varying signals. Each of these signals has been measured multiple times. The time-varying signal is not linear with time, but slowly changing with time. I want to test the slopes of these two time-varying signals at different times. The hypothesis is the slope of one signal is always greater than the other.

    My plan is to use something similar to your SlopeTest function, but limit the range to a certain time window, for example, 100 data points over time. Then apply SlopeTest at all different time positions to get test results over time.

    I am wondering if this is logical? or are there any better way of doing this?

    Many thanks,

    Reply
  8. Hi Charles,
    Comparing slopes of two independent samples interests me very much, however, I need to compare slopes of three ind. samples as well. Can I add the 3rd sample group and its statistical parameters like below?
    ‘= (………..+(n3-2)sy.x32)/(…..+n3-(4+2))
    ‘= sRes*SQRT(1/(sx12(n1-1))+……+1/(sx32(n3-1)))
    ‘= (b1-b2-b3)/(sb1-b2-b3)
    ‘= n1+n2+n3-(4+2)
    etc..
    If is not as the way as I thought as above. Would you kindly provide how can we compare slopes of three ind. samples?
    Thank you and appreciate very much!
    Thuy

    Reply
  9. Installed and trying to run SlopesTest. No missing data or anything, but the output is just the single term “std err”. How come I’m not seeing the rest of the output?

    Reply
  10. Hi Charles.

    Thanks for the article. I’m completely green with statistics. Just trying to figure out a test that works for a school paper. I wonder if it makes sense to perform an ANOVA test on slopes to see if there is a difference in the mean of slopes between groups.

    The use case is this. I’m trying to compare the slopes of time series of company share prices between groups. Each group has a different characteristic and about 5 companies in them. The statistic is meant to tell if the distinguishing charasteric influenced the steepness of the movement in shareprices between groups, by determining If there is a difference in the mean of the slopes.

    I’m however worried if the slopes are directly comparable in such a manner. The size each company’s shares seems to influence how big the slope’s number is (A company with an average share price of 1000 CU gets of slope of about -200 while one with 10 CU get a slope of about -3). I was wondering if there was a way to treat the slopes to make them more comparable before running them through ANOVA or T-test. I had thought of expressing the slope as a percentage of the intercept. I wondered though if that made sense to an actual statistician.

    Thanks again, Mr Charles.

    Reply
  11. Dear Charles,
    Thank you very much for your stat pack.
    I am running this slope test but does not work for me. I installed satisfactory the pack and can open it on the add-on. Then, I clicked on regression tab but I do not see the slope test. Finally, I used =SlopesTest(A5:A19,B5:B19,D5:D20,E5:E20) as example in my data set changing data ranges accordingly. Is there any other way to perform this test using the pack?
    Best regards,
    Ramiro

    Reply
  12. Hi, Mr.Charles,

    I cannot understand about the degree of freedom.
    Why are you using -4??
    In this case, I think Men=15-1, Women=16-1, so, “df”is n1-1+n2-1 (= n1+n2-2)?

    Reply
    • This just how the mathematics turns out. The intuitive answer is that there are 4 variables: men and women for sample 1 and men and women for sample 2.
      Charles

      Reply
  13. Hello. I am looking to use a test like this to assess the probability of similarity between two groups of bivatiate data. I tried this slope test in Excel and got it to work. If I am reporting the results, how should I refer to the test? I think I can figure out how to report the results, but I’m not sure what type of test I should say that I used. Also, are there any additional tests that might be more appropriate? I am comparing the density and porosity of stone to assess the probability that the relationship of density to porosity is the same between two groups. Thanks!

    Reply
    • Hi Mike,
      I got this test from Howell’s textbook (see Bibliography). No fancy name is given. I would call it
      Testing the difference between the slopes from two independent samples.
      I don’t know of other tests that do this.
      Charles

      Reply
  14. Good day, I want to compare stadisticaly diferent calibration curves in order to evaluate the standard stability in diferent day. How can I do this?

    Reply
    • Hello Paola,
      I need to additional context in order to answer your question. What sort of calibration curves are you referring to and what do you mean by standard stability?
      Charles

      Reply
      • Good evening Charles:
        I’m having the same issue as Curran.
        I’ve installed the software as described, it appears in the Excel add-ins and the box is checked. I cannot find it in any of the Excel ribbon tabs, and Ctrl-m just generates a chime sound.
        Any help will be appreciated.
        Regards,
        Bill

        Reply
  15. Thank you for this helpful page. Why have you used the same number of degrees of freedom for the unpooled and pooled methods? Shouldn’t the degrees of freedom for the unpooled case be different?

    Reply
  16. Good morning Charles,

    Thanks for your examples. When running the slopes test, I’m getting a significant difference between the groups’ respective slopes. However, when running the groups’ probability and z-scores using an on-line calculator, I’m getting a significant difference. Should this be happening or is this something that tends to occur? Thanks in advance.

    Richard.

    Reply
  17. Using unpooled values our hypothesis would be

    H0 : β1 − β2 = 0
    and alternative is
    Ha : β1 − β2 > 0

    When you receive “sig = no” in figure 2, where you calculate the conlusion of the t.test for unpooled values, do you mean that slope 1 is not sig. bigger than slope 2 ?

    Reply
    • Manuela,
      The alternative hypothesis is Ha : β1 − β2 not equal to 0. If sig = no, then you can conclude that there is no evidence that slope 1 is significantly different from slope 2.
      Charles

      Reply
  18. Hi Charles,
    Thanks for this great pack!
    I have the most current version of realstats loaded but somehow the slopestest function isn’t returning what’s referenced in Figure 3. I am just getting “st dev” or a single number e.g. 0.00298. Am I just missing something?

    Reply
  19. A child with no gifted and talented students in his or her school, would be predicted to have a reading test score of what?

    0

    .049

    50.7

    58.6

    Reply

Leave a Comment