aboutsummaryrefslogtreecommitdiff
path: root/R/mhmkin.R
diff options
context:
space:
mode:
authorJohannes Ranke <johannes.ranke@jrwb.de>2025-02-14 07:19:15 +0100
committerJohannes Ranke <johannes.ranke@jrwb.de>2025-02-14 07:19:15 +0100
commitb0f08271d1dae8ffaf57f557c27eba1314ece1d5 (patch)
tree98da899d455d6945849d6f4b4e98adfb98dc8b2b /R/mhmkin.R
parent7dc59c522d0639f6473463340e518e2e8074e364 (diff)
parent55d9c2331e468efd364472555dbfae84603a4f73 (diff)
Merge branch 'main' into dev
Diffstat (limited to 'R/mhmkin.R')
-rw-r--r--R/mhmkin.R28
1 files changed, 21 insertions, 7 deletions
diff --git a/R/mhmkin.R b/R/mhmkin.R
index 6265a59e..14a7ac29 100644
--- a/R/mhmkin.R
+++ b/R/mhmkin.R
@@ -219,11 +219,22 @@ print.mhmkin <- function(x, ...) {
print(status(x))
}
+#' Check if fit within an mhmkin object failed
+#' @param x The object to be checked
+check_failed <- function(x) {
+ if (inherits(x, "try-error")) {
+ return(TRUE)
+ } else {
+ if (inherits(x$so, "try-error")) {
+ return(TRUE)
+ } else {
+ return(FALSE)
+ }
+ }
+}
+
#' @export
AIC.mhmkin <- function(object, ..., k = 2) {
- if (inherits(object[[1]], "saem.mmkin")) {
- check_failed <- function(x) if (inherits(x$so, "try-error")) TRUE else FALSE
- }
res <- sapply(object, function(x) {
if (check_failed(x)) return(NA)
else return(AIC(x$so, k = k))
@@ -235,9 +246,6 @@ AIC.mhmkin <- function(object, ..., k = 2) {
#' @export
BIC.mhmkin <- function(object, ...) {
- if (inherits(object[[1]], "saem.mmkin")) {
- check_failed <- function(x) if (inherits(x$so, "try-error")) TRUE else FALSE
- }
res <- sapply(object, function(x) {
if (check_failed(x)) return(NA)
else return(BIC(x$so))
@@ -280,7 +288,13 @@ anova.mhmkin <- function(object, ...,
if (identical(model.names, "auto")) {
model.names <- outer(rownames(object), colnames(object), paste)
}
- rlang::inject(anova(!!!(object), method = method, test = test,
+ failed_index <- which(sapply(object, check_failed), arr.ind = TRUE)
+ if (length(failed_index > 0)) {
+ rlang::inject(anova(!!!(object[-failed_index]), method = method, test = test,
+ model.names = model.names[-failed_index]))
+ } else {
+ rlang::inject(anova(!!!(object), method = method, test = test,
model.names = model.names))
+ }
}

Contact - Imprint