agg_to_daily {ern}R Documentation

Infer daily counts from aggregates

Description

Infer daily counts from aggregates

Usage

agg_to_daily(cl.data, dist.gi, prm.daily, silent = FALSE)

Arguments

cl.data

Data frame. Must have variables:

  • date: calendar date of report

  • value: count of reported cases

dist.gi

List. Parameters for the generation interval distribution in the same format as returned by def_dist().

prm.daily

List. Parameters for daily report inference via MCMC. Elements include:

  • method: String. Method name to infer the daily incidence reports from aggregated ones. Either linear or renewal is currently implemented. The linear method simply performs a linear interpolation that matches the aggregated values. The renewal method fits a SIR-like model using a renewal equation to infer the daily incidence. In this case, the fitting algorithm is a Markov Chain Monte Carlo (MCMC) implemented in JAGS and needs the parameters below (e.g., burn,iter,chains,...). The renewal method is more adapted for short single wave epidemics as this models i) naturally fits a single wave and ii) has longer computing time. For longer time series, user may perfer the linear method.

  • popsize: Integer. Population size to use in MCMC simulation to infer daily observations from aggregated input data.

  • burn: Numeric. Length of burn-in period (number of days).

  • iter: Numeric. Number of iterations after burn-in period (number of days).

  • chains: Numeric. Number of chains to simulate.

  • prior_R0_shape: Shape of the (hyper-)parameter for the prior Gamma distribution for R0.

  • prior_R0_rate: Rate of the (hyper-)parameter for the prior Gamma distribution for R0.

  • prior_alpha_shape: Shape of the (hyper-)parameter for the prior Gamma distribution for alpha.

  • prior_alpha_rate: Rate of the (hyper-)parameter for the prior Gamma distribution for alpha.

  • first.agg.period: length of aggregation period for first aggregated observation (number of days); if NULL, assume same aggregation period as observed for second observation (gap between first and second observations)

silent

Logical. Flag to suppress all output messages, warnings, and progress bars.

Value

A list containing a data frame with individual realizations of daily reported cases and the JAGS object.

Examples


# Importing data attached to the `ern` package
# and selecting the Omicron wave in Ontario, Canada.
# This is *weekly* incidence.
data(cl.data)
data = cl.data[cl.data$pt == 'on' & 
                  cl.data$date > as.Date('2021-11-30') & 
                  cl.data$date < as.Date('2021-12-31'),] 
head(data)
dist.gi = ern::def_dist(
 dist     = "gamma",
 mean     = 6.84,
 mean_sd  = 0.7486,
 shape    = 2.39,
 shape_sd = 0.3573,
 max      = 15
)

a = agg_to_daily(
cl.data = data, 
dist.gi = dist.gi, 
  prm.daily = list(
  method = "renewal",
  popsize = 14e6,
  # MCMC parameters.
  # small values for computation speed for this example.
  # Increase for better accuracy
  burn = 100,
  iter = 100,
  chains = 2,
  # - - - - - 
  prior_R0_shape = 2,
  prior_R0_rate = 0.6,
  prior_alpha_shape = 1,
  prior_alpha_rate = 1
))
# This is a Bayesian inference, so we 
# have a posterior distribution of  
# daily incidences. Here we just plot
# one single draw:
      
 df = a$df
 df1 = df[df$id==1,]
 plot(x = df1$t, y = df1$value, typ = 'o',
      xlab = 'days', ylab = 'daily incidence',
      main = 'Posterior daily incidence infered from weekly incidence')
 
 # Extract of the parameters values from the first chain
 a$jags.object[[1]][1:9,1:9]
 

[Package ern version 2.0.0 Index]