covid19br / nowcaster

Repository to the R package nowcaster, nowcasting with INLA
https://covid19br.github.io/nowcaster
GNU General Public License v3.0
18 stars 5 forks source link

Implement Hessian testing #33

Open rafalopespx opened 2 years ago

rafalopespx commented 2 years ago

Hessian test is constructed to avoid problems when the INLA solver stack in negative eigenvalues, to avoid it we can work on the length iteration steps. The test can be implemented through a while test until it reach a certain amount of tries. Follows a schematic test to be put on the nowcasting_age and nowcasting_no_age functions:

hess.min <- -1
h.value <- 0.01
h.trials <- 0.001
trials <- 0
while (hess.min <= 0 & trials < 50){

    # Running the Negative Binomial model in INLA
    output0 <- inla(model, family = "nbinomial", data = dados.age,
                    control.predictor = list(link = 1, compute = T),
                    control.compute = list(config = T, waic=F, dic=F, openmp.strategy='huge'),
                    control.family = list(
                      hyper = list("theta" = list(prior = "loggamma", 
                                                  param = c(0.001, 0.001))
                      )
                    ),
                    num.threads = 6,
                    control.inla = list(h = h.value),
                    ...

    )
    hess.start <- which(output0$logfile == 'Eigenvalues of the Hessian')
    hess.min <- min(as.numeric(output0$logfile[(hess.start+1):(hess.start+3)]))
    h.value <- h.trials + 0.001
    h.trials <- h.value
    trials <- trials + 1

  }
rafalopespx commented 2 years ago

Input the hessian test as a parameter on the nowcasting_inla that parse to nowcasting_age and nowcasting_no_age