R2M: R-squared for nonlinear mixed models

View source: R/IA_tab.R

R2MR Documentation

R-squared for nonlinear mixed models

Description

R-squared ‘modified’ for nonlinear (mixed) models

Usage

R2M(x, ...)

## S3 method for class 'nls'
R2M(x, ...)

## S3 method for class 'lm'
R2M(x, ...)

## S3 method for class 'gls'
R2M(x, ...)

## S3 method for class 'gnls'
R2M(x, ...)

## S3 method for class 'lme'
R2M(x, ...)

## S3 method for class 'nlme'
R2M(x, ...)

Arguments

x

object of class ‘lm’, ‘nls’, ‘gls’, ‘gnls’, ‘lme’ or ‘nlme’ .

...

additional arguments (none use at the moment).

Details

I have read some papers about computing an R-squared for (non)linear (mixed) models and I am not sure that it makes sense at all. However, here they are and the method is general enough that it extends to nonlinear mixed models. What do these numbers mean and why would you want to compute them are good questions to ponder...

Recommended reading:
Nakagawa and Schielzeth Methods in Ecology and Evolution \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1111/j.2041-210x.2012.00261.x")}

https://stats.oarc.ucla.edu/other/mult-pkg/faq/general/faq-what-are-pseudo-r-squareds/

Spiess, AN., Neumeyer, N. An evaluation of R2 as an inadequate measure for nonlinear models in pharmacological and biochemical research: a Monte Carlo approach. BMC Pharmacol 10, 6 (2010). \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1186/1471-2210-10-6")}

https://stat.ethz.ch/pipermail/r-sig-mixed-models/2010q1/003363.html

https://blog.minitab.com/en/adventures-in-statistics-2/why-is-there-no-r-squared-for-nonlinear-regression

https://stats.stackexchange.com/questions/111150/calculating-r2-in-mixed-models-using-nakagawa-schielzeths-2013-r2glmm-me/225334#225334

Other R pacakges which calculate some version of an R-squared: performance, rcompanion, MuMIn

Value

it returns a list with the following structure:
for an object of class ‘lm’, ‘nls’, ‘gls’ or ‘gnls’,
R2: R-squared
var.comp: variance components with var.fixed and var.resid
var.perc: variance components percents (should add up to 100)
for an object of class ‘lme’ or ‘nlme’ in addition it also returns:
R2.marginal: marginal R2 which only includes the fixed effects
R2.conditional: conditional R2 which includes both the fixed and random effects
var.random: the variance contribution of the random effects

Note

The references here strongly discourage the use of R-squared in anything but linear models.

See Also

IA_tab

Examples


require(nlme)
data(barley, package = "nlraa")
fit2 <- lme(yield ~ NF + I(NF^2), random = ~ 1 | year, data = barley)
R2M(fit2)
## Nonlinear Mixed Model
barleyG <- groupedData(yield ~ NF | year, data = barley)
fit3L <- nlsLMList(yield ~ SSquadp3(NF, a, b, c), data = barleyG)
fit3 <- nlme(fit3L, random = pdDiag(a + b ~ 1))
R2M(fit3)


nlraa documentation built on May 29, 2024, 2:01 a.m.