Skip to content

Commit

Permalink
Errors in using r2_kullback
Browse files Browse the repository at this point in the history
Fixes #667
  • Loading branch information
strengejacke committed Feb 16, 2024
1 parent 41d60d0 commit 3985394
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 3 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.8.15
Version: 0.10.8.16
Authors@R:
c(person(given = "Daniel",
family = "Lüdecke",
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,8 @@ S3method(r2_coxsnell,survreg)
S3method(r2_coxsnell,svycoxph)
S3method(r2_coxsnell,truncreg)
S3method(r2_efron,default)
S3method(r2_kullback,default)
S3method(r2_kullback,glm)
S3method(r2_loo_posterior,BFBayesFactor)
S3method(r2_loo_posterior,brmsfit)
S3method(r2_loo_posterior,stanmvreg)
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
`check_collinearity()` and `check_outliers()` for models with non-numeric
response variables.

* `r2_kullback()` now gives an informative error for non-supported models.

## Bug fixes

* Fixed issue in `binned_residuals()` for models with binary outcome, where
Expand Down
14 changes: 13 additions & 1 deletion R/r2_kl.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#' @param model A generalized linear model.
#' @param adjust Logical, if `TRUE` (the default), the adjusted R2 value is
#' returned.
#' @param ... Additional arguments. Currently not used.
#'
#' @return A named vector with the R2 value.
#'
Expand All @@ -19,7 +20,13 @@
#' 77: 329-342.
#'
#' @export
r2_kullback <- function(model, adjust = TRUE) {
r2_kullback <- function(model, ...) {
UseMethod("r2_kullback")
}

#' @rdname r2_kullback
#' @export
r2_kullback.glm <- function(model, adjust = TRUE, ...) {
if (adjust) {
adj <- model$df.null / model$df.residual
} else {
Expand All @@ -31,3 +38,8 @@ r2_kullback <- function(model, adjust = TRUE) {
names(klr2) <- "Kullback-Leibler R2"
klr2
}

#' @export
r2_kullback.default <- function(model, ...) {
insight::format_error("This function only works for objects of class `glm`.")
}
7 changes: 6 additions & 1 deletion man/r2_kullback.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3985394

Please sign in to comment.