【问题标题】:R-Squared of lmer model fitlmer 模型拟合的 R 平方
【发布时间】:2018-01-01 19:00:15
【问题描述】:

我有一个混合效应模型,我想查看 R² 值和 p 值。我认为这是可以通过 summary() 访问的,但事实并非如此。或者至少我没有意识到。

> summary(fit1.lme <- lmer(log(log(Amplification)) ~ poly(Voltage, 3) + (1 | Serial_number), data = bdf))
Linear mixed model fit by REML ['lmerMod']
Formula: log(log(Amplification)) ~ poly(Voltage, 3) + (1 | Serial_number)
   Data: bdf

REML criterion at convergence: -253237.6

Scaled residuals: 
     Min       1Q   Median       3Q      Max 
-14.8183  -0.4863  -0.0681   0.2941   9.3292 

Random effects:
 Groups        Name        Variance Std.Dev.
 Serial_number (Intercept) 0.008435 0.09184 
 Residual                  0.001985 0.04456 
Number of obs: 76914, groups:  Serial_number, 1270

Fixed effects:
                    Estimate Std. Error t value
(Intercept)         0.826745   0.002582     320
poly(Voltage, 3)1 286.978430   0.045248    6342
poly(Voltage, 3)2 -74.061993   0.045846   -1615
poly(Voltage, 3)3  39.605454   0.045505     870

Correlation of Fixed Effects:
            (Intr) p(V,3)1 p(V,3)2
ply(Vlt,3)1 0.001                 
ply(Vlt,3)2 0.002  0.021          
ply(Vlt,3)3 0.001  0.032   0.028  

【问题讨论】:

标签: r lme4


【解决方案1】:

对于 R²,您可以使用来自 ‘MuMInr.squaredGLMM(fit1.lme) 包裹。它将返回边际和条件 R²。

对于 p 值,您可以通过使用 summarylmerTest 包来找到它们。

有关混合模型的 p 值的更多信息:http://mindingthebrain.blogspot.ch/2014/02/three-ways-to-get-parameter-specific-p.html

【讨论】:

    【解决方案2】:

    我添加了一个非常小的演示,其中包含臭氧层的分层建模,其中建模承认它按月变化。您可以在下面找到比较。我只能在 MuMIn 包中找到 R squared 术语。

    MuMIn 包

    > data(airquality)
    
    > MuMIn::r.squaredGLMM(lme4::lmer(data=airquality, Ozone ~ 1 + (1|Month)))
         R2m       R2c
    [1,]   0 0.2390012
    > summary(lm(data=airquality, Ozone ~ 1 + (1|Month)))$r.squared
    [1] 0
    

    我们比较线性回归和混合效应模型,也就是分层回归模型。

    线性回归

    > summary(lm(data=airquality, Ozone ~ 1 + (1|Month)))
    
    Call:
    lm(formula = Ozone ~ 1 + (1 | Month), data = airquality)
    
    Residuals:
       Min     1Q Median     3Q    Max 
    -41.13 -24.13 -10.63  21.12 125.87 
    
    Coefficients: (1 not defined because of singularities)
                  Estimate Std. Error t value Pr(>|t|)    
    (Intercept)     42.129      3.063   13.76   <2e-16 ***
    1 | MonthTRUE       NA         NA      NA       NA    
    ---
    Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    
    Residual standard error: 32.99 on 115 degrees of freedom
      (37 observations deleted due to missingness)
    

    lmer4

    > summary(lme4::lmer(data=airquality, Ozone ~ 1 + (1|Month)))
    Linear mixed model fit by REML ['lmerMod']
    Formula: Ozone ~ 1 + (1 | Month)
       Data: airquality
    
    REML criterion at convergence: 1116.5
    
    Scaled residuals: 
        Min      1Q  Median      3Q     Max 
    -1.7084 -0.6269 -0.2669  0.4121  3.7507 
    
    Random effects:
     Groups   Name        Variance Std.Dev.
     Month    (Intercept) 270.6    16.45   
     Residual             861.6    29.35   
    Number of obs: 116, groups:  Month, 5
    
    Fixed effects:
                Estimate Std. Error t value
    (Intercept)   41.093      7.922   5.187
    

    lmerTest

    library(lmerTest)
    
    > lmerTest::lmer(data=airquality, Ozone ~ 1 + (1|Month))
    Linear mixed model fit by REML ['lmerModLmerTest']
    Formula: Ozone ~ 1 + (1 | Month)
       Data: airquality
    REML criterion at convergence: 1116.544
    Random effects:
     Groups   Name        Std.Dev.
     Month    (Intercept) 16.45   
     Residual             29.35   
    Number of obs: 116, groups:  Month, 5
    Fixed Effects:
    (Intercept)  
          41.09  
    > summary(lmerTest::lmer(data=airquality, Ozone ~ 1 + (1|Month)))
    Linear mixed model fit by REML. t-tests use Satterthwaite's method ['lmerModLmerTest']
    Formula: Ozone ~ 1 + (1 | Month)
       Data: airquality
    
    REML criterion at convergence: 1116.5
    
    Scaled residuals: 
        Min      1Q  Median      3Q     Max 
    -1.7084 -0.6269 -0.2669  0.4121  3.7507 
    
    Random effects:
     Groups   Name        Variance Std.Dev.
     Month    (Intercept) 270.6    16.45   
     Residual             861.6    29.35   
    Number of obs: 116, groups:  Month, 5
    
    Fixed effects:
                Estimate Std. Error     df t value Pr(>|t|)   
    (Intercept)   41.093      7.922  4.096   5.187  0.00616 **
    ---
    Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
    

    【讨论】:

    • 留下关于拒绝投票原因的反馈是积极的,不好。
    • 有趣,我从未见过没有坡度的模型。为什么只绘制截距?
    • @J.A.Cado 可能用户想将其用作空模型进行比较。
    【解决方案3】:

    您可以尝试使用 sjPlot 或 sjstats 软件包。第一个包帮助从 lme4 分析创建 APA 样式表,第二个包用于提取拟合统计数据。

    您只需要简单地编写代码:

    tab_model(fit1.lme)
    

    它将输出一个 APA 表,包括估计斜率、截距、CI、p 值、方差、残差、观察数、ICC、边际和条件 R 平方等。

    看起来像这样:

    【讨论】:

    • 如果我没记错的话,这个图来自 sjPlot,sjstat 可以帮助提取 p 值,代码:p_value()。我个人更喜欢使用 sjPlot,因为它更清晰,返回的统计值也更多。希望对您有所帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-07-29
    • 2020-02-12
    • 1970-01-01
    • 2021-02-15
    • 2023-03-25
    • 2021-02-04
    • 2015-06-25
    相关资源
    最近更新 更多