From 610b12bea6540af3da0974df5d4232f90eca40e7 Mon Sep 17 00:00:00 2001 From: melina-leite Date: Tue, 17 Sep 2024 18:01:45 +0200 Subject: [PATCH] fixes #280 - matrix type for observedResponse Changing getObservedResponse.default() to deal with matrix-type observed responses that are probably (or mostly) due to scaling the response variable (scale(y)). --- DHARMa/R/compatibility.R | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/DHARMa/R/compatibility.R b/DHARMa/R/compatibility.R index 861e7d37..247dd5d9 100644 --- a/DHARMa/R/compatibility.R +++ b/DHARMa/R/compatibility.R @@ -246,12 +246,16 @@ getObservedResponse.default <- function (object, ...){ out = out * x$`(weights)` } - # check for k/n binomial if(is.matrix(out)){ - if(!(ncol(out) == 2)) securityAssertion("nKcase - wrong dimensions of response") - if(!(family(object)$family %in% c("binomial", "betabinomial"))) securityAssertion("nKcase - wrong family") - - out = out[,1] + # case scaled variables or something like that + if(ncol(out) == 1){ + out = as.vector(out) + } else if(ncol(out) == 2) { + # case k/n binomial + if(!(family(object)$family %in% c("binomial", "betabinomial"))) securityAssertion("nKcase - wrong family") + out = out[,1] + } + else securityAssertion("Response in the model is a matrix with > 2 dim") } return(out) }