如何从 ML 拟合的 lme4::lmer 模型中提取信息标准,并与 REML 拟合模型的模型摘要相结合

How to extract information criterions from `lme4::lmer`-model fitted by ML and combine with model summary from REML-fitted model

我正在尝试从 lme4::lmer 中使用最大似然 (ML) 拟合的 HLM 模型 summary 访问 AIC、BIC、logLik 和偏差数据,并与基本相同的模型结合装有受限最大似然 (REML)。 lmersummary返回的对象结构乱七八糟,我无法找到where/how存储了这个数据。

[更新:]根据我收到的回复,我更新了代码以反映所取得的进展:

代码示例:

# Least working example
library(lme4)
library(lmerTest)
df <- lme4::sleepstudy
names(df)
# Example model
model <- lmer(Reaction ~ (1|Subject), df, REML = TRUE)
information_criterion <- data.frame(
            "AIC" = AIC(model),
            "BIC" = BIC(model),
            "logLik" = logLik(model),
            "deviance" = deviance(model, REML=FALSE),
            "df.residual" = df.residual(model)
            )
mod_sum <- list(summary(model), information_criterion)
我基本上想修改输出以类似于 summary if REML = FALSE(不工作)的输出:
> mod_sum

Linear mixed model fit by REML. t-tests use Satterthwaite's method [
lmerModLmerTest]
Formula: Reaction ~ (1 | Subject)
   Data: df

## Information criterion injected here: ##########################

     AIC      BIC   logLik deviance df.resid   # <-- THESE ARE THE LINES I WANT
  1916.5   1926.1   -955.3   1910.5      177   # <-- 

##################################################################

REML criterion at convergence: 1904.3

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-2.4983 -0.5501 -0.1476  0.5123  3.3446 

Random effects:
 Groups   Name        Variance Std.Dev.
 Subject  (Intercept) 1278     35.75   
 Residual             1959     44.26   
Number of obs: 180, groups:  Subject, 18

Fixed effects:
            Estimate Std. Error     df t value Pr(>|t|)    
(Intercept)   298.51       9.05  17.00   32.98   <2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

有几点:

  1. 这里有错字:
    m2sum[["information_criterion"]] <- summary(model1)$information_criterion

应该是m2_sum

  1. 您可以使用:
  2. 而不是 summary(model1)$information_criterion
     AIC(model1)

因此,以下应该有效:

m2_sum[["information_criterion"]] <- AIC(model1)

根据对 OP 的更改进行更新。

这应该可行,但请参阅我最后的评论,因为这可能不是明智之举:

> m2_sum$AICtab <- m1_sum$AICtab
> m2_sum

Linear mixed model fit by REML. t-tests use Satterthwaite's method ['lmerModLmerTest']
Formula: Reaction ~ (1 | Subject)
   Data: df

     AIC      BIC   logLik deviance df.resid 
  1916.5   1926.1   -955.3   1910.5      177 

Scaled residuals: 
    Min      1Q  Median      3Q     Max 
-2.4983 -0.5501 -0.1476  0.5123  3.3446