covid19br / nowcaster

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

Bug on forecasting K steps ahead #44

Closed lsbastos closed 6 months ago

lsbastos commented 8 months ago

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()