diff options
author | Johannes Ranke <jranke@uni-bremen.de> | 2022-10-18 17:27:05 +0200 |
---|---|---|
committer | Johannes Ranke <jranke@uni-bremen.de> | 2022-10-18 17:27:05 +0200 |
commit | 273efa0704130ff594d8b780e67827acc537b25a (patch) | |
tree | cd09ef7c33558500a506721f88f6dc8e7a24aa76 | |
parent | 73e12103447295d3d9110249b30edb222aed99fe (diff) |
Don't fail if one of the Hessians can't be computed
-rw-r--r-- | R/mkinfit.R | 9 |
1 files changed, 8 insertions, 1 deletions
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))) }) |