performance icon indicating copy to clipboard operation
performance copied to clipboard

Argument for additional metrics in model_performance()

Open bwiernik opened this issue 3 years ago • 8 comments

I'd like to be able to request additional performance metrics in model_performance(), such as AICC or confidence intervals for R2 or sigma. It would be nice if, in addition to the metrics argument, there were an additional_metrics argument that could take a named list of additional functions to run, each of which should return a vector a results that would be added as additional columns to the performance data frame.

For example:

m <- lm(formula = mpg ~ wt + qsec + am, data = mtcars)
performance(m, metrics = "common", additional_metrics = list(`R2 CI` = confint_R2, AICC = performance_aicc))

Or perhaps it would be cleaner to just have the one metrics argument and allow it to be either the current string vector or a named list of functions:

m <- lm(formula = mpg ~ wt + qsec + am, data = mtcars)
performance(m, metrics = "list(R2 = r2, `R2 CI` = confint_R2, AICC = performance_aicc, Sigma = get_sigma))

bwiernik avatar Apr 03 '21 23:04 bwiernik

Or perhaps it would be cleaner to just have the one metrics argument and allow it to be either the current string vector or a named list of functions

I would prefer to have less arguments.

Regarding AICc, perhaps we should return it by default? Or even instead of the AIC, if that makes sense?

DominiqueMakowski avatar Apr 04 '21 01:04 DominiqueMakowski

I think retaining first order AIC makes sense given its ubiquity. I’d really like there to be an option to add R2 CIs and n_obs() to the performance table to facilitate reporting (especially when teaching), so an option to add additional functions to metrics would be great.

bwiernik avatar Apr 04 '21 04:04 bwiernik

You can already request AICc (https://easystats.github.io/performance/reference/model_performance.lm.html).

But we could indeed add the other ones, too.

strengejacke avatar Apr 04 '21 05:04 strengejacke

Ah I missed the casing "AICC” is ignored.

bwiernik avatar Apr 04 '21 05:04 bwiernik

Ah I missed the casing "AICC” is ignored.

That's indeed inconsistent, we should convert all input into upper or lower case inside the function, so case can mostly be ignored.

strengejacke avatar Apr 04 '21 05:04 strengejacke

I just checked, and should already work:

library(performance)
m <- lm(formula = mpg ~ wt + qsec + am, data = mtcars)
performance(m, metrics = c("R2", "AICc"))
#> # Indices of model performance
#> 
#> AICc    |    R2
#> ---------------
#> 156.427 | 0.850

performance(m, metrics = c("R2", "AICC"))
#> # Indices of model performance
#> 
#> AICc    |    R2
#> ---------------
#> 156.427 | 0.850

performance(m, metrics = c("R2", "r2_adj", "aicc"))
#> # Indices of model performance
#> 
#> AICc    |    R2 | R2 (adj.)
#> ---------------------------
#> 156.427 | 0.850 |     0.834

performance(m, metrics = c("R2", "r2_adj", "aicc", "AiC"))
#> # Indices of model performance
#> 
#> AIC     |    AICc |    R2 | R2 (adj.)
#> -------------------------------------
#> 154.119 | 156.427 | 0.850 |     0.834

Created on 2021-04-05 by the reprex package (v2.0.0)

Please re-open if you still find any issues!

strengejacke avatar Apr 05 '21 14:04 strengejacke

Re-opening to discuss the broader question of adding additional functions.

For example, let's say I'd like to add n_obs() to performance, output, something like this would be nice:

library(performance)
m <- lm(formula = mpg ~ wt + qsec + am, data = mtcars)
performance(m, metrics = list(R2 = r2, Sigma = insight::get_sigma, N = insight::n_obs))

Within the performance function, the type of metrics could be checked. If its "character", the current behavior is used; if it's "list", it is taken as a list of functions.

I can put together a PR if there is interest.

bwiernik avatar Apr 05 '21 15:04 bwiernik

Yeah, that sounds reasonable! Please open a PR, if you like. And we could indeed add n_obs() as further metric (N, nobs?) as well.

strengejacke avatar Apr 05 '21 15:04 strengejacke