0
$\begingroup$

From my understanding, the addition of a -1 in the fixed effects of a lmer() model would avoid comparisons of factor levels to a baseline (e.g. the (intercept) in the model summary). However, adding -1 to the fixed effects of the lmer() changes the df of the factor levels and ANOVA results (see code below). Does anyone know why this occurs? When should you code models with -1?

Prep

library(lmerTest)
mtcars$am<-as.factor(mtcars$am)

Traditional model

M1<-lmer(mpg~am*hp+(1|carb),data=mtcars)

summary(M1)
            Estimate Std. Error       df t value
(Intercept) 25.66172    2.28955 21.40909  11.208
am1          5.83594    2.61030 26.89064   2.236
hp          -0.05230    0.01347 24.93249  -3.882
am1:hp      -0.00412    0.01633 27.96768  -0.252

anova(M1)
       Sum Sq Mean Sq NumDF  DenDF F value    Pr(>F)
am     40.696  40.696     1 26.891  4.9985   0.03387
hp    306.263 306.263     1 17.996 37.6171 8.597e-06
am:hp   0.518   0.518     1 27.968  0.0636   0.80271

No intercept model

M2<-lmer(mpg~-1+am*hp+(1|carb),data=mtcars)

summary(M2)
       Estimate Std. Error       df t value Pr(>|t|)
am0    25.66172    2.28955 21.40909  11.208 2.02e-10
am1    31.49766    1.65927 12.32171  18.983 1.71e-10
hp     -0.05230    0.01347 24.93249  -3.882 0.000673
am1:hp -0.00412    0.01633 27.96768  -0.252 0.802705

anova(M2)
      Sum Sq Mean Sq NumDF  DenDF  F value    Pr(>F)
am    3502.5 1751.26     2 18.422 215.1004 1.692e-13
hp     306.3  306.26     1 17.996  37.6171 8.597e-06
am:hp    0.5    0.52     1 27.968   0.0636    0.8027
$\endgroup$
2
  • $\begingroup$ I think what is happening is that am is "taking" the role of your intercept, the only way to completly remove an intercept from a linear model would be to not have any categorical variables $\endgroup$
    – Bruno
    Commented Aug 6, 2021 at 20:05
  • $\begingroup$ I don't think this has anything to do with lmer/lme4/nlme, or mixed models generally - the same thing is bound to happen with any linear model. $\endgroup$ Commented Aug 7, 2021 at 15:41

2 Answers 2

1
$\begingroup$

This is more a question for CrossValidated, but for what it is worth, the intercept is capturing the grand mean and the remaining factors the differences to the overall mean (as if all those other factors were 0). That's why the am results differ - with the intercept, the am results are about how they are different to the overall mean. Without the intercept, the am results are about how they are different from zero.

Similarly, without the intercept, both levels are included in the regression. That is, for am, two means need to be estimated. Hence df=2.

Just to illustrate this:

Data:
set.seed(42)
df <- data.frame(y=rnorm(9), x = factor(c(rep(0, 3), rep(1,3), rep(2,3))))

df
           y x
1 -1.7813084 0
2 -0.1719174 0
3  1.2146747 0
4  1.8951935 1
5 -0.4304691 1
6 -0.2572694 1
7 -1.7631631 2
8  0.4600974 2
9 -0.6399949 2
Overall means for reference:
df %>% group_by(x) %>% summarise(mn = mean(y))
# A tibble: 3 x 2
  x         mn
* <fct>  <dbl>
1 0     -0.246
2 1      0.402
3 2     -0.648

Notice the different means for the different factor levels.

Let's use the simples method: linear regression.

mod <- lm(y~x, data=df)
mod1 <- lm(y~x-1, data=df)

mod

Coefficients:
(Intercept)           x1           x2  
    -0.2462       0.6487      -0.4015  

mod1

Coefficients:
     x0       x1       x2  
-0.2462   0.4025  -0.6477  

Notice how the latter model (without the intercept) reflects the means, whereas the former is reflective of the differences to the mean with x0.

And now you also get similar differences for anova:

anova(mod)
Analysis of Variance Table

Response: y
          Df  Sum Sq Mean Sq F value Pr(>F)
x          2  1.6848 0.84242  0.4895 0.6354
Residuals  6 10.3250 1.72084               

anova(mod1)
Analysis of Variance Table

Response: y
          Df  Sum Sq Mean Sq F value Pr(>F)
x          3  1.9263  0.6421  0.3731 0.7758
Residuals  6 10.3250  1.7208               

And this change in the degrees of freedom also make sense as with mod1 we have to estimate three parameters associated with x, whereas with mod, we only estimate two.

$\endgroup$
2
  • $\begingroup$ Perfect, this helps. Although this should go to CrossValidated (sorry, this was my first post here and I didn't know about the different sites!), one more follow-up: if the intercept is only changing the comparison of factor levels to one another, the difference in ANOVA results are strictly due to the differences in DF, right? If so, why bother with eliminating the intercept when you could compare terms with a post-hoc test? $\endgroup$
    – U. Mena
    Commented Aug 6, 2021 at 22:02
  • $\begingroup$ The main difference comes from the difference in contracts, but I think CrossValidated is a better place to ask. Either way, in my line of work, removing the constant would be highly unusual. I would never do. $\endgroup$ Commented Aug 7, 2021 at 14:07
0
$\begingroup$

Ok there is probably some deep mathematical explanation for this, but practically by taking the Intercept out of your model and keeping a categorical variable it "absorbed" it's effect

The simple way to prove that is that as you can see your Intercept matches your am0, and your am1 of the new model is just Intercept + am1 of the old model, that is why nothing changed, this may be relevant if you want to consider droping am, as the p-values for am's get inflated.

$\endgroup$
3
  • $\begingroup$ Thanks for the quick response, but I'm still not getting it. Yes, the estimate for the 'am' levels are the same but the ANOVA results differ. Also, could you elaborate on "absorbed" effects?? $\endgroup$
    – U. Mena
    Commented Aug 6, 2021 at 20:33
  • $\begingroup$ Look at the hp result, it is the same. everything that has am on it gets distorted by it's absortion of the old intercept effects, but at the end of the day it is still the exact same model. $\endgroup$
    – Bruno
    Commented Aug 6, 2021 at 20:43
  • $\begingroup$ my tip is to move this to cross validated someone there is sure to cleanly explain the math, here is more of an programming related problem site $\endgroup$
    – Bruno
    Commented Aug 6, 2021 at 20:45

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.