1

In Nakagawa et al. the conditional and marginal R2 are defined for linear mixed models to disentangle the ~variance explained by the fixed and random effects .

Nakagawa, S., Johnson, P. C. D., & Schielzeth, H. (2017). The coefficient of determination R2 and intra-class correlation coefficient from generalized linear mixed-effects models revisited and expanded. Journal of The Royal Society Interface, 14(134), 20170213. doi: 10.1098/rsif.2017.0213

When fitting a generalized additive mixed model (GAMM) via the mgcv package in R with normal errors and identity link, the fit is done via the nlme package here. Is it possible to estimate marginal and conditional R2 for this non linear regression in the same way as for lme, e.g. via the r.squaredGLMM() function from the MuMIn package and if yes why?

Update: What if I rewrite my gam model and use polynomials and lme instead, say

lme(Y~ poly(x1,2):fac+poly(x2,2):fac, random=~1|a/b/d)

does this reduce to:

lme(Y~ I(x1^2):fac+I(x1):fac+I(x2^2):fac+I(x2):fac+fac, random=~1|a/b/d)

so that this reduces to a linear mixed model instead?

Karolis Koncevičius
  • 4,282
  • 7
  • 30
  • 47
MriRo
  • 83
  • 10
  • Since your question is about a specific function in a package,, why don't you just try it and see what happens? – rep_ho Nov 05 '21 at 10:41
  • Sure, I can calculate them and I know that the calculation works or better said I get estimated from it, but I do not know if those are mathematically meaningul, because I have not a linear mixed model but estimated nonlinear effects in a gamm and so if I can actually calculate the variances of the fixed effects in that way? – MriRo Nov 10 '21 at 04:00
  • good question ... – rep_ho Nov 10 '21 at 17:40
  • 1
    Be careful about $R^2$ when the model is nonlinear. The “proportion of variance explained” interpretation does not apply. – Dave Nov 11 '21 at 23:11
  • Can I (in the gaussian error identity link case) calculate : 1- ((deviance(model)/deviance(nullmodel)) where nullmodel is a model including only my random effect structure? Should this give me a deviance explained for my fixed effects at least? – MriRo Nov 11 '21 at 23:19

1 Answers1

-1

The R squared for a non-linear function should be the same as that for a linear function. The reason is that it explains the amount of variance explained by the fitted line of best fit. When you have GAM model, this is the same case. You can think of this as the functional summation of each of the spline basis function terms in the model. The combined summation of best fit line can then be analysed using the exact same variance explained principle as a linear function.

SysEng
  • 73
  • 9
  • thanks for your help,. From GAMM (rdocumentation.org/packages/mgcv/versions/1.8-38/topics/gamm) the wiggly parts of the smooth functions are treated as random effects, so I don´t know how to disentangle the variance of the fixed effects then in accordance to the formula in Nakagawa et al.... – MriRo Nov 11 '21 at 23:22
  • To disentangle the fixed and random effect R squared, fit the model with fixed effects only variables, calculate the corresponding R squared for this model fit. Then fit the the model with the fixed variable plus random effect variable(s) e.g. y ~ fixed vars + (1 | randomVar), and calculate the corresponding R squared coefficient. The increase in R square is the amount of variance explained by adding the random effects variable(s); this can be converted to a percentage. Similarly for icc @MriRo. – SysEng Nov 12 '21 at 21:43
  • 1
    -1 [It is false that $R^2$ describes the explained variance in nonlinear regression models](https://stats.stackexchange.com/q/551915/247274), of which GAM is one example. – Dave Nov 14 '21 at 01:40