From bfc8f8ff285983ec57c86741f9780c010f9e564f Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 29 Oct 2023 09:40:43 +0100 Subject: [PATCH] posterior predictive check for binomial glm with matrix response Fixes #644 --- DESCRIPTION | 2 +- NEWS.md | 13 +++++++++++++ R/check_predictions.R | 4 ++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index d8dff46a6..026a700bb 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: performance Title: Assessment of Regression Models Performance -Version: 0.10.7.1 +Version: 0.10.7.2 Authors@R: c(person(given = "Daniel", family = "Lüdecke", diff --git a/NEWS.md b/NEWS.md index 2bb37d162..5c6691a17 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,16 @@ +# performance 0.10.8 + +## Changes + +* Changed behaviour of `check_predictions()` for models from binomial family, + to get comparable plots for different ways of outcome specification. Now, + if the outcome is a proportion, or defined as matrix of trials and successes, + the produced plots are the same (because the models should be the same, too). + +## Bug fixes + +* Fixed CRAN check erros. + # performance 0.10.7 ## Breaking changes diff --git a/R/check_predictions.R b/R/check_predictions.R index 832f9cc87..121bb27ba 100644 --- a/R/check_predictions.R +++ b/R/check_predictions.R @@ -263,7 +263,7 @@ pp_check.glm <- function(object, out <- tryCatch( { matrix_sim <- stats::simulate(object, nsim = iterations, re.form = re_formula, ...) - as.data.frame(sapply(matrix_sim, function(i) i[, 1] / i[, 2], simplify = TRUE)) + as.data.frame(sapply(matrix_sim, function(i) i[, 1] / rowSums(i, na.rm = TRUE), simplify = TRUE)) }, error = function(e) { NULL @@ -285,7 +285,7 @@ pp_check.glm <- function(object, ) resp_string <- insight::find_terms(object)$response - out$y <- response[, 1] / response[, 2] + out$y <- response[, 1] / rowSums(response, na.rm = TRUE) # safe information about model if (!is.null(model_info)) {