Let say I've ran this linear regression:
lm_mtcars <- lm(mpg ~ wt + vs, mtcars)
I can use anova()
to see the amount of variance in the dependent variable accounted for by the two predictors:
anova(lm_mtcars)
Analysis of Variance Table
Response: mpg
Df Sum Sq Mean Sq F value Pr(>F)
wt 1 847.73 847.73 109.7042 2.284e-11 ***
vs 1 54.23 54.23 7.0177 0.01293 *
Residuals 29 224.09 7.73
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Lets say I now add a random intercept for cyl
:
library(lme4)
lmer_mtcars <- lmer(mpg ~ wt + vs + (1 | cyl), mtcars)
summary(lmer_mtcars)
Linear mixed model fit by REML ['lmerMod']
Formula: mpg ~ wt + vs + (1 | cyl)
Data: mtcars
REML criterion at convergence: 148.8
Scaled residuals:
Min 1Q Median 3Q Max
-1.67088 -0.68589 -0.08363 0.48294 2.16959
Random effects:
Groups Name Variance Std.Dev.
cyl (Intercept) 3.624 1.904
Residual 6.784 2.605
Number of obs: 32, groups: cyl, 3
Fixed effects:
Estimate Std. Error t value
(Intercept) 31.4788 2.6007 12.104
wt -3.8054 0.6989 -5.445
vs 1.9500 1.4315 1.362
Correlation of Fixed Effects:
(Intr) wt
wt -0.846
vs -0.272 0.006
The variance accounted for by each fixed effect now drops because the random intercept for cyl
is now accounting for some of the variance in mpg
:
anova(lmer_mtcars)
Analysis of Variance Table
Df Sum Sq Mean Sq F value
wt 1 201.707 201.707 29.7345
vs 1 12.587 12.587 1.8555
But in lmer_mtcars
, how can I tell what proportion of the variance is being accounted for by wt
, vs
and the random intecept for cyl
?