Skip to content

Commit 6d9b61a

Browse files
committed
additional checks/catches for hessian
1 parent 448bd19 commit 6d9b61a

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

NEWS.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22

33
* Now returning the series name of the data in the spec object for use in
44
multivariate models.
5-
6-
* If the hessian cannot be calculated in the first step for the scaling, then
5+
* If the hessian cannot be calculated in the first or second step for the scaling, then
76
a numerical approximation is used instead. There seems to be some instability
87
in the egarch-nig model for some datasets.
98

R/estimate.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,10 @@ solve_model <- function(init_pars, env, const, lower, upper, control) {
188188
scaled_sol <- solve_model(init_pars = scaled_init_pars, env = scaled_env, const = scaled_const, lower = scaled_lower, upper = scaled_upper, control = control)
189189
scaled_sol$par_scale <- par_scale
190190
hessian <- scaled_tmb$he()
191+
if (any(is.na(hessian))) {
192+
warning("\nunable to calculate hessian for parameter scaling in scaling step. Reverting to numerical estimation.")
193+
hessian <- hessian(scaled_env$fun, x = scaled_sol$solution, env = scaled_env)
194+
}
191195
scores <- jacobian(score_function, scaled_sol$solution, env = scaled_env)
192196
m <- object$model_options[1]
193197
sig <- scaled_env$tmb$report(scaled_sol$solution)$sigma

man/tsgarch-package.Rd

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/TMB/distfun.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,8 @@ namespace distfun{
163163
Type fwd_kappagh(Type x, Type lambda)
164164
{
165165
Type kappa = Type(0.0);
166-
if(lambda == Type(-0.5)) {
167-
kappa = Type(1.0)/x;
168-
} else {
169-
Type tmp = lambda + Type(1.0);
170-
kappa = (fwd_scaled_besselK(x, tmp) /fwd_scaled_besselK(x, lambda)) / x;
171-
}
166+
Type tmp = lambda + Type(1.0);
167+
kappa = (fwd_scaled_besselK(x, tmp) /fwd_scaled_besselK(x, lambda)) / x;
172168
return kappa;
173169
}
174170
VECTORIZE2_tt(fwd_kappagh)

0 commit comments

Comments
 (0)