I've conducted a multiple linear regression with interaction in RStudio. In my data, I want to see how CL varies with depth and how/if CL (numerical) varies with depth (numerical) depending on the side the sample has been taken (medial or lateral/categorical).

I have used the code as follows:

my_data <- read.csv(file.choose())
Side <- factor(c("MED", "LAT"))
mlr <- lm(CL_002 ~ Depth * Side, data = my_data)

So you can see I have MED and LAT as variables in my data, under the category Side.

This gives me this result:

lm(formula = CL_002 ~ Depth * Side, data = my_data)

    Min      1Q  Median      3Q     Max 
-9.8106 -1.7643 -0.3233  1.4473 19.5799 

                Estimate Std. Error t value Pr(>|t|)    
(Intercept)    2.531e+01  7.281e-02 347.586   <2e-16 ***
Depth          5.763e-04  4.293e-05  13.424   <2e-16 ***
SideMED        2.133e-01  8.734e-02   2.442   0.0146 *  
Depth:SideMED -6.001e-04  4.962e-05 -12.096   <2e-16 ***
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 2.545 on 14732 degrees of freedom
Multiple R-squared:  0.02404,   Adjusted R-squared:  0.02384 
F-statistic: 120.9 on 3 and 14732 DF,  p-value: < 2.2e-16

I may be misinterpreting my results here, but why do I only get the results for the SideMED in terms of depth? So as I understand it, this shows that CL_002 changes significantly (p < 0.001) with depth:

Depth          5.763e-04  4.293e-05  13.424   <2e-16 ***

CL_002 is significantly different (p < 0.05) between each side

 SideMED        2.133e-01  8.734e-02   2.442   0.0146 * 

But does this mean that CL_002 varies significantly with depth and in different ways depending on the side? Or does this mean something else? As the summary only includes "SideMED" and does not mention the LAT side, I am confused.

Depth:SideMED -6.001e-04  4.962e-05 -12.096   <2e-16 ***

How do I get the estimates for the lateral side, as I appear to only have them for the medial?

Is this correct, or should I be using a different kind of regression as I have categorical data too?


Example data:

ID Side Depth CL_002
67.00 LAT 0.00 25.28
67.00 LAT 25.00 27.24
67.00 LAT 50.00 27.84
67.00 LAT 75.00 28.08
67.00 LAT 100.00 28.49
67.00 MED 0.00 21.48
67.00 MED 25.00 21.85
67.00 MED 50.00 21.85
67.00 MED 75.00 21.54
67.00 MED 100.00 22.21
68.00 LAT 0.00 22.83
68.00 LAT 25.00 23.46
68.00 LAT 50.00 24.21
68.00 LAT 75.00 24.97
68.00 LAT 100.00 27.53
68.00 MED 0.00 34.39
68.00 MED 25.00 27.92
68.00 MED 50.00 27.39
68.00 MED 75.00 26.77
68.00 MED 100.00 26.55

1 Answer 1


These outputs are by default expressed versus a reference category (in this case: LAT). "Depth" is, I guess, processed as a continuous rather than a categorical variable. The "SideMed" line in the output expresses the general difference for the MED (versus LAT) category. The interaction ("Depth:SideMED"), finally, expresses the difference in slope between Depth and CL_002 for the MED category. In other words, to predict values for a specific combination of Depth and MED/LAT, for the LAT category, this is simply the global intercept + (coefficient Depth)*Depth. For the MED category, you have to additionally add the (interaction coefficient)*Depth PLUS the SideMED coefficient.

If you're looking for a more "traditional" table with your factors, you can use e.g. the Anova function of the Car package (car::Anova(mlr, type = 3)).

Incidentally, if you assume ID to be a relevant source of variance (i.e., repeated measures design) you might want to consider taking up ID as a random effect in a linear mixed model.

  • 1
    $\begingroup$ Thank you for your answer @KrisBae and for so clearly explaining my results for me! I have looked into the Car package, but unfortunately even when I turn Depth into a categorical factor I get this error: Error in `contrasts<-`(`*tmp*`, value = contrasts.arg[[nn]]) : contrasts apply only to factors . I believe this is because the depth varies across the different patients, i.e. some only go to 1025, some go to 3600, so I am not sure if this will work $\endgroup$
    – sdavies
    Sep 7, 2021 at 10:48
  • $\begingroup$ Additionally, just to confirm I understand this. In this instance, global intercept + (coefficient Depth)*Depth would be = (2.531e+01) + 5.763e-04 for the LAT, and for MED this would be = (2.531e+01) + 5.763e-04 + (-6.001e-04) + (2.133e-01)? $\endgroup$
    – sdavies
    Sep 7, 2021 at 10:57
  • $\begingroup$ Correct. The broom (broom.mixed) package allows you to automatically compute the predictions for each line in your dataframe with the "augment" function (mlr_augmented <- broom.mixed::augment(mlr).) This way you can verify your calculations. $\endgroup$
    – KrisBae
    Sep 7, 2021 at 18:06
  • $\begingroup$ Not entirely sure regarding the anova error. You can, however, perform an F test comparing a model with and without, e.g. the interaction term by simply anova(mlr.without_interaction, mlr.with_interaction), presuming mlr.without_interaction<- lm(CL_002 ~ Depth + Side, data = my_data) and mlr.with_interaction<- lm(CL_002 ~ Depth * Side, data = my_data) $\endgroup$
    – KrisBae
    Sep 7, 2021 at 18:17
  • $\begingroup$ Thank you for explaining this for me! Really appreciated $\endgroup$
    – sdavies
    Sep 8, 2021 at 11:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.