From 65319a145f12fc76e4f3bffb5f699ec21ba3bccd Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Thu, 29 Sep 2022 08:37:25 +0200 Subject: More adaptations to deal with failed saem fits --- R/mhmkin.R | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/R/mhmkin.R b/R/mhmkin.R index 17c8a1f7..15c92f3c 100644 --- a/R/mhmkin.R +++ b/R/mhmkin.R @@ -168,8 +168,11 @@ print.convergence.mhmkin <- function(x, ...) { #' @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 (inherits(x, "try-error")) return(NA) + if (check_failed(x)) return(NA) else return(AIC(x$so, k = k)) }) dim(res) <- dim(object) @@ -179,8 +182,11 @@ 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 (inherits(x, "try-error")) return(NA) + if (check_failed(x)) return(NA) else return(BIC(x$so)) }) dim(res) <- dim(object) -- cgit v1.2.1