Skip to main content
Statistics LibreTexts

9.5: Using Technology - Unequal Slopes Model

  • Page ID
    33170
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

    \( \newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\)

    ( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\)

    \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

    \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\)

    \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)

    \( \newcommand{\Span}{\mathrm{span}}\)

    \( \newcommand{\id}{\mathrm{id}}\)

    \( \newcommand{\Span}{\mathrm{span}}\)

    \( \newcommand{\kernel}{\mathrm{null}\,}\)

    \( \newcommand{\range}{\mathrm{range}\,}\)

    \( \newcommand{\RealPart}{\mathrm{Re}}\)

    \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

    \( \newcommand{\Argument}{\mathrm{Arg}}\)

    \( \newcommand{\norm}[1]{\| #1 \|}\)

    \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)

    \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    \( \newcommand{\vectorA}[1]{\vec{#1}}      % arrow\)

    \( \newcommand{\vectorAt}[1]{\vec{\text{#1}}}      % arrow\)

    \( \newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vectorC}[1]{\textbf{#1}} \)

    \( \newcommand{\vectorD}[1]{\overrightarrow{#1}} \)

    \( \newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}} \)

    \( \newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}} \)

    \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

    \(\newcommand{\avec}{\mathbf a}\) \(\newcommand{\bvec}{\mathbf b}\) \(\newcommand{\cvec}{\mathbf c}\) \(\newcommand{\dvec}{\mathbf d}\) \(\newcommand{\dtil}{\widetilde{\mathbf d}}\) \(\newcommand{\evec}{\mathbf e}\) \(\newcommand{\fvec}{\mathbf f}\) \(\newcommand{\nvec}{\mathbf n}\) \(\newcommand{\pvec}{\mathbf p}\) \(\newcommand{\qvec}{\mathbf q}\) \(\newcommand{\svec}{\mathbf s}\) \(\newcommand{\tvec}{\mathbf t}\) \(\newcommand{\uvec}{\mathbf u}\) \(\newcommand{\vvec}{\mathbf v}\) \(\newcommand{\wvec}{\mathbf w}\) \(\newcommand{\xvec}{\mathbf x}\) \(\newcommand{\yvec}{\mathbf y}\) \(\newcommand{\zvec}{\mathbf z}\) \(\newcommand{\rvec}{\mathbf r}\) \(\newcommand{\mvec}{\mathbf m}\) \(\newcommand{\zerovec}{\mathbf 0}\) \(\newcommand{\onevec}{\mathbf 1}\) \(\newcommand{\real}{\mathbb R}\) \(\newcommand{\twovec}[2]{\left[\begin{array}{r}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\ctwovec}[2]{\left[\begin{array}{c}#1 \\ #2 \end{array}\right]}\) \(\newcommand{\threevec}[3]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\cthreevec}[3]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \end{array}\right]}\) \(\newcommand{\fourvec}[4]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\cfourvec}[4]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}\) \(\newcommand{\fivevec}[5]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\cfivevec}[5]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}\) \(\newcommand{\mattwo}[4]{\left[\begin{array}{rr}#1 \amp #2 \\ #3 \amp #4 \\ \end{array}\right]}\) \(\newcommand{\laspan}[1]{\text{Span}\{#1\}}\) \(\newcommand{\bcal}{\cal B}\) \(\newcommand{\ccal}{\cal C}\) \(\newcommand{\scal}{\cal S}\) \(\newcommand{\wcal}{\cal W}\) \(\newcommand{\ecal}{\cal E}\) \(\newcommand{\coords}[2]{\left\{#1\right\}_{#2}}\) \(\newcommand{\gray}[1]{\color{gray}{#1}}\) \(\newcommand{\lgray}[1]{\color{lightgray}{#1}}\) \(\newcommand{\rank}{\operatorname{rank}}\) \(\newcommand{\row}{\text{Row}}\) \(\newcommand{\col}{\text{Col}}\) \(\renewcommand{\row}{\text{Row}}\) \(\newcommand{\nul}{\text{Nul}}\) \(\newcommand{\var}{\text{Var}}\) \(\newcommand{\corr}{\text{corr}}\) \(\newcommand{\len}[1]{\left|#1\right|}\) \(\newcommand{\bbar}{\overline{\bvec}}\) \(\newcommand{\bhat}{\widehat{\bvec}}\) \(\newcommand{\bperp}{\bvec^\perp}\) \(\newcommand{\xhat}{\widehat{\xvec}}\) \(\newcommand{\vhat}{\widehat{\vvec}}\) \(\newcommand{\uhat}{\widehat{\uvec}}\) \(\newcommand{\what}{\widehat{\wvec}}\) \(\newcommand{\Sighat}{\widehat{\Sigma}}\) \(\newcommand{\lt}{<}\) \(\newcommand{\gt}{>}\) \(\newcommand{\amp}{&}\) \(\definecolor{fillinmathshade}{gray}{0.9}\)
    SAS Example

    If the data collected in the example study were instead as follows:

    Females Males
    Salary Years Salary Years
    80 5 42 1
    50 3 112 4
    30 2 92 3
    20 1 62 2
    60 4 142 5

    We would see in Step 2 of the ANCOVA that we do have a significant treatment × covariate interaction.

    Steps for ANCOVA

    Using this SAS program with the new data shown below.

    data unequal_slopes;
    input gender $ salary years;
    datalines;
    m 42 1
    m 112 4
    m 92 3
    m 62 2
    m 142 5
    f 80 5
    f 50 3
    f 30 2
    f 20 1
    f 60 4
    ;
    proc mixed data=unequal_slopes;
    class gender;
    model salary=gender years gender*years;
    title 'Covariance Test for Equal Slopes';
    /*Note that we found a significant years*gender interaction*/
    /*so we add the lsmeans for comparisons*/
    /*With 2 treatments levels we omitted the Tukey adjustment*/
    lsmeans gender/pdiff at years=1;
    lsmeans gender/pdiff at years=3;
    lsmeans gender/pdiff at years=5;
    run;
    

    We get the following output:

    Type 3 Test of Fixed Effects
    Effect Num DF De DF F Value Pr > F
    years 1 6 800.00 F">< .0001
    gender 1 6 6.55 F">0.0430
    years*gender 1 6 50.00 F">0.0004
    Generating Covariate Regression Slopes and Intercepts
    data unequal_slopes;
    input gender $ salary years;
    datalines;
    m 42 1
    m 112 4
    m 92 3
    m 62 2
    m 142 5
    f 80 5
    f 50 3
    f 30 2
    f 20 1
    f 60 4
    ;
    proc mixed data=unequal_slopes;
    class gender;
    model salary=gender years gender*years / noint solution;
    ods select SolutionF;
    title 'Reparmeterized Model';
    run;
    

    Output:

    Solution for Fixed Effects
    Effect gender Estimate Standard Error DF t Value Pr > |t|
    gender f 3.0000 3.3166 6 0.90 |t|">0.4006
    gender m 15.0000 3.3166 6 4.52 |t|">0.0040
    years   25.0000 1.0000 6 25.00 |t|"><.0001
    years*gender f -10.0000 1.4142 6 -7.07 |t|">0.0004
    years*gender m 0 . . . |t|">.

    Here the intercepts are the Estimates for effects labeled "gender" and the slopes are the Estimates for the effect labeled "years*gender". Thus, the regression equations for this unequal slopes model are: \[\text{Females} \quad \hat{y} = 3.0 + 15(\text{Years})\] \[\text{Males} \quad \hat{y} = 15 + 25(\text{Years})\]

    The slopes of the regression lines differ significantly and are not parallel:

    Plot of salary in thousands vs years after graduation, separated by gender and with regression line equations indicated.
    Figure \(\PageIndex{a1}\): Non-parallel regression lines of salary vs years since graduation

    And here is the output:

    Differences of Least Squares Means
    Effect gender _gender years Estimate Standard Error DF t Value Pr > |t|
    gender f m 1.00 -22.000 3.4641 6 -6.35 |t|">0.0007
    gender f m 3.00 -42.000 2.0000 6 -21.00 |t|">< .0001
    gender f m 5.00 -62.000 3.4641 6 -17.90 |t|">< .0001

    In this case, we see a significant difference at each level of the covariate specified in the lsmeans statement. The magnitude of the difference between males and females differs (giving rise to the interaction significance). In more realistic situations, a significant treatment × covariate interaction often results in significant treatment level differences at certain points along the covariate axis.

    Minitab Example
    Steps in Minitab

    When we re-run the program with the new dataset Salary-new Data, we find a significant interaction between gender and years.

    To do this, open the Minitab dataset Salary-new Data.

    Go to Stat > ANOVA > General Linear model > Fit General Linear Model and follow the same sequence of steps as in the previous section. In Step 2, Minitab will display the following output.

    Analysis of Variance

    Source DF Adj SS Adj MS F-Value P-Value
    years 1 8000.0 8000.0 800.00 0.000
    gender 1 65.5 65.45 6.55 0.043
    years*gender 1 500.0 500.0 50.00 0.000
    Error 6 60.0 10.00    
    Total 9 12970.0      

    It is clear the interaction term is significant and should not be removed. This suggests the slopes are not equal. Thus, the magnitude of the difference between males and females differs (giving rise to the interaction significance).

    R Example

    Steps:

    • Fit an unequal slopes model.
    • Plot the regression lines.
    Steps in R

    1. Fit an unequal slopes model by using the following commands:

    setwd("~/path-to-folder/")
    unequal_slopes_data <- read.table("unequal_slopes.txt",header=T)
    attach(unequal_slopes_data)
    unequal_slopes_model<-lm(salary ~ gender + years + gender:years,unequal_slopes_data)
    anova(unequal_slopes_model)
    #Analysis of Variance Table
    #Response: salary
    #             Df Sum Sq Mean Sq F value     Pr(>F)
    #gender        1   4410    4410     441  7.596e-07 ***
    #years         1   8000    8000     800  1.293e-07 ***
    #gender:years  1    500     500      50  0.0004009 ***
    #Residuals     6     60      10
    #---
    #Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
    

    With a \(p\)-value of 0.0004009 in the interaction term (gender*years), we can conclude that the slopes are unequal. To estimate the two regression lines, we need the following output:

    #summary(unequal_slopes_model)$coefficients
    #             Estimate  Std. Error    t value      Pr(>|t|)
    #(Intercept)         3    3.316625   0.904534  4.005719e-01
    #genderm            12    4.690416   2.558409  4.300074e-02
    #years              15    1.000000  15.000000  5.530240e-06
    #genderm:years      10    1.414214  7.071068   4.008775e-04
    

    Here the intercept for females is the estimate for intercept and the intercept for males is the summation of the estimates intercept+genderm (note the letter m after gender). The slope for females is the estimate for years and the slope for males is the summation of the estimates years+genderm: years (note the letter m after gender). Thus, the regression equations for the unequal slopes model are: \(y=3 + 15x\) for females and \(y = 15+25x\) for males.

    2. Plot the regression lines by using the following commands:

    males_regression <- lm(salary~years,data=subset(unequal_slopes_data,gender=="m"))
    females_regression <- lm(salary~years,data=subset(unequal_slopes_data,gender=="f"))
    plot(years,salary, xlab="Years after graduation", ylab="Salary(Thousands)",pch=23, col=ifelse(gender=="m","red","blue"), lwd=2)
    abline(males_regression)
    abline(females_regression)
    text(locator(1),"y=25x+15",col="red")
    text(locator(1),"y=15x+3",col="blue")
    detach(unequal_slopes_data)
    
    Plot of salary in thousands vs years after graduation, separated by gender, with regression lines.
    Figure \(\PageIndex{c1}\): Regression line plot in R

    This page titled 9.5: Using Technology - Unequal Slopes Model is shared under a CC BY-NC 4.0 license and was authored, remixed, and/or curated by Penn State's Department of Statistics via source content that was edited to the style and standards of the LibreTexts platform.