3
$\begingroup$

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?

$\endgroup$
5
  • $\begingroup$ Since your question is about a specific function in a package,, why don't you just try it and see what happens? $\endgroup$
    – rep_ho
    Nov 5, 2021 at 10:41
  • 1
    $\begingroup$ 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? $\endgroup$
    – MriRo
    Nov 10, 2021 at 4:00
  • $\begingroup$ good question ... $\endgroup$
    – rep_ho
    Nov 10, 2021 at 17:40
  • 1
    $\begingroup$ Be careful about $R^2$ when the model is nonlinear. The “proportion of variance explained” interpretation does not apply. $\endgroup$
    – Dave
    Nov 11, 2021 at 23:11
  • $\begingroup$ 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? $\endgroup$
    – MriRo
    Nov 11, 2021 at 23:19

2 Answers 2

0
$\begingroup$

You can use the r.squaredGLMM function in the R package MuMIn as it follows:

r.squaredGLMM(your_GAMM_object$lme)
$\endgroup$
-1
$\begingroup$

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.

$\endgroup$
3
  • $\begingroup$ 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.... $\endgroup$
    – MriRo
    Nov 11, 2021 at 23:22
  • $\begingroup$ 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. $\endgroup$
    – StatsBio
    Nov 12, 2021 at 21:43
  • 1
    $\begingroup$ -1 It is false that $R^2$ describes the explained variance in nonlinear regression models, of which GAM is one example. $\endgroup$
    – Dave
    Nov 14, 2021 at 1:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.