sample_Rt: Sample piecewise-constant Rt values

View source: R/sampling.R

sample_RtR Documentation

Sample piecewise-constant Rt values

Description

If the renewal model is specified by a Poisson (the default):

cases_true_t ~ Poisson(Rt * \sum_tau=1^t_max w_t cases_true_t-tau)

If an Rt value is given a gamma prior, this results in a posterior distribution:

Rt ~ gamma(alpha + cases_true_t, beta + \sum_tau=1^t_max w_t cases_true_t-tau))

where alpha and beta are the shape and rate parameters of the gamma prior distribution. Here, we assume that Rt is constant over a set of onset times 'onset_time_set'. This means that the posterior for a single Rt value is given by:

Rt ~ gamma(alpha + \sum_{t in onset_time_set} cases_true_t, beta + \sum_{t in onset_time_set}\sum_tau=1^t_max w_t cases_true_t-tau))

This function either returns a draw (or draws if ndraws>1) from this posterior, or it returns the Rt set that maximises it (if maximise=TRUE). Alternatively the renewal equation may be specified by a negative binomial distribution:

cases_true_t ~ NB(Rt * \sum_tau=1^t_max w_t cases_true_t-tau, kappa)

where kappa is the overdispersion parameter. In this case, importance sampling using the Poisson posterior as the importance distribution is used to estimate a negative binomial posterior.

Usage

sample_Rt(
  cases_history_df,
  Rt_prior_parameters,
  serial_parameters,
  kappa = NULL,
  serial_max = 40,
  ndraws = 1,
  maximise = FALSE,
  is_negative_binomial = FALSE,
  nresamples = 100
)

Arguments

cases_history_df

a tibble with three columns: time_onset, cases_true and Rt_index

Rt_prior_parameters

a list with elements 'shape' and 'rate' describing the gamma prior for Rt

serial_parameters

named list of 'mean' and 'sd' of gamma distribution characterising the serial interval distribution

kappa

overdispersion parameter

serial_max

maximum point at which to truncate sum in renewal process

ndraws

number of draws of Rt

maximise

rather than sample a case count give the case count with the maximum probability (by default is FALSE)

is_negative_binomial

if negative-binomial renewal model specified (defaults to FALSE)

nresamples

number of importance resamples of Rt to perform if assuming a negative binomial model

Value

a tibble with three columns: "Rt_piece_index", "draw_index", "Rt"


ben18785/incidenceinflation documentation built on Feb. 8, 2024, 2:36 a.m.