From 4aa22dd976b0868a75e2bd5aed3bdfa839289174 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 17 Nov 2022 08:10:28 +0100 Subject: [PATCH] #515 --- DESCRIPTION | 2 +- NEWS.md | 2 ++ R/icc.R | 2 +- R/model_performance.bayesian.R | 18 +++++++++++------- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index b112141d4..571821e17 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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", diff --git a/NEWS.md b/NEWS.md index c37356f64..96e1b9b3d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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. diff --git a/R/icc.R b/R/icc.R index 7aefb0eb3..785f92e86 100644 --- a/R/icc.R +++ b/R/icc.R @@ -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) } diff --git a/R/model_performance.bayesian.R b/R/model_performance.bayesian.R index 4dd38cbb4..7a3d74a4c 100644 --- a/R/model_performance.bayesian.R +++ b/R/model_performance.bayesian.R @@ -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 @@ -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 @@ -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)