我正在尝试分析Year对特定个体组(我有3个组)的变量logInd的影响。最简单的模型:
> fix1 = lm(logInd ~ 0 + Group + Year:Group, data = mydata)
> summary(fix1)
Call:
lm(formula = logInd ~ 0 + Group + Year:Group, data = mydata)
Residuals:
Min 1Q Median 3Q Max
-5.5835 -0.3543 -0.0024 0.3944 4.7294
Coefficients:
Estimate Std. Error t value Pr(>|t|)
Group1 4.6395740 0.0466217 99.515 < 2e-16 ***
Group2 4.8094268 0.0534118 90.044 < 2e-16 ***
Group3 4.5607287 0.0561066 81.287 < 2e-16 ***
Group1:Year -0.0084165 0.0027144 -3.101 0.00195 **
Group2:Year 0.0032369 0.0031098 1.041 0.29802
Group3:Year 0.0006081 0.0032666 0.186 0.85235
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.7926 on 2981 degrees of freedom
Multiple R-squared: 0.9717, Adjusted R-squared: 0.9716
F-statistic: 1.705e+04 on 6 and 2981 DF, p-value: < 2.2e-16
我们可以看到Group1显着下降,Groups 2和3上升但不是显着。
显然,个体应该是随机效应,所以我为每个个体引入随机拦截效应:
> mix1a = lmer(logInd ~ 0 + Group + Year:Group + (1|Individual), data = mydata)
> summary(mix1a)
Linear mixed model fit by REML
Formula: logInd ~ 0 + Group + Year:Group + (1 | Individual)
Data: mydata
AIC BIC logLik deviance REMLdev
4727 4775 -2356 4671 4711
Random effects:
Groups Name Variance Std.Dev.
Individual (Intercept) 0.39357 0.62735
Residual 0.24532 0.49530
Number of obs: 2987, groups: Individual, 103
Fixed effects:
Estimate Std. Error t value
Group1 4.6395740 0.1010868 45.90
Group2 4.8094268 0.1158095 41.53
Group3 4.5607287 0.1216522 37.49
Group1:Year -0.0084165 0.0016963 -4.96
Group2:Year 0.0032369 0.0019433 1.67
Group3:Year 0.0006081 0.0020414 0.30
Correlation of Fixed Effects:
Group1 Group2 Group3 Grp1:Y Grp2:Y
Group2 0.000
Group3 0.000 0.000
Group1:Year -0.252 0.000 0.000
Group2:Year 0.000 -0.252 0.000 0.000
Group3:Year 0.000 0.000 -0.252 0.000 0.000
它产生了预期的效果-斜率的SE(系数Group1-3:Year)现在更低,而剩余SE也更低。
个体的斜率也不同,因此我还介绍了随机斜率效应:
> mix1c = lmer(logInd ~ 0 + Group + Year:Group + (1 + Year|Individual), data = mydata)
> summary(mix1c)
Linear mixed model fit by REML
Formula: logInd ~ 0 + Group + Year:Group + (1 + Year | Individual)
Data: mydata
AIC BIC logLik deviance REMLdev
2941 3001 -1461 2885 2921
Random effects:
Groups Name Variance Std.Dev. Corr
Individual (Intercept) 0.1054790 0.324775
Year 0.0017447 0.041769 -0.246
Residual 0.1223920 0.349846
Number of obs: 2987, groups: Individual, 103
Fixed effects:
Estimate Std. Error t value
Group1 4.6395740 0.0541746 85.64
Group2 4.8094268 0.0620648 77.49
Group3 4.5607287 0.0651960 69.95
Group1:Year -0.0084165 0.0065557 -1.28
Group2:Year 0.0032369 0.0075105 0.43
Group3:Year 0.0006081 0.0078894 0.08
Correlation of Fixed Effects:
Group1 Group2 Group3 Grp1:Y Grp2:Y
Group2 0.000
Group3 0.000 0.000
Group1:Year -0.285 0.000 0.000
Group2:Year 0.000 -0.285 0.000 0.000
Group3:Year 0.000 0.000 -0.285 0.000 0.000
但是现在,与预期相反,坡度的SE(系数Group1-3:Year)现在要高得多,甚至比完全没有随机效应的SE高!
这怎么可能?我希望随机效应将“吞噬”无法解释的可变性并增加估计的“确定性”!
但是,残余SE的行为符合预期-低于随机拦截模型中的SE。
如果需要,这是数据。
编辑
现在我意识到了惊人的事实。如果我分别对每个人进行线性回归,然后对所得斜率进行ANOVA,则得到的结果与随机斜率模型完全相同!你知道为什么吗?
indivSlope = c()
for (indiv in 1:103) {
mod1 = lm(logInd ~ Year, data = mydata[mydata$Individual == indiv,])
indivSlope[indiv] = coef(mod1)['Year']
}
indivGroup = unique(mydata[,c("Individual", "Group")])[,"Group"]
anova1 = lm(indivSlope ~ 0 + indivGroup)
summary(anova1)
Call:
lm(formula = indivSlope ~ 0 + indivGroup)
Residuals:
Min 1Q Median 3Q Max
-0.176288 -0.016502 0.004692 0.020316 0.153086
Coefficients:
Estimate Std. Error t value Pr(>|t|)
indivGroup1 -0.0084165 0.0065555 -1.284 0.202
indivGroup2 0.0032369 0.0075103 0.431 0.667
indivGroup3 0.0006081 0.0078892 0.077 0.939
Residual standard error: 0.04248 on 100 degrees of freedom
Multiple R-squared: 0.01807, Adjusted R-squared: -0.01139
F-statistic: 0.6133 on 3 and 100 DF, p-value: 0.6079
如果需要,这是数据。
Group
Group
:Year
logInd ~ Year*Group
,只有系数的形状不同,仅此而已。取决于您的口味和喜欢的系数形状,仅此而已。在您编写第一个模型时,不排除“年主要影响” ...的logInd ~ Year*Group
作用完全相同,因此Year
系数不是主要影响,而是Group1:Year。