I am trying to estimate a LMEM model with three fixed effects (two regressors and their interaction) and one random effect (a by-subject random intercept). Both regressors are dichotomous.

I'm using R's lme4 command, and I'm just having some problems understanding the residual degrees of freedom.

The model is below. Per my training, I estimated p-values using a Type III Wald F test with Kenward-Rogers degrees of freedom.

conflict1 <- lmer(neurosynth_conflict ~ contrast*Teen_vs_Adult + (1 | participant_id),dCon)

car::Anova(conflict1, type = 3, test = 'F')

The model converges just fine and the output mostly aligns with my expectations, but I'm just really thrown by the residual degrees of freedom. I get that residual degrees of freedom will almost never be integers under REML, but I don't understand why the values are so different across my regressors? Can anyone help me wrap my head around this?

                             F Df Df.res    Pr(>F)    
(Intercept)            20.0400  1 377.20 1.006e-05 ***
contrast               10.5006  1 496.74  0.001273 ** 
Teen_vs_Adult           2.7166  1 388.47  0.100118    
contrast:Teen_vs_Adult  5.9632  1 499.22  0.014953 *  


2 Answers 2


These degrees of freedom aren't importantly different: they're all large, and that's what matters.

More generally, the residual df will depend a lot on whether the information for a particular comparison comes from comparisons within participant or between participants. Very roughly, the residual df is a sort of $n-p$ number where $n$ is the number of observations and $p$ is the number of parameters you've estimated. If you have a variable that is constant within individuals, the relevant $n$ is going to be the number of individuals; if the variable varies within individuals as well, the relevant $n$ will be larger and might be the total number of observations.

I've got an example here looking at microbiome transplants in mice where one issue was whether the residual df was roughly the number of microbiome donors (8) or roughly the number of mice (206), so the between-donor comparisons have much smaller residual df than the between-mouse comparisons.


Perhaps it's due to the contrasts used. I had the same issue (type3 and F test) and I had normal df.res once I ran this code before running the models: options(contrasts=c("contr.sum","contr.poly"))

Found here:Conflicting results of Type III sum of squares in ANOVA in SAS and R


Your Answer

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

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