Code Monkey home page Code Monkey logo

nowcaster's Issues

Slope function to calculate the tendency of the curve

Through a simple linear model adjusted to the trajectories, we can infer the tendency of the epidemic curve, to do so we can construct functions that take the posteriors output from the main function nowcasting_inla and adjust the linear model and return the slope of the trajectories, to give a more quantitative tendency inference:

Bug on forecasting K steps ahead

There is a bug on the use of parameter K. When the last week is incomplete and K = 0 the last week to correct delay is the last complete week. But when K>0, it should forecast the current (and incomplete) week and the following K-1 weeks, but it seems to forecast K weeks beyond the current. As as example, when K=1, it should forecast the current (and incomplete) week but it forecasts two weeks ahead, the current one + 1.

data(sragBH)

sragBH20 <- sragBH %>% 
  filter(
    # Excluding typing date before symptoms onset
    DT_SIN_PRI <= DT_DIGITA, 
    # Excluding no typing date
    !is.na(DT_DIGITA),
    # cases reported in 2020
    year(DT_DIGITA) == 2020
  ) 

max(sragBH20$DT_DIGITA)
weekdays(max(sragBH20$DT_DIGITA))

epiweek(max(sragBH20$DT_DIGITA))
# Incomplete week (recording ends on Thursday)

# Nowcasting ignores an incomplete week (OK)
nowk0 = nowcasting_inla(dataset = sragBH20,
                        date_onset = DT_SIN_PRI,
                        date_report = DT_DIGITA,
                        silent = T)
nowk0$total %>% 
  mutate(
    epiweek = epiweek(dt_event)
  )  %>% tail()



# Week to forecast: week 53 only, but it forecast weeks 53/20 and 1/21
nowk1 = nowcasting_inla(dataset = sragBH20,
                        date_onset = DT_SIN_PRI,
                        date_report = DT_DIGITA,
                        K = 1,
                        silent = T)
nowk1$total %>% 
  mutate(
    epiweek = epiweek(dt_event)
  )  %>% tail()


# Weeks to forecast: week 53 and 1, but it forecast weeks 53/20, 1 and 2/21
nowk2 = nowcasting_inla(dataset = sragBH20,
                        date_onset = DT_SIN_PRI,
                        date_report = DT_DIGITA,
                        K = 2,
                        silent = T)
nowk2$total %>% 
  mutate(
    epiweek = epiweek(dt_event)
  ) %>% tail()

Need to verify the date formats

We need on this line to verify which are date formats, the actual problem it is the onset dates are moved to the last complete day of the week .

Maybe a solution:

turn back the dates to its original format, which it is the inverser of the formula in dados_w()

create `nowcasting_cluster()`

Create new internal functions for nowcasting with and without spatial structured data, nowcasting_spatial for spatialy structured data and the existing nowcasting_age & nowcasting_no_age for non-spatial structured data

  • nowcasting_spatial created and implemented
  • stable and tested for the README

Implement Hessian testing

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
    
  }

Silent and Return.age

  • Silent parameter is not working properly needs fixing
  • Return.age is obsolete, needs fixing

Trajectory parameter

Implement a trajectory flag on nowcasting_inla to give back the option trajectory devolution

INLA Requeriments warning

Require INLA with the NAMESPACE and Warning if it is not installed:

  • INLA load with the NAMESPACE
  • Warning if it is not installed

Review articles in the package site

To guarantee a well written documentation and understandable articles, we have to review the articles presented in the site of the package:

  • Get started!
  • Forecasting
  • Nowcasting for decision-making
  • Structured data

Nowcasting functions that accept any type of data

To build more cleaverly the package, without problems when calling nowcasting_inla(), create another functions that will by called by nowcasting_inla to make nowcasting without stratifying and make nowcasting with clustering specified data.

Tentative names, nowcasting_no_stratum() and nowcasting_cluster(), add the parameters to call those functions on nowcasting_inla(), these new functions will have a structure similar to nowcasting_age()

  • #6
  • #19
  • implement above functions on nowcasting_inla()
  • test stability of any kind of data passed to nowcasting_inla()

Change to new cran checks badge URL

๐Ÿ‘‹๐Ÿฝ I maintain the cran checks badges. Please change to the new cran checks badge URL (e.g., https://badges.cranchecks.info/worst/dplyr.svg). Old badges at (e.g. https://cranchecks.info/badges/worst/dplyr) will be unavailable as of Jan 1st 2023.

Forecasting article

Create an article performing a forecasting using the parameter K > 0

  • create a rmarkdown performing the forecasting
  • build article
  • build site

Imports

Stabilize the Imports for the package, now is import by the export specification on the NAMESPACE:

  • Verify Imports needed
  • NAMESPACE update
  • Warning to certify if INLA package is installed

Add observed number of cases into nowcaster outputs

Add a column with the observed number of cases in the nowcaster outputs.

> aaa$total
# A tibble: 15 ร— 7
    Time dt_event   Median    LI    LS   LIb   LSb
   <int> <date>      <dbl> <dbl> <dbl> <dbl> <dbl>
 1    17 2019-10-26    154  154   154    154  154 
 2    18 2019-11-02    173  173   173    173  173 

Last date to nowcast

Need to check the last date in the dataset and the last date in the nowcast estimates. It seems they don't match properly.

Covariate feature

Implement and test a model with covariate of tweets counts and google trends searches on the main function nowcasting_inla:

  • creates new shadow function nowcasting_covariates()
  • flag on the main function nowcasting_inla
  • all together

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.