r2 {lvmisc} | R Documentation |
Compute R squared
Description
Returns the R squared values according to the model class.
Usage
r2(model)
## Default S3 method:
r2(model)
## S3 method for class 'lm'
r2(model)
## S3 method for class 'lmerMod'
r2(model)
Arguments
model |
An object containing a model. |
Details
R squared computations.
Value
If the model is a linear model, it returns a data.frame
with the R squared and adjusted R squared values. If the model is a
linear mixed model it return a data.frame
with the marginal and
conditional R squared values as described by Nakagawa and Schielzeth
(2013). See the formulas for the computations in "Details".
R squared
Where is the variance explained by the model and
is the residual variance.
Adjusted R squared
Where is the number of data points and
is the number of
predictors in the model.
Marginal R squared
Where is the variance of the fixed effects,
is
the variance of the random effects and
is the
residual variance.
Conditional R squared
References
Nakagawa, S., & Schielzeth, H. (2013). A general and simple method for obtaining R2 from generalized linear mixed-effects models. Methods in Ecology and Evolution, 4(2), 133–142. doi:10.1111/j.2041-210x.2012.00261.x.
Examples
m1 <- lm(Sepal.Length ~ Species, data = iris)
r2(m1)
if (require(lme4, quietly = TRUE)) {
m2 <- lmer(
Sepal.Length ~ Sepal.Width + Petal.Length + (1 | Species), data = iris
)
r2(m2)
}