假设我已经运行了这个线性回归:
lm_mtcars <- lm(mpg ~ wt + vs, mtcars)
我可以anova()用来查看两个预测变量所解释的因变量的方差量:
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
假设我现在添加一个随机截距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
每个固定效应所解释的方差现在下降了,因为 的随机截距cyl现在解释了 中的一些方差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
但是lmer_mtcars,我怎样才能知道方差的比例是多少wt,vs以及随机拦截的比例是cyl多少?