Skip to contents

Function that uses the rstan::sampling() engine to generate nowcasts.

Usage

nowcast(
  .disease_data,
  true_date,
  report_date,
  strata = NULL,
  temporal_effects_delay = "auto",
  temporal_effects_epidemic = "auto",
  has_cycle = FALSE,
  autoregresive = AR(),
  moving_average = MA(),
  dist = c("NegativeBinomial", "Poisson", "Normal", "Student"),
  link_x = default_x_link(dist),
  link_y = default_y_link(dist),
  now = NULL,
  units = NULL,
  max_delay = Inf,
  prior_only = FALSE,
  proportion_reported = 1,
  normalize_data = (dist[1] %in% c("Normal", "Student")),
  refresh = 250 * rlang::is_interactive(),
  control = control_default(),
  method = c("sampling", "variational", "optimization"),
  priors = set_priors(),
  ...
)

Arguments

.disease_data

A time series of reporting data in aggregated line list format such that each row has a column for onset date, report date, and (optionally) strata

true_date

In quotations, the name of the column of datatype Date designating the date of case onset. e.g. "onset_week"

report_date

In quotations, the name of the column of datatype Date designating the date of case report. e.g. "report_week"

strata

Character vector of names of the strata included in the data.

temporal_effects_delay

Either "auto" or a temporal_effects() object specifying which effects have an influence on the delay.

temporal_effects_epidemic

Either "auto" or a temporal_effects() object specifying which effects have an influence on the epidemic process (delay independent).

has_cycle

Boolean. Whether include a cycle component in the model.

autoregresive

An AR() object with the autoregresive components for the epidemic and delay processes.

moving_average

A MA() object with the moving average component for the epidemic and delay processes.

dist

Distribution. Either "NegativeBinomial", "Poisson", "Normal", or "Student"

Link function for the epidemic process (see section On links).

Link function for the data (see section On links).

now

An object of datatype Date indicating the date at which to perlform the nowcast.

units

Time scale of reporting. Options: "1 day", "1 week".

max_delay

Maximum possible delay observed or considered for estimation of the delay distribution (numeric). Default: Inf

prior_only

Boolean variable indicating whether to compute only the prior distribution

proportion_reported

A decimal greater than 0 and less than or equal to 1 representing the proportion of all cases expected to be reported. Default: 1, e.g. 100 percent of all cases will eventually be reported. For asymptomatic diseases where not all cases will ever be reported, or for outbreaks in which severe under-reporting is expected, change this to less than 1.

normalize_data

Whether the data y should be normalized (substracted its mean and divided by standard deviation) for fitting. This option is only valid if using a continuous model (Normal or Student).

refresh

Refresh parameter for rstan::sampling()

control

Control parameter for rstan::sampling()

method

Fitting method either sampling (recommended for inference), variational (recommended for testing) or optimization. The sampling method calls rstan::sampling() while the variational calls rstan::vb() and optimization calls rstan::optimizing()

priors

A list of all of the nowcast priors. You can use set_priors() to change the priors of the function (see details)

...

Additional arguments to pass to rstan::sampling()

Examples

# Load the data
data(denguedat)

# Run a nowcast with very few iterations
# change to method = "sampling" when working and remove the iter = 10 (or set to iter = 2000)
now <- as.Date("1990-10-01")
nowcast(denguedat, "onset_week", "report_week", now = now,
  method = "optimization", seed = 2495624, iter = 10)
#> 
#> ── Nowcast for 1990-10-01 ──
#> 
#> • Column with `true_date` = "onset_week"
#> • Column with `report_date` = "report_week"
#> • units = "weeks"
#> 
#> ── Epidemic effects: 
#> The following effects are in place:
#>week_of_year
#> 
#> ── Delay effects: 
#> No temporal effects are considered
#> 
#> Use the `summary` function to obtain the summary of predictions or `plot` to
#> generate an image
#>