
Posterior samples of the parametric reporting-delay distribution
Source:R/postprocess.R
enw_posterior_delay.RdExtracts posterior draws of the parametric reporting-delay distribution from a fit (e.g. a delay-only fit, see the delay estimation vignette) and returns the discretised delay probability mass function for each draw. This supports comparing the estimated distribution against a known truth and plotting posterior samples rather than only summaries.
Arguments
- fit
A
cmdstanrfit object (thefit[[1]]element of anepinowcastoutput).- max_delay
Maximum delay (number of delay slots, delays
0:(max_delay - 1)).- distribution
The parametric distribution used in
enw_reference(), one of "lognormal", "gamma", "exponential", or "loglogistic". Defaults to "lognormal". Acmdstanrfit does not record which distribution was used (themodel_refpid is Stan data, not saved to the draws), so this must match the distribution passed toenw_reference(). An incorrect value silently yields the wrong PMF.- draws
Optional integer; if supplied, a random subset of this many posterior draws is returned (useful for plotting). The same draws are used across all reference-design rows.
Value
A long data.table with columns .draw, delay, and pmf, plus
an integer row column when the delay model has more than one
reference-design row.
Details
The function reads the full refp_mean and refp_sd vectors saved by the
Stan model (one entry per unique combination of parametric reference-date
covariates) and discretises a delay PMF for each. For an intercept-only
delay (the common case, refp_mean of length one) the output is a long
data.table with columns .draw, delay, and pmf. For a delay model
with reference-date covariates, random effects, or time- or group-varying
delays (refp_mean of length greater than one) an additional integer row
column identifies the reference-design row, and each row may have a
different PMF. The mapping from row to reference date and group is set by
the reference module's fixed-effect design (see enw_reference() and
enw_formula_as_data_list()'s refp_findex); it is not recovered here
because a cmdstanr fit does not retain that design on its own.
See also
Functions used for postprocessing of model fits
.check_primarycensored(),
.delay_draw_columns(),
.discretise_parametric_pmf(),
build_ord_obs(),
enw_add_latest_obs_to_nowcast(),
enw_nowcast_samples(),
enw_nowcast_summary(),
enw_posterior(),
enw_pp_summary(),
enw_quantiles_to_long(),
enw_summarise_samples(),
subset_obs()
Examples
if (FALSE) { # interactive()
fit <- enw_example("nowcast")
# Intercept-only delay
enw_posterior_delay(fit$fit[[1]], max_delay = 20, draws = 50)
# A delay model with a reference-date covariate yields one PMF per
# reference-design row, identified by the `row` column:
if (FALSE) { # \dontrun{
pobs <- enw_example("preprocessed")
covariate_fit <- epinowcast(
pobs,
reference = enw_reference(~ 1 + day_of_week, data = pobs),
obs = enw_obs(delay_only = TRUE, data = pobs)
)
enw_posterior_delay(covariate_fit$fit[[1]], max_delay = 20, draws = 50)
} # }
}