Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Nov 17, 2022
1 parent 64acd1e commit 4aa22dd
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: performance
Title: Assessment of Regression Models Performance
Version: 0.10.0.12
Version: 0.10.0.13
Authors@R:
c(person(given = "Daniel",
family = "Lüdecke",
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
* The model underlying `check_distribution()` was now also trained to detect
cauchy, half-cauchy and inverse-gamma distributions.

* `model_performance()` now allows to include the ICC for Bayesian models.

## Bug fixes

* `verbose` didn't work for `r2_bayes()` with `BFBayesFactor` objects.
Expand Down
2 changes: 1 addition & 1 deletion R/icc.R
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ icc <- function(model, by_group = FALSE, tolerance = 1e-05, ci = NULL, iteration
}

if (!insight::is_mixed_model(model)) {
warning("'model' has no random effects.", call. = FALSE)
warning("`model` has no random effects.", call. = FALSE)
return(NULL)
}

Expand Down
18 changes: 11 additions & 7 deletions R/model_performance.bayesian.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ model_performance.stanreg <- function(model, metrics = "all", verbose = TRUE, ..
metrics[tolower(metrics) == "log_loss"] <- "LOGLOSS"
}

all_metrics <- c("LOOIC", "WAIC", "R2", "R2_adjusted", "RMSE", "SIGMA", "LOGLOSS", "SCORE")
all_metrics <- c("LOOIC", "WAIC", "R2", "R2_adjusted", "ICC", "RMSE", "SIGMA", "LOGLOSS", "SCORE")

if (all(metrics == "all")) {
metrics <- all_metrics
Expand Down Expand Up @@ -150,12 +150,8 @@ model_performance.stanreg <- function(model, metrics = "all", verbose = TRUE, ..
# LOO-R2 ------------------
if (("R2_ADJUSTED" %in% metrics || "R2_LOO" %in% metrics) && mi$is_linear) {
r2_adj <- tryCatch(
{
suppressWarnings(r2_loo(model, verbose = verbose))
},
error = function(e) {
NULL
}
suppressWarnings(r2_loo(model, verbose = verbose)),
error = function(e) NULL
)
if (!is.null(r2_adj)) {
# save attributes
Expand All @@ -176,6 +172,14 @@ model_performance.stanreg <- function(model, metrics = "all", verbose = TRUE, ..
attri$r2_bayes <- attri_r2
}

# ICC ------------------
if ("ICC" %in% metrics) {
out$ICC <- tryCatch(
suppressWarnings(icc(model, verbose = verbose)),
error = function(e) NULL
)
}

# RMSE ------------------
if ("RMSE" %in% metrics && !mi$is_ordinal && !mi$is_multinomial && !mi$is_categorical) {
out$RMSE <- performance_rmse(model, verbose = verbose)
Expand Down

0 comments on commit 4aa22dd

Please sign in to comment.