Calculate conditional and marginal R2 from a gam/bam model

311 Views Asked by At

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
0

There are 0 best solutions below