I'm running a multilevel model using lmerTest in which employees are nested in teams and departments. I'm taking a model comparison approach, so I'm building the model with just the random effects. Here are the results when I use the two random effects (team and department membership) to predict intense exercise:
library(lme4)
summary(m0_ev_io <- lmer(exer_vig ~ 1 + (1 | team_num) + (1 | dept_client), data = clean_data_0))
Linear mixed model fit by REML. t-tests use Satterthwaite's method ['lmerModLmerTest']
Formula: exer_vig ~ 1 + (1 | team_num) + (1 | dept_client)
Data: clean_data_0
REML criterion at convergence: 527.5
Scaled residuals:
Min 1Q Median 3Q Max
-1.6783 -0.6071 -0.2324 0.4233 2.1587
Random effects:
Groups Name Variance Std.Dev.
team_num (Intercept) 0.16687 0.4085
dept_client (Intercept) 0.03047 0.1746
Residual 1.14821 1.0715
Number of obs: 169, groups: team_num, 58; dept_client, 33
Fixed effects:
Estimate Std. Error df t value Pr(>|t|)
(Intercept) 2.6743 0.1081 14.6284 24.74 2.4e-13 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
This model--and all subsequent ones--run well with no errors. However, when I run the same model using the same data on lite exercise, I get a singularity warning and suddenly department membership has no variance:
summary(m0_el_io <- lmer(exer_lite ~ 1 + (1 | team_num) + (1 | dept_client), data = clean_data_0))
boundary (singular) fit: see ?isSingular
Linear mixed model fit by REML. t-tests use Satterthwaite's method [
lmerModLmerTest]
Formula: exer_lite ~ 1 + (1 | team_num) + (1 | dept_client)
Data: clean_data_0
REML criterion at convergence: 542
Scaled residuals:
Min 1Q Median 3Q Max
-1.6403 -0.5925 -0.3208 0.4440 2.0776
Random effects:
Groups Name Variance Std.Dev.
team_num (Intercept) 0.1471 0.3835
dept_client (Intercept) 0.0000 0.0000
Residual 1.3027 1.1414
Number of obs: 169, groups: team_num, 58; dept_client, 33
Fixed effects:
Estimate Std. Error df t value Pr(>|t|)
(Intercept) 2.7160 0.1037 42.5453 26.2 <2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
convergence code: 0
boundary (singular) fit: see ?isSingular
Except for the dependent variable, the data are the same, so I'm very confused why this would be the case. I'm confident it's not due to overfitting (like in this thread (How to cope with a singular fit in a linear mixed model (lme4)?)) because, even when the vigorous exercise model contains many more variables, it never gives a singular warning.
Do you have any ideas on why this is happening and how I can fix this issue without removing department membership? I've tried recommendations from other sites, including turning REML = FALSE and changing the optimizer [control = lmerControl(optimizer ='optimx', optCtrl=list(method='L-BFGS-B')], but nothing has worked.
Thank you!
EDIT: Here is a sample of the data. Note: team_num and dept_client are factors.
library(tidyverse)
clean_data_0 <- tibble(
exer_lite = c(5, 4, 4, 5, 2, 4, 3, 1, 2, 2, 5,3, 4, 5, 2, 2, 2, 5, 5, 2, 3, 3, 1, 2, 5),
exer_vig = c(4, 2, 4, 1, 2, 2, 3, 1, 2, 2, 5, 3, 3, 5, 2, 2, 3, 5, 5, 2, 3, 2, 1, 3, 5),
dept_client = factor(c(17, 17, 45, 45, 80, 100, 90, 14, 2, 80, 100, 90, 121, 121, 121, 2, 90, 90, 90, 2, 100, 14, 14, 76, 76)),
team_num = factor(c(509, 509, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6, 6, 13, 13, 14, 14)),
id = c(1:25))