| r2 | R Documentation |
Calculate the R2, also known as the coefficient of determination, value for different model objects. Depending on the model, R2, pseudo-R2, or marginal / adjusted R2 values are returned.
r2(model, ...)
## Default S3 method:
r2(model, ci = NULL, verbose = TRUE, ...)
## S3 method for class 'mlm'
r2(model, multivariate = TRUE, ...)
## S3 method for class 'merMod'
r2(model, ci = NULL, tolerance = 1e-05, ...)
model |
A statistical model. |
... |
Arguments passed down to the related r2-methods. |
ci |
Confidence interval level, as scalar. If |
verbose |
Logical. Should details about R2 and CI methods be given
( |
multivariate |
Logical. Should multiple R2 values be reported as
separated by response (FALSE) or should a single R2 be reported as
combined across responses computed by |
tolerance |
Tolerance for singularity check of random effects, to decide
whether to compute random effect variances for the conditional r-squared
or not. Indicates up to which value the convergence result is accepted. When
|
Returns a list containing values related to the most appropriate R2
for the given model (or NULL if no R2 could be extracted). See the
list below:
Logistic models: Tjur's R2
Generalized linear models: Nagelkerke's R2
Multinomial Logit: McFadden's R2
Beta or ordered Beta: Ferrari's R2
Models with zero-inflation: R2 for zero-inflated models
Mixed models: Nakagawa's R2
Bayesian models: R2 bayes
Additional model families from package glmmTMB that are not mentioned
above (like nbinom1, compois, betabinomial etc.) default to
McFadden's R2.
R2 for models from package gamlss is extracted directly from the
summary(), if available. Else, McFadden's R2 is returned.
If there is no r2()-method defined for the given model class, r2() tries
to return a "generic" r-quared value, calculated as following:
1-sum((y-y_hat)^2)/sum((y-y_bar)^2)
r2_bayes(), r2_coxsnell(), r2_kullback(), r2_loo(),
r2_mcfadden(), r2_nagelkerke(), r2_nakagawa(), r2_tjur(),
r2_xu(), r2_zeroinflated(), and r2_mlm().
# Pseudo r-quared for GLM
model <- glm(vs ~ wt + mpg, data = mtcars, family = "binomial")
r2(model)
# r-squared including confidence intervals
model <- lm(mpg ~ wt + hp, data = mtcars)
r2(model, ci = 0.95)
model <- lme4::lmer(Sepal.Length ~ Petal.Length + (1 | Species), data = iris)
r2(model)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.