| estimate_truncation | R Documentation |
Estimates a truncation distribution from multiple snapshots of the same
data source over time. This distribution can then be passed to the
truncation argument in regional_epinow(), epinow(), and
estimate_infections() to adjust for truncated data and propagate the
uncertainty associated with data truncation into the estimates.
The model of truncation is as follows:
The truncation distribution can be any parametric family supported
by dist_spec (e.g. log-normal, gamma), with parameters informed by
the data.
The data set with the latest observations is adjusted for truncation using the truncation distribution.
Earlier data sets are recreated by applying the truncation distribution to the adjusted latest observations in the time period of the earlier data set. These data sets are then compared to the earlier observations using the selected observation model (negative binomial or Poisson) with an additive noise term to handle zero observations.
This can be thought of as a Bayesian form of the chain-ladder
nowcasting approach in the
baselinenowcast
package. For settings requiring time-varying delays, see
epinowcast.
estimate_truncation(
data,
truncation = trunc_opts(LogNormal(meanlog = Normal(0, 1), sdlog = Normal(1, 1), max =
10)),
obs = obs_opts(),
noise = Normal(mean = 0, sd = 1),
stan = stan_opts(),
CrIs = c(0.2, 0.5, 0.9),
filter_leading_zeros = FALSE,
zero_threshold = Inf,
verbose = TRUE,
...
)
data |
A list of |
truncation |
A call to |
obs |
A list of observation model options as generated by
|
noise |
A |
stan |
A list of stan options as generated by |
CrIs |
Numeric vector of credible intervals to calculate. |
filter_leading_zeros |
Logical, defaults to FALSE. Should zeros at the start of the time series be filtered out. |
zero_threshold |
Numeric, defaults to Inf. Observations with a primary count less than this threshold are set to zero. |
verbose |
Logical, should model fitting progress be returned. |
... |
Additional parameters to pass to |
An <estimate_truncation> object containing:
observations: The input data (list of <data.frame>s).
args: A list of arguments used for fitting (stan data).
fit: The stan fit object.
get_samples() get_predictions() get_parameters()
# set number of cores to use
old_opts <- options()
options(mc.cores = ifelse(interactive(), 4, 1))
# fit model to example data
# See [example_truncated] for more details
# iterations and calculation time have been reduced for this example
# for real analyses, use more
est <- estimate_truncation(example_truncated,
verbose = interactive(),
chains = 2, iter = 200
)
# extract the estimated truncation distribution
get_parameters(est)[["truncation"]]
# summarise the truncation distribution parameters
summary(est)
# validation plot of observations vs estimates
plot(est)
# Pass the truncation distribution to `epinow()`.
# Note, we're using the last snapshot as the observed data as it contains
# all the previous snapshots. Also, we're using the default options for
# illustrative purposes only.
out <- epinow(
generation_time = generation_time_opts(example_generation_time),
example_truncated[[5]],
truncation = trunc_opts(get_parameters(est)[["truncation"]])
)
plot(out)
options(old_opts)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.