Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

R2M

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 doi: 10.1111/j.2041-210x.2012.00261.x

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). doi: 10.1186/1471-2210-10-6

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

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

Nonlinear Regression for Agricultural Applications

v0.89
GPL-3
Authors
Fernando Miguez [aut, cre] (<https://orcid.org/0000-0002-4627-8329>), José Pinheiro [ctb, cph] (author of nlme::nlsList, nlme::predict.gnls, nlme::predict.nlme), Douglas Bates [ctb, cph] (author of nlme::nlsList, nlme::predict.gnls, nlme::predict.nlme), R-core [ctb, cph]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.