performance

performance: An R Package for Assessment, Comparison and Testing of Statistical Models - Published in JOSS (2021)

https://github.com/easystats/performance

Science Score: 93.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 4 DOI reference(s) in README and JOSS metadata
  • Academic publication links
    Links to: joss.theoj.org
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
    Published in Journal of Open Source Software

Keywords

aic easystats hacktoberfest loo machine-learning mixed-models models performance r r2 statistics

Keywords from Contributors

standardization correlation predict pca beta ci confidence-intervals data-reduction fa feature-extraction

Scientific Fields

Earth and Environmental Sciences Physical Sciences - 40% confidence
Economics Social Sciences - 40% confidence
Engineering Computer Science - 40% confidence
Last synced: 4 months ago · JSON representation

Repository

:muscle: Models' quality and performance metrics (R2, ICC, LOO, AIC, BF, ...)

Basic Info
Statistics
  • Stars: 1,100
  • Watchers: 24
  • Forks: 100
  • Open Issues: 105
  • Releases: 26
Topics
aic easystats hacktoberfest loo machine-learning mixed-models models performance r r2 statistics
Created almost 7 years ago · Last pushed 4 months ago
Metadata Files
Readme Changelog Contributing Funding License Code of conduct Support

README.Rmd

---
output: github_document
bibliography: paper.bib
---

# performance 

```{r, echo = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  warning = FALSE,
  message = FALSE,
  out.width = "100%",
  dpi = 150,
  fig.path = "man/figures/",
  comment = "#>"
)

options(
  knitr.kable.NA = "",
  digits = 4,
  width = 100
)

library(performance)
```

