lme4和stan中混合模型输出的解释

机器算法验证 混合模式 lme4-nlme 斯坦
2022-04-06 00:52:18

这是我的模型lme4

library(nlme)   # for the data
data("Machines")  # the data

fit2 <- lmer(score ~  -1 + Machine + (1|Worker), data=Machines)
summary(fit2)

Linear mixed model fit by REML ['lmerMod']
Formula: score ~ -1 + Machine + (1 | Worker)
   Data: Machines

REML criterion at convergence: 286.9

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-2.7249 -0.5233  0.1328  0.6513  1.7559 

Random effects:
 Groups   Name        Variance Std.Dev.
 Worker   (Intercept) 26.487   5.147   
 Residual              9.996   3.162   
Number of obs: 54, groups:  Worker, 6

Fixed effects:
         Estimate Std. Error t value
MachineA   52.356      2.229   23.48
MachineB   60.322      2.229   27.06
MachineC   66.272      2.229   29.73

Correlation of Fixed Effects:
         MachnA MachnB
MachineB 0.888        
MachineC 0.888  0.888 

当我在 STAN 中使用 建模时rstanarm,我得到了完全不同的输出:

library(rstanarm)
fit2a <- stan_glmer(score ~  -1 + Machine + (1|Worker), data=Machines)
fit2a

stan_glmer(formula = score ~ -1 + Machine + (1 | Worker), data = Machines)

Estimates:
         Median MAD_SD
MachineA -6.3   24.4  
MachineB  1.6   24.3  
MachineC  7.5   24.4  
sigma     3.6    0.4  

Error terms:
 Groups   Name        Std.Dev.
 Worker   (Intercept) 38.2    
 Residual              3.6    
Num. levels: Worker 6 

Sample avg. posterior predictive 
distribution of y (X = xbar):
         Median MAD_SD
mean_PPD 59.6    0.7 

我的解释是这样的:我通过将 mean_PPD 添加到估计值来获得固定效应,例如 lme 中的 59.6-6.3 = 53.3 ~ 52.3。

stan 输出中的误差项是随机效应吗?为什么它使用中位数进行估计,或者这是一个rstanarm特定的东西?

1个回答

主要问题是 rstanarm 中的一个错误的结果,该错误已在 GitHub 上修复。

但是,一般来说,我们不推荐排除截距的 rstanarm 模型。更好的选择是在截距上放置一个均值为零的紧先验。lme4::lmer在这种情况下,包括截距会在和之间产生更好的拟合和相似的结果rstanarm::stan_lmer