| Title: | Statistical Models for Notification Delay Correction of Epidemiological Data |
|---|---|
| Description: | Statistical models for correcting notification delays of epidemiological data. The package wraps statistical models to estimate not yet reported data using empirical delay distribution either from individual-level data or from the differences of aggregated time series of cases. For more details see Bastos et al. (2019) <doi:10.1002/sim.8303>. |
| Authors: | Rafael Lopes [aut] (ORCID: <https://orcid.org/0000-0002-9416-6145>), Tatiana Portella [aut] (ORCID: <https://orcid.org/0000-0001-8364-1978>), Theo Economou [aut] (ORCID: <https://orcid.org/0000-0001-8697-1518>), Marcelo Gomes [aut] (ORCID: <https://orcid.org/0000-0003-4693-5402>), Leo Bastos [aut, cre] (ORCID: <https://orcid.org/0000-0002-1406-0122>) |
| Maintainer: | Leo Bastos <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 1.0.1 |
| Built: | 2026-09-18 19:51:13 UTC |
| Source: | https://github.com/covid19br/nowcaster |
Function to put the data into the format proper to the nowcasting estimation, has to use the maximum of data present on the last week parsed to the estimation. Makes the account of maximum days per week to be used.
data.w( dataset, trim.data, bins_age = c("SI-PNI", "10 years", "5 years", bins_age), date_onset, date_report, age_col, use.epiweek = FALSE, K = 0, silent = FALSE )data.w( dataset, trim.data, bins_age = c("SI-PNI", "10 years", "5 years", bins_age), date_onset, date_report, age_col, use.epiweek = FALSE, K = 0, silent = FALSE )
dataset |
dataset to be formatted as data by week |
trim.data |
How much to trim of the data? |
bins_age |
Bins of age to cu the data, parsing from nowcasting_inla |
date_onset |
Column of dates of onset of the events, normally date of onset of first symptoms of cases |
date_report |
Column of dates of report of the event, normally date of digitation of the notification of cases |
age_col |
Age column to be where to cut the data into age classes |
use.epiweek |
If TRUE, it uses the CDC epiweek definition where the week starts on Sunday, if FALSE it the week ends at the weekday of the last record date. |
K |
How much weeks to forecast ahead? The default for K is 0, no forecasting ahead |
silent |
Deprecated. To be removed. |
Data in weeks format, with the maximum dates for the last week used
Function to put the data into the format proper to the nowcasting estimation, has to use the maximum of data present on the last week parsed to the estimation. Makes the account of maximum days per week to be used. With no age structure.
data.w_no_age( dataset, trim.data, date_onset, date_report, use.epiweek = FALSE, K = 0, silent = FALSE )data.w_no_age( dataset, trim.data, date_onset, date_report, use.epiweek = FALSE, K = 0, silent = FALSE )
dataset |
dataset to be formatted as data by week |
trim.data |
How much to trim of the data? |
date_onset |
Column of dates of onset of the events, normally date of onset of first symptoms of cases |
date_report |
Column of dates of report of the event, normally date of digitation of the notification of cases |
use.epiweek |
If TRUE, it uses the CDC epiweek definition where the week starts on Sunday, if FALSE it the week ends at the weekday of the last record date. |
K |
How much weeks to forecast ahead? Default K is 0, no forecasting ahead |
silent |
DEPRECATED to be removed. |
Data in weeks format, with the maximum dates for the last week used
Run INLA model on structured data by age-class data has to be in the format of delay-triangle
nowcasting_age( dataset, zero_inflated = FALSE, timeREmodel = "rw2", INLAoutput = FALSE, INLAoutputOnly = FALSE, WAIC = FALSE, DIC = FALSE )nowcasting_age( dataset, zero_inflated = FALSE, timeREmodel = "rw2", INLAoutput = FALSE, INLAoutputOnly = FALSE, WAIC = FALSE, DIC = FALSE )
dataset |
data pre formatted in to age classes and delays by week for each cases, delay triangle format |
zero_inflated |
Experimental! It deals with zero-inflated data by using a zeroinflatednbinomial2 model. |
timeREmodel |
Latent model for time random effects. The default is a second-order random walk model. |
INLAoutput |
return the INLA output. Default is FALSE. |
INLAoutputOnly |
return the only the INLA output. Default is FALSE. |
WAIC |
return the WAIC. Default is FALSE. |
DIC |
return the DIC. Default is FALSE. |
Trajectories from the inner 'INLA' model
Run INLA model on structured data by age-class data has to be in the format of delay-triangle
nowcasting_age_mgcv(dataset, method = "fs")nowcasting_age_mgcv(dataset, method = "fs")
dataset |
data pre formatted in to age classes and delays by week for each cases, delay triangle format |
method |
method used grouped gam, "by" where the smooth function will be s(., by= agegroup) or "fs" (factor smooth) where the smooth function uses s(., age_group, ,bs="fs") |
Trajectories from the inner 'INLA' model
function to estimate amount of events already started by not yet notified. The main use is to estimate how many cases in a outbreak has already started their onset date of symptons but has not yet notified. nowcasting_inla, fits a statistical distribution to the empirical distribution of time of delay between onset date and report date.
nowcasting_inla( dataset, bins_age = "SI-PNI", trim.data = 0, Dmax = 15, wdw = 30, use.epiweek = TRUE, age_col, date_onset, date_report, data.by.week = FALSE, return.age = NULL, silent = FALSE, K = 0, trajectories = FALSE, zero_inflated = FALSE, timeREmodel = "rw2", INLAoutput = FALSE, INLAoutputOnly = FALSE, WAIC = FALSE, DIC = FALSE, ... )nowcasting_inla( dataset, bins_age = "SI-PNI", trim.data = 0, Dmax = 15, wdw = 30, use.epiweek = TRUE, age_col, date_onset, date_report, data.by.week = FALSE, return.age = NULL, silent = FALSE, K = 0, trajectories = FALSE, zero_inflated = FALSE, timeREmodel = "rw2", INLAoutput = FALSE, INLAoutputOnly = FALSE, WAIC = FALSE, DIC = FALSE, ... )
dataset |
Dataset with at least 2 columns, date of onset, date of report. It can be a dataset with 3 columns, two dates columns as before said and a another one being an stratum column, in which data will stratified, usually being age. |
bins_age |
Age bins to do the nowcasting, it receive a vector of age bins, or options between, "SI-PNI", "10 years", "5 years". The default is "SI-PNI". |
trim.data |
(in weeks) Date to be trimmed out from the data base, in days. Default is 0 days. |
Dmax |
(in weeks) Window of dates the estimation will act, i.e., till how many past weeks the nowcasting will estimate. Default is 15 weeks. |
wdw |
(in weeks) Until which maximum amount of weeks the Nowcasting will use to the estimation. Default is 30 weeks. |
use.epiweek |
If TRUE, it uses the CDC epiweek definition where the week starts on Sunday, if FALSE it the week ends at the weekday of the last record date. Default is TRUE |
age_col |
Column for ages |
date_onset |
Column of dates of onset of the events, normally date of onset of first symptoms of cases |
date_report |
Column of dates of report of the event, normally date of digitation of the notification of cases |
data.by.week |
If it has to be returned the whole time-series data. Default is FALSE. |
return.age |
Deprecated. If the estimate by Age should be returned. Default is TRUE. |
silent |
Deprecated. Should be the warnings turned off? . The default is FALSE |
K |
(in weeks) How much weeks to forecast ahead? . The default is K = 0, no forecasting ahead |
trajectories |
Returns the trajectories estimated from the inner 'INLA' model . The default is FALSE. |
zero_inflated |
Experimental! In non-structured models, fit a model that deals with zero-inflated data. The default is FALSE. If the age_col is not missing this flag is ignored. |
timeREmodel |
Latent model for time random effects. . The default is a second-order random walk model. |
INLAoutput |
return the INLA output. Default is FALSE. |
INLAoutputOnly |
return the only the INLA output. Default is FALSE. |
WAIC |
return the WAIC. The default is FALSE. |
DIC |
return the DIC.The default is FALSE. |
... |
list parameters to other functions |
a list of 2 elements, each element with a data.frame with nowcasting estimation, 'Total', 'data' with the time-series out of wdw . If 'age_col' is parsed, add a third element with by age estimation 'age' . If 'trajectories' = TRUE, add a forth element with the returned trajectories from 'inla'. If 'INLAoutput' = TRUE, the INLA output is returned as a list object named 'output'. If 'INLAoutputOnly' = TRUE, just the INLA output is returned in a list object named 'output'. If 'WAIC' = TRUE or 'DIC' = TRUE, then 'INLAoutput' is forced to be TRUE returning the INLA output and a list object named waic or dic are also returned.
## Not run: # Loading Belo Horizonte SARI dataset data(sragBH) output <- nowcasting_inla(dataset = sragBH, date_onset = DT_SIN_PRI, date_report = DT_DIGITA, silent = T) ## End(Not run)## Not run: # Loading Belo Horizonte SARI dataset data(sragBH) output <- nowcasting_inla(dataset = sragBH, date_onset = DT_SIN_PRI, date_report = DT_DIGITA, silent = T) ## End(Not run)
function to estimate amount of events already started by not yet notified. The main use is to estimate how many cases in a outbreak has already started their onset date of symptons but has not yet notified. nowcasting_mgcv, fits a statistical distribution to the empirical distribution of time of delay between onset date and report date.
nowcasting_mgcv( dataset, bins_age = "SI-PNI", trim.data = 0, Dmax = 15, wdw = 30, use.epiweek = TRUE, age_col, date_onset, date_report, data.by.week = FALSE, return.age = NULL, silent = FALSE, method.group.gam = "fs", K = 0, trajectories = FALSE, ... )nowcasting_mgcv( dataset, bins_age = "SI-PNI", trim.data = 0, Dmax = 15, wdw = 30, use.epiweek = TRUE, age_col, date_onset, date_report, data.by.week = FALSE, return.age = NULL, silent = FALSE, method.group.gam = "fs", K = 0, trajectories = FALSE, ... )
dataset |
Dataset with at least 2 columns, date of onset, date of report. It can be a dataset with 3 columns, two dates columns as before said and a another one being an stratum column, in which data will stratified, usually being age. |
bins_age |
Age bins to do the nowcasting, it receive a vector of age bins, or options between, "SI-PNI", "10 years", "5 years". The default is "SI-PNI". |
trim.data |
(in weeks) Date to be trimmed out from the data base, in days. Default is 0 days. |
Dmax |
(in weeks) Window of dates the estimation will act, i.e., till how many past weeks the nowcasting will estimate. Default is 15 weeks. |
wdw |
(in weeks) Until which maximum amount of weeks the Nowcasting will use to the estimation. Default is 30 weeks. |
use.epiweek |
If TRUE, it uses the CDC epiweek definition where the week starts on Sunday, if FALSE it the week ends at the weekday of the last record date. Default is TRUE |
age_col |
Column for ages |
date_onset |
Column of dates of onset of the events, normally date of onset of first symptoms of cases |
date_report |
Column of dates of report of the event, normally date of digitation of the notification of cases |
data.by.week |
If it has to be returned the whole time-series data. Default is FALSE. |
return.age |
Deprecated. If the estimate by Age should be returned. Default is TRUE. |
silent |
Deprecated. Should be the warnings turned off? . The default is FALSE |
method.group.gam |
Method for aggregated smooth function in gam. Default is "fs" factor smooth, another alternative is "by". |
K |
(in weeks) How much weeks to forecast ahead? . The default is K = 0, no forecasting ahead |
trajectories |
Returns the predictive trajectories. The default is FALSE. |
... |
list parameters to other functions |
a list of 2 elements, each element with a data.frame with nowcasting estimation, 'Total', 'data' with the time-series out of wdw . If 'age_col' is parsed, add a third element with by age estimation 'age' . If 'trajectories' = TRUE, add a forth element with the returned trajectories from 'inla'.
# Loading Belo Horizonte SARI dataset data(sragBH) output <- nowcasting_mgcv(dataset = sragBH, date_onset = DT_SIN_PRI, date_report = DT_DIGITA)# Loading Belo Horizonte SARI dataset data(sragBH) output <- nowcasting_mgcv(dataset = sragBH, date_onset = DT_SIN_PRI, date_report = DT_DIGITA)
Run INLA model on non-structured data, data has to be in the format of delay-triangle
nowcasting_no_age( dataset, zero_inflated = FALSE, timeREmodel = "rw2", INLAoutput = FALSE, INLAoutputOnly = FALSE, WAIC = FALSE, DIC = FALSE )nowcasting_no_age( dataset, zero_inflated = FALSE, timeREmodel = "rw2", INLAoutput = FALSE, INLAoutputOnly = FALSE, WAIC = FALSE, DIC = FALSE )
dataset |
data pre formatted in to age classes and delays by week for each cases, delay triangle format |
zero_inflated |
zero-inflated model. Default is FALSE. |
timeREmodel |
Latent model for time random effects. The default is a second-order random walk model. |
INLAoutput |
return the INLA output. Default is FALSE. |
INLAoutputOnly |
return the only the INLA output. Default is FALSE. |
WAIC |
return the WAIC. Default is FALSE. |
DIC |
return the DIC. Default is FALSE. |
Trajectories from the inner 'INLA' model
Run INLA model on non-structured data, data has to be in the format of delay-triangle
nowcasting_no_age_mgcv(dataset)nowcasting_no_age_mgcv(dataset)
dataset |
data pre formatted in to age classes and delays by week for each cases, delay triangle format |
Trajectories from the Negative Binomial GAM
Function to summarize the output from the posteriors generated from any of the of the workhorse functions, nowcasting_no_age and nowcasting_age
nowcasting.summary(trajectory, age = FALSE)nowcasting.summary(trajectory, age = FALSE)
trajectory |
Trajectories to be summarized, trajectory should have sample, Time, dt_event and Y columns. |
age |
Is by age data? Default FALSE, If its TRUE it will have columns for age class, fx_etaria e fx_etaria.num |
A list with 2 elements summarized and grouped by, with the 'Median', 'LS' upper limit, 95% CI 'LI' lower limit, 95% CI 'LSb' upper limit, 50% CI 'LIb' lower limit, 50% CI
Fits a linear model to trajectories returned from 'nowcasting_inla()' within a given window. The default is 3 weeks. If 'end.week' is missing uses the maximum date in 'trajectories'.
slope.estimate.quant(end.week, trajectories, window = 3)slope.estimate.quant(end.week, trajectories, window = 3)
end.week |
(in weeks) The end of the week wanted to the slope estimate. Default: max. date in 'trajectories'. |
trajectories |
Data.frame with the predicted or nowcasted estimate |
window |
(in weeks) Window of how much time will be used to calculate the slope estimate. The default is 3 weeks. |
The numerical value of the slope of the estimate
# Loading Belo Horizonte SARI dataset data(sragBH) now <- nowcasting_mgcv(dataset = sragBH, date_onset = DT_SIN_PRI, date_report = DT_DIGITA, trajectories = TRUE, silent = TRUE) slope.estimate.quant(trajectories = now$trajectories)# Loading Belo Horizonte SARI dataset data(sragBH) now <- nowcasting_mgcv(dataset = sragBH, date_onset = DT_SIN_PRI, date_report = DT_DIGITA, trajectories = TRUE, silent = TRUE) slope.estimate.quant(trajectories = now$trajectories)
An anonymized dataset containing cases of severe acute respiratory illness (SARI) from a Brazilian municipality, Belo Horizonte, with symptoms onset varying from 2019-12-29 to 2022-03-27.
sragBHsragBH
A data frame with 65404 rows and 7 variables:
Date of onset symptoms.
Date of recording.
Final classification of the case. (Not used for nowcasting)
Case evolution. (Not used for nowcasting)
IBGE municipality code. Belo Horizonte is 310620.
Age in years.
Age brackets.
...
https://opendatasus.saude.gov.br/