[![DOI](https://joss.theoj.org/papers/10.21105/joss.03139/status.svg)](https://doi.org/10.21105/joss.03139)
[![downloads](https://cranlogs.r-pkg.org/badges/performance)](https://cran.r-project.org/package=performance) [![total](https://cranlogs.r-pkg.org/badges/grand-total/performance)](https://cranlogs.r-pkg.org/)

***Test if your model is a good model!***

A crucial aspect when building regression models is to evaluate the quality of modelfit. It is important to investigate how well models fit to the data and which fit indices to report. Functions to create diagnostic plots or to compute fit measures do exist, however, mostly spread over different packages. There is no unique and consistent approach to assess the model quality for different kind of models.

The primary goal of the **performance** package is to fill this gap and to provide utilities for computing **indices of model quality** and **goodness of fit**. These include measures like r-squared (R2), root mean squared error (RMSE) or intraclass correlation coefficient (ICC) , but also functions to check (mixed) models for overdispersion, zero-inflation, convergence or singularity.

## Installation

[![CRAN](https://www.r-pkg.org/badges/version/performance)](https://cran.r-project.org/package=performance) [![performance status badge](https://easystats.r-universe.dev/badges/performance)](https://easystats.r-universe.dev) [![codecov](https://codecov.io/gh/easystats/performance/branch/main/graph/badge.svg)](https://app.codecov.io/gh/easystats/performance)

The *performance* package is available on CRAN, while its latest development version is available on R-universe (from _rOpenSci_).

Type | Source | Command
---|---|---
Release | CRAN | `install.packages("performance")`
Development | R-universe | `install.packages("performance", repos = "https://easystats.r-universe.dev")`

Once you have downloaded the package, you can then load it using:

```{r, eval=FALSE}
library("performance")
```

> **Tip**
>
> Instead of `library(performance)`, use `library(easystats)`. This will make all features of the easystats-ecosystem available.
>
> To stay updated, use `easystats::install_latest()`.

## Citation

To cite performance in publications use:

```{r}
citation("performance")
```

## Documentation

[![Documentation](https://img.shields.io/badge/documentation-performance-orange.svg?colorB=E91E63)](https://easystats.github.io/performance/)
[![Blog](https://img.shields.io/badge/blog-easystats-orange.svg?colorB=FF9800)](https://easystats.github.io/blog/posts/)
[![Features](https://img.shields.io/badge/features-performance-orange.svg?colorB=2196F3)](https://easystats.github.io/performance/reference/index.html)


There is a nice introduction into the package on [youtube](https://www.youtube.com/watch?v=EPIxQ5i5oxs).

## The *performance* workflow

```{r workflow, echo=FALSE, out.width="75%"}
knitr::include_graphics("man/figures/figure_workflow.png")
```

### Assessing model quality

#### R-squared

**performance** has a generic `r2()` function, which computes the r-squared for
many different models, including mixed effects and Bayesian regression models.

`r2()` returns a list containing values related to the "most appropriate"
r-squared for the given model.

```{r}
model <- lm(mpg ~ wt + cyl, data = mtcars)
r2(model)

model <- glm(am ~ wt + cyl, data = mtcars, family = binomial)
r2(model)

library(MASS)
data(housing)
model <- polr(Sat ~ Infl + Type + Cont, weights = Freq, data = housing)
r2(model)
```

The different R-squared measures can also be accessed directly via functions like `r2_bayes()`, `r2_coxsnell()` or `r2_nagelkerke()` (see a full list of functions [here](https://easystats.github.io/performance/reference/index.html#section-r-functions)).

For mixed models, the _conditional_ and _marginal_ R-squared are returned. The
_marginal R-squared_ considers only the variance of the fixed effects and
indicates how much of the model's variance is explained by the fixed effects
part only. The _conditional R-squared_ takes both the fixed and random effects
into account and indicates how much of the model's variance is explained by the
"complete" model.

For frequentist mixed models, `r2()` (resp. `r2_nakagawa()`) computes the _mean_
random effect variances, thus `r2()` is also appropriate for mixed models with
more complex random effects structures, like random slopes or nested random
effects [@johnson_extension_2014; @nakagawa_coefficient_2017].

```{r}
set.seed(123)
library(rstanarm)

model <- stan_glmer(
  Petal.Length ~ Petal.Width + (1 | Species),
  data = iris,
  cores = 4
)

r2(model)

library(lme4)
model <- lmer(Reaction ~ Days + (1 + Days | Subject), data = sleepstudy)
r2(model)
```

#### Intraclass Correlation Coefficient (ICC)

Similar to R-squared, the ICC provides information on the explained variance and
can be interpreted as "the proportion of the variance explained by the grouping
structure in the population" [@hox_multilevel_2010].

`icc()` calculates the ICC for various mixed model objects, including `stanreg`
models.

```{r}
library(lme4)
model <- lmer(Reaction ~ Days + (1 + Days | Subject), data = sleepstudy)
icc(model)
```

...and models of class `brmsfit`.

```{r, echo=FALSE, eval=curl::has_internet()}
model <- insight::download_model("brms_mixed_1")
```
```{r, eval=FALSE}
library(brms)
set.seed(123)
model <- brm(mpg ~ wt + (1 | cyl) + (1 + wt | gear), data = mtcars)
```
```{r}
icc(model)
```

### Model diagnostics

#### Check for overdispersion

Overdispersion occurs when the observed variance in the data is higher than the
expected variance from the model assumption (for Poisson, variance roughly
equals the mean of an outcome). `check_overdispersion()` checks if a count model
(including mixed models) is overdispersed or not.

```{r}
library(glmmTMB)
data(Salamanders)
model <- glm(count ~ spp + mined, family = poisson, data = Salamanders)
check_overdispersion(model)
```

Overdispersion can be fixed by either modelling the dispersion parameter (not
possible with all packages), or by choosing a different distributional family
(like Quasi-Poisson, or negative binomial, see [@gelman_data_2007]).

#### Check for zero-inflation

Zero-inflation (in (Quasi-)Poisson models) is indicated when the amount of
observed zeros is larger than the amount of predicted zeros, so the model is
_underfitting_ zeros. In such cases, it is recommended to use negative binomial
or zero-inflated models.

Use `check_zeroinflation()` to check if zero-inflation is present in the fitted model.

```{r}
model <- glm(count ~ spp + mined, family = poisson, data = Salamanders)
check_zeroinflation(model)
```

#### Check for singular model fits

A "singular" model fit means that some dimensions of the variance-covariance
matrix have been estimated as exactly zero. This often occurs for mixed models
with overly complex random effects structures.

`check_singularity()` checks mixed models (of class `lme`, `merMod`, `glmmTMB`
or `MixMod`) for singularity, and returns `TRUE` if the model fit is singular.

```{r}
library(lme4)
data(sleepstudy)

# prepare data
set.seed(123)
sleepstudy$mygrp <- sample(1:5, size = 180, replace = TRUE)
sleepstudy$mysubgrp <- NA
for (i in 1:5) {
  filter_group <- sleepstudy$mygrp == i
  sleepstudy$mysubgrp[filter_group] <-
    sample(1:30, size = sum(filter_group), replace = TRUE)
}

# fit strange model
model <- lmer(
  Reaction ~ Days + (1 | mygrp / mysubgrp) + (1 | Subject),
  data = sleepstudy
)

check_singularity(model)
```

Remedies to cure issues with singular fits can be found [here](https://easystats.github.io/performance/reference/check_singularity.html).

#### Check for heteroskedasticity

Linear models assume constant error variance (homoskedasticity).

The `check_heteroscedasticity()` functions assess if this assumption has been
violated:

```{r}
data(cars)
model <- lm(dist ~ speed, data = cars)

check_heteroscedasticity(model)
```

#### Comprehensive visualization of model checks

**performance** provides many functions to check model assumptions, like
`check_collinearity()`, `check_normality()` or `check_heteroscedasticity()`. To
get a comprehensive check, use `check_model()`.

```{r, fig.height=12, fig.width=10, out.width="80%"}
# defining a model
model <- lm(mpg ~ wt + am + gear + vs * cyl, data = mtcars)

# checking model assumptions
check_model(model)
```

### Model performance summaries

`model_performance()` computes indices of model performance for regression
models. Depending on the model object, typical indices might be r-squared, AIC,
BIC, RMSE, ICC or LOOIC.

#### Linear model

```{r}
m1 <- lm(mpg ~ wt + cyl, data = mtcars)
model_performance(m1)
```

#### Logistic regression

```{r}
m2 <- glm(vs ~ wt + mpg, data = mtcars, family = "binomial")
model_performance(m2)
```

#### Linear mixed model

```{r}
library(lme4)
m3 <- lmer(Reaction ~ Days + (1 + Days | Subject), data = sleepstudy)
model_performance(m3)
```

### Models comparison

The `compare_performance()` function can be used to compare the performance and
quality of several models (including models of different types).

```{r}
counts <- c(18, 17, 15, 20, 10, 20, 25, 13, 12)
outcome <- gl(3, 1, 9)
treatment <- gl(3, 3)
m4 <- glm(counts ~ outcome + treatment, family = poisson())

compare_performance(m1, m2, m3, m4, verbose = FALSE)
```

#### General index of model performance

One can also easily compute and a [**composite index**](https://easystats.github.io/performance/reference/compare_performance.html#details) of model performance and sort the models from the best one to the worse.

```{r}
compare_performance(m1, m2, m3, m4, rank = TRUE, verbose = FALSE)
```

#### Visualisation of indices of models' performance

Finally, we provide convenient visualisation (the `see` package must be
installed).

```{r}
plot(compare_performance(m1, m2, m4, rank = TRUE, verbose = FALSE))
```

### Testing models

`test_performance()` (and `test_bf`, its Bayesian sister) carries out the most
relevant and appropriate tests based on the input (for instance, whether the
models are nested or not).

```{r}
set.seed(123)
data(iris)

lm1 <- lm(Sepal.Length ~ Species, data = iris)
lm2 <- lm(Sepal.Length ~ Species + Petal.Length, data = iris)
lm3 <- lm(Sepal.Length ~ Species * Sepal.Width, data = iris)
lm4 <- lm(Sepal.Length ~ Species * Sepal.Width + Petal.Length + Petal.Width, data = iris)

test_performance(lm1, lm2, lm3, lm4)

test_bf(lm1, lm2, lm3, lm4)
```

### Plotting Functions

Plotting functions are available through the [**see** package](https://easystats.github.io/see/articles/performance.html).


# Code of Conduct

Please note that the performance project is released with a [Contributor Code of Conduct](https://easystats.github.io/performance/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms.


# Contributing

We are happy to receive bug reports, suggestions, questions, and (most of all)
contributions to fix problems and add features.

Please follow contributing guidelines mentioned here:



## References

Owner

  • Name: easystats
  • Login: easystats
  • Kind: organization
  • Location: worldwide

Make R stats easy!

JOSS Publication

performance: An R Package for Assessment, Comparison and Testing of Statistical Models
Published
April 21, 2021
Volume 6, Issue 60, Page 3139
Authors
Daniel Lüdecke ORCID
University Medical Center Hamburg-Eppendorf, Germany
Mattan S. Ben-Shachar ORCID
Ben-Gurion University of the Negev, Israel
Indrajeet Patil ORCID
Center for Humans and Machines, Max Planck Institute for Human Development, Berlin, Germany
Philip Waggoner ORCID
University of Chicago, USA
Dominique Makowski ORCID
Nanyang Technological University, Singapore
Editor
Mikkel Meyer Andersen ORCID
Tags
easystats parameters regression linear models coefficients

Papers & Mentions

Total mentions: 17

The minimal informative monitoring interval of N-terminal pro-B-type natriuretic peptide in patients with stable heart failure
Last synced: 3 months ago
Relationship between Speed of Response Inhibition and Ability to Suppress a Step in Midlife and Older Adults
Last synced: 3 months ago
Chimpanzees’ (<i>Pan troglodytes</i>) problem-solving skills are influenced by housing facility and captive care duration
Last synced: 3 months ago
Sexual dimorphism in the horn size of a pair-forming coral reef butterflyfish
Last synced: 3 months ago
Not by the light of the moon: Investigating circadian rhythms and environmental predictors of calling in Bornean great argus
Last synced: 3 months ago
Experimental warming influences species abundances in a Drosophila host community through direct effects on species performance rather than altered competition and parasitism
Last synced: 3 months ago
Online biology degree program broadens access for women, first-generation to college, and low-income students, but grade disparities remain
Last synced: 3 months ago
Predictors for Perioperative Blood Transfusion in Patients Undergoing Open Cystectomy and Urinary Diversion and Development of a Nomogram: An Observational Cohort Study
Last synced: 3 months ago
Reproductive performance in houbara bustard is affected by the combined effects of age, inbreeding and number of generations in captivity
Last synced: 3 months ago
Health and Mental Health Disparities Between National Identity Groups in Wales
Last synced: 3 months ago
A Randomized Controlled Trial Evaluating the FIT Game’s Efficacy in Increasing Fruit and Vegetable Consumption
Last synced: 3 months ago
Hierarchical modelling of immunoglobulin coated bacteria in dogs with chronic enteropathy shows reduction in coating with disease remission but marked inter-individual and treatment-response variability
Last synced: 3 months ago
Bimodal activity of diurnal flower visitation at high elevation
Last synced: 3 months ago
Roadsides provide refuge for orchids: characteristic of the surrounding landscape
Last synced: 3 months ago
Metabolic Rates Predict Baseline Corticosterone and Reproductive Output in a Free-Living Passerine
Last synced: 3 months ago
Selection on vocal output affects laryngeal morphology in rats
Last synced: 3 months ago
Food Liking but Not Wanting Decreases after Controlled Intermittent or Continuous Energy Restriction to ≥5% Weight Loss in Women with Overweight/Obesity
Last synced: 3 months ago

GitHub Events

Total
  • Create event: 44
  • Release event: 4
  • Issues event: 46
  • Watch event: 79
  • Delete event: 39
  • Issue comment event: 254
  • Push event: 354
  • Pull request review event: 40
  • Pull request review comment event: 67
  • Pull request event: 81
  • Fork event: 17
Last Year
  • Create event: 44
  • Release event: 4
  • Issues event: 46
  • Watch event: 80
  • Delete event: 39
  • Issue comment event: 254
  • Push event: 354
  • Pull request review event: 40
  • Pull request review comment event: 67
  • Pull request event: 81
  • Fork event: 17

Committers

Last synced: 8 months ago

All Time
  • Total Commits: 2,182
  • Total Committers: 19
  • Avg Commits per committer: 114.842
  • Development Distribution Score (DDS): 0.232
Past Year
  • Commits: 146
  • Committers: 7
  • Avg Commits per committer: 20.857
  • Development Distribution Score (DDS): 0.178
Top Committers
Name Email Commits
Daniel m****l@d****e 1,676
Indrajeet Patil p****e@g****m 184
Dominique Makowski d****9@g****m 143
mattansb 3****b 60
Brenton M. Wiernik b****k 41
Rémi Thériault 1****c 29
github-actions[bot] 4****] 12
Vincent Arel-Bundock v****k@u****a 9
Etienne Bacher 5****r 9
Philip Waggoner 3****r 7
RemPsyc R****c 3
Jeffrey Girard me@j****m 2
Daniel Riggins d****s@p****m 1
Elliot Gould e****o 1
Joseph Luchman j****n@g****m 1
Matthias Grenié m****e@e****r 1
Michał Krassowski 5****i 1
Mickaël Canouil 8****l 1
Pablo Bernabeu p****u@g****m 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 4 months ago

All Time
  • Total issues: 186
  • Total pull requests: 246
  • Average time to close issues: 5 months
  • Average time to close pull requests: 9 days
  • Total issue authors: 87
  • Total pull request authors: 13
  • Average comments per issue: 4.66
  • Average comments per pull request: 2.23
  • Merged pull requests: 212
  • Bot issues: 0
  • Bot pull requests: 30
Past Year
  • Issues: 30
  • Pull requests: 81
  • Average time to close issues: 7 days
  • Average time to close pull requests: 3 days
  • Issue authors: 20
  • Pull request authors: 8
  • Average comments per issue: 2.87
  • Average comments per pull request: 2.49
  • Merged pull requests: 67
  • Bot issues: 0
  • Bot pull requests: 16
Top Authors
Issue Authors
  • IndrajeetPatil (15)
  • mattansb (14)
  • strengejacke (14)
  • rempsyc (9)
  • bbolker (9)
  • DominiqueMakowski (8)
  • bwiernik (7)
  • jebyrnes (6)
  • roaldarbol (4)
  • nniiicc (3)
  • profandyfield (3)
  • dpmoriarity (3)
  • raffaem (3)
  • MarcRieraDominguez (3)
  • qdread (2)
Pull Request Authors
  • strengejacke (196)
  • github-actions[bot] (33)
  • rempsyc (20)
  • DominiqueMakowski (9)
  • etiennebacher (8)
  • bwiernik (3)
  • jimrothstein (3)
  • IndrajeetPatil (2)
  • mattansb (2)
  • egouldo (1)
  • vincentarelbundock (1)
  • jluchman (1)
  • jmgirard (1)
  • mcanouil (1)
Top Labels
Issue Labels
3 investigators :grey_question::question: (32) enhancement :boom: (20) bug :bug: (16) docs :books: (11) reprex :bar_chart: (9) Enhancement :boom: (7) waiting for response :love_letter: (7) Bug :bug: (6) feature idea :fire: (5) invalid :x: (3) consistency :green_apple: :apple: (2) low priority :sleeping: (2) Feature idea :fire: (2) high priority :runner: (2) question :interrobang: (2) Reprex :bar_chart: (1) Waiting for response :love_letter: (1) beginner-friendly :handshake: (1) help us :eyes: (1) dissemination :tv: (1) breaking 🏴‍☠️ (1) refactor :recycle: (1)
Pull Request Labels
Auto-update (23) auto-update (10) bug :bug: (2) hacktoberfest 💻 (2) docs :books: (1)

Packages

  • Total packages: 3
  • Total downloads:
    • cran 81,980 last-month
  • Total docker downloads: 48,356
  • Total dependent packages: 42
    (may contain duplicates)
  • Total dependent repositories: 72
    (may contain duplicates)
  • Total versions: 83
  • Total maintainers: 1
cran.r-project.org: performance

Assessment of Regression Models Performance

  • Versions: 42
  • Dependent Packages: 34
  • Dependent Repositories: 71
  • Downloads: 81,980 Last month
  • Docker Downloads: 48,356
Rankings
Stargazers count: 0.3%
Forks count: 0.7%
Downloads: 1.6%
Dependent packages count: 2.3%
Dependent repos count: 2.8%
Average: 5.1%
Docker downloads count: 23.1%
Maintainers (1)
Last synced: 4 months ago
proxy.golang.org: github.com/easystats/performance
  • Versions: 17
  • Dependent Packages: 0
  • Dependent Repositories: 0
Rankings
Dependent packages count: 5.5%
Average: 5.6%
Dependent repos count: 5.8%
Last synced: 4 months ago
conda-forge.org: r-performance
  • Versions: 24
  • Dependent Packages: 8
  • Dependent Repositories: 1
Rankings
Dependent packages count: 7.1%
Stargazers count: 13.8%
Average: 16.6%
Forks count: 21.3%
Dependent repos count: 24.4%
Last synced: 4 months ago

Dependencies

DESCRIPTION cran
  • R >= 3.6 depends
  • bayestestR >= 0.13.0 imports
  • datawizard >= 0.6.5 imports
  • insight >= 0.18.8 imports
  • methods * imports
  • stats * imports
  • utils * imports
  • AER * suggests
  • BayesFactor * suggests
  • CompQuadForm * suggests
  • Hmisc * suggests
  • ICS * suggests
  • ICSOutlier * suggests
  • ISLR * suggests
  • MASS * suggests
  • Matrix * suggests
  • VGAM * suggests
  • afex * suggests
  • bayesplot * suggests
  • betareg * suggests
  • bigutilsr * suggests
  • blavaan * suggests
  • boot * suggests
  • brms * suggests
  • car * suggests
  • correlation * suggests
  • cplm * suggests
  • dbscan * suggests
  • estimatr * suggests
  • fixest * suggests
  • forecast * suggests
  • gamm4 * suggests
  • ggplot2 * suggests
  • glmmTMB * suggests
  • graphics * suggests
  • httr * suggests
  • lavaan * suggests
  • lme4 * suggests
  • lmtest * suggests
  • loo * suggests
  • mclust * suggests
  • metafor * suggests
  • mgcv * suggests
  • mlogit * suggests
  • multimode * suggests
  • nlme * suggests
  • nonnest2 * suggests
  • ordinal * suggests
  • parallel * suggests
  • parameters * suggests
  • patchwork * suggests
  • poorman * suggests
  • pscl * suggests
  • psych * suggests
  • randomForest * suggests
  • rmarkdown * suggests
  • rstanarm * suggests
  • rstantools * suggests
  • sandwich * suggests
  • see >= 0.7.4 suggests
  • survey * suggests
  • survival * suggests
  • testthat * suggests
  • tweedie * suggests