Skip to content

Commit

Permalink
fixes #280 - matrix type for observedResponse
Browse files Browse the repository at this point in the history
Changing getObservedResponse.default() to deal with matrix-type observed responses that are probably (or mostly) due to scaling the response variable (scale(y)).
  • Loading branch information
melina-leite committed Sep 17, 2024
1 parent b41ae74 commit 610b12b
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions DHARMa/R/compatibility.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 610b12b

Please sign in to comment.