We use cookies and other tracking technologies to improve your browsing experience on our website, to show you personalized content and targeted ads, to analyze our website traffic, and to understand where our visitors are coming from.
Hypothesis testing in mixed linear models with a factorial design
dat <-expand_grid(time =factor(1:3), group =factor(1:2), ID =1:5) |>mutate(hh =paste('time', time, 'group', group, sep ='_'))X <-model.matrix(~ hh +factor(ID), data = dat)dat <- dat |>mutate(y = X %*%rnorm(10) +rnorm(30))fm_1 <-lmer(y ~ time * group + (1| ID), data = dat)fm_2 <-lmer(y ~ hh -1+ (1| ID), data = dat)fm_1
Linear mixed model fit by REML ['lmerMod']
Formula: y ~ time * group + (1 | ID)
Data: dat
REML criterion at convergence: 92.9467
Random effects:
Groups Name Std.Dev.
ID (Intercept) 0.9389
Residual 1.2076
Number of obs: 30, groups: ID, 5
Fixed Effects:
(Intercept) time2 time3 group2 time2:group2
-0.08427 2.12602 -0.21546 -0.15532 -3.74877
time3:group2
-0.65262
fm_2
Linear mixed model fit by REML ['lmerMod']
Formula: y ~ hh - 1 + (1 | ID)
Data: dat
REML criterion at convergence: 92.9467
Random effects:
Groups Name Std.Dev.
ID (Intercept) 0.9389
Residual 1.2076
Number of obs: 30, groups: ID, 5
Fixed Effects:
hhtime_1_group_1 hhtime_1_group_2 hhtime_2_group_1 hhtime_2_group_2
-0.08427 -0.23959 2.04174 -1.86234
hhtime_3_group_1 hhtime_3_group_2
-0.29973 -1.10767
AIC(fm_1)
[1] 108.9467
AIC(fm_2)
[1] 108.9467
summary(fm_1)
Linear mixed model fit by REML ['lmerMod']
Formula: y ~ time * group + (1 | ID)
Data: dat
REML criterion at convergence: 92.9
Scaled residuals:
Min 1Q Median 3Q Max
-1.7375 -0.5930 0.2371 0.6309 1.1804
Random effects:
Groups Name Variance Std.Dev.
ID (Intercept) 0.8816 0.9389
Residual 1.4582 1.2076
Number of obs: 30, groups: ID, 5
Fixed effects:
Estimate Std. Error t value
(Intercept) -0.08427 0.68408 -0.123
time2 2.12602 0.76373 2.784
time3 -0.21546 0.76373 -0.282
group2 -0.15532 0.76373 -0.203
time2:group2 -3.74877 1.08007 -3.471
time3:group2 -0.65262 1.08007 -0.604
Correlation of Fixed Effects:
(Intr) time2 time3 group2 tm2:g2
time2 -0.558
time3 -0.558 0.500
group2 -0.558 0.500 0.500
time2:grop2 0.395 -0.707 -0.354 -0.707
time3:grop2 0.395 -0.354 -0.707 -0.707 0.500
summary(fm_2)
Linear mixed model fit by REML ['lmerMod']
Formula: y ~ hh - 1 + (1 | ID)
Data: dat
REML criterion at convergence: 92.9
Scaled residuals:
Min 1Q Median 3Q Max
-1.7375 -0.5930 0.2371 0.6309 1.1804
Random effects:
Groups Name Variance Std.Dev.
ID (Intercept) 0.8816 0.9389
Residual 1.4582 1.2076
Number of obs: 30, groups: ID, 5
Fixed effects:
Estimate Std. Error t value
hhtime_1_group_1 -0.08427 0.68408 -0.123
hhtime_1_group_2 -0.23959 0.68408 -0.350
hhtime_2_group_1 2.04174 0.68408 2.985
hhtime_2_group_2 -1.86234 0.68408 -2.722
hhtime_3_group_1 -0.29973 0.68408 -0.438
hhtime_3_group_2 -1.10767 0.68408 -1.619
Correlation of Fixed Effects:
h_1__1 h_1__2 h_2__1 h_2__2 h_3__1
hhtm_1_gr_2 0.377
hhtm_2_gr_1 0.377 0.377
hhtm_2_gr_2 0.377 0.377 0.377
hhtm_3_gr_1 0.377 0.377 0.377 0.377
hhtm_3_gr_2 0.377 0.377 0.377 0.377 0.377