从GAM/BAM模型中计算有条件和边际R2

发布于 2025-01-25 17:13:55 字数 1721 浏览 4 评论 0原文

我有一个使用MGCV软件包的BAM函数计算得出的广义添加剂模型。我在模型中有两个随机效应,有5个固定效果,其中一种是平滑的。 R2很高(见下文),我有兴趣知道这是否是由随机效应以及固定效果在解释差异中所扮演的角色的驱动。

我以前通过计算条件和边缘R2值来对GLMM进行此操作。有没有一种方法可以使用伽玛?特别是使用MGCV的BAM函数的一种?

deg_test1 <- bam(deg ~ SE_score + s(ri,bs="ad") + sex + species + year + 
                  s(code, bs = 're') + s(station, bs = 're'), 
                family=nb(), data=node_dat, na.action = "na.fail", discrete = TRUE)

> summary(deg_test1)

Family: Negative Binomial(41687141.289) 
Link function: log 

Formula:
deg ~ SE_score + s(ri, bs = "ad") + sex + species + year + 
    s(code, bs = "re") + s(station, bs = "re")

Parametric coefficients:
                       Estimate Std. Error t value Pr(>|t|)    
(Intercept)            -0.06071    0.10751  -0.565  0.57232    
SE_score               -0.30396    0.15245  -1.994  0.04618 *  
sexM                    0.17797    0.09329   1.908  0.05643 .  
speciesSilvertip Shark  0.58195    0.09445   6.161 7.24e-10 ***
year2015               -0.07197    0.05307  -1.356  0.17508    
year2016               -0.11550    0.05927  -1.949  0.05131 .  
year2017               -0.18810    0.06467  -2.908  0.00363 ** 
year2018               -0.43988    0.07953  -5.531 3.19e-08 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Approximate significance of smooth terms:
              edf  Ref.df      F  p-value    
s(ri)       6.029   7.228 21.651  < 2e-16 ***
s(code)    83.744 133.000  8.133 0.001792 ** 
s(station) 43.302  62.000 15.196 0.000659 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

R-sq.(adj) =  0.836   Deviance explained = 95.7%
fREML =  76757  Scale est. = 1         n = 82210

I have a generalised additive model calculated using the bam function from the mgcv package. I have two random effects in the model and 5 fixed effects, one of which is smoothed. The R2 are quite high (see below) and I'm interested to know if this is being driven by the random effects and how much of a role the fixed effects play in explaining the variance.

I've previously done this on GLMM by calculating the conditional and marginal R2 values. Is there a way of doing this with a GAMM? Specifically one using the bam function from mgcv?

deg_test1 <- bam(deg ~ SE_score + s(ri,bs="ad") + sex + species + year + 
                  s(code, bs = 're') + s(station, bs = 're'), 
                family=nb(), data=node_dat, na.action = "na.fail", discrete = TRUE)

> summary(deg_test1)

Family: Negative Binomial(41687141.289) 
Link function: log 

Formula:
deg ~ SE_score + s(ri, bs = "ad") + sex + species + year + 
    s(code, bs = "re") + s(station, bs = "re")

Parametric coefficients:
                       Estimate Std. Error t value Pr(>|t|)    
(Intercept)            -0.06071    0.10751  -0.565  0.57232    
SE_score               -0.30396    0.15245  -1.994  0.04618 *  
sexM                    0.17797    0.09329   1.908  0.05643 .  
speciesSilvertip Shark  0.58195    0.09445   6.161 7.24e-10 ***
year2015               -0.07197    0.05307  -1.356  0.17508    
year2016               -0.11550    0.05927  -1.949  0.05131 .  
year2017               -0.18810    0.06467  -2.908  0.00363 ** 
year2018               -0.43988    0.07953  -5.531 3.19e-08 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Approximate significance of smooth terms:
              edf  Ref.df      F  p-value    
s(ri)       6.029   7.228 21.651  < 2e-16 ***
s(code)    83.744 133.000  8.133 0.001792 ** 
s(station) 43.302  62.000 15.196 0.000659 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

R-sq.(adj) =  0.836   Deviance explained = 95.7%
fREML =  76757  Scale est. = 1         n = 82210

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文