From 273efa0704130ff594d8b780e67827acc537b25a Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Tue, 18 Oct 2022 17:27:05 +0200 Subject: Don't fail if one of the Hessians can't be computed --- R/mkinfit.R | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'R') diff --git a/R/mkinfit.R b/R/mkinfit.R index 1c2f8b5e..693778fd 100644 --- a/R/mkinfit.R +++ b/R/mkinfit.R @@ -844,8 +844,13 @@ mkinfit <- function(mkinmod, observed, } } + dim_hessian <- length(c(degparms, errparms)) + fit$hessian <- try(numDeriv::hessian(cost_function, c(degparms, errparms), OLS = FALSE, update_data = FALSE), silent = TRUE) + if (inherits(fit$hessian, "try-error")) { + fit$hessian <- matrix(NA, nrow = dim_hessian, ncol = dim_hessian) + } dimnames(fit$hessian) <- list(names(c(degparms, errparms)), names(c(degparms, errparms))) @@ -858,7 +863,9 @@ mkinfit <- function(mkinmod, observed, fit$hessian_notrans <- try(numDeriv::hessian(cost_function, c(bparms.optim, errparms), OLS = FALSE, trans = FALSE, update_data = FALSE), silent = TRUE) - + if (inherits(fit$hessian_notrans, "try-error")) { + fit$hessian_notrans <- matrix(NA, nrow = dim_hessian, ncol = dim_hessian) + } dimnames(fit$hessian_notrans) <- list(names(c(bparms.optim, errparms)), names(c(bparms.optim, errparms))) }) -- cgit v1.2.1