View source: R/estimate_dist.R
| estimate_dist | R Documentation |
Fit a delay distribution accounting for primary and secondary
event censoring (double interval censoring) and right
truncation.
Estimation is done via MCMC using a Stan model that vendors
likelihood functions from the
primarycensored
package.
For more flexible delay distribution modelling (e.g.
time-varying delays, partial pooling, or regression on
covariates), see the
epidist package.
If you use this function, please cite
primarycensored in
addition to EpiNow2.
estimate_dist(
data,
dist = "lognormal",
priors = switch(dist, lognormal = list(meanlog = Normal(1, 1), sdlog = Normal(0.5,
0.5)), gamma = list(shape = Normal(2, 2), rate = Normal(0.5, 0.5)), normal =
list(mean = Normal(5, 5), sd = Normal(1, 1)), exp = list(rate = Normal(0.5, 0.5)),
weibull = list(shape = Normal(2, 2), scale = Normal(5, 5))),
primary = "uniform",
primary_params = numeric(0),
stan = stan_opts(),
max_value = NULL,
obs_time_threshold = 2,
verbose = FALSE
)
data |
A data.frame with date columns:
|
dist |
Character string, which distribution to fit.
One of |
priors |
A list of
|
primary |
Character string specifying the primary event distribution. One of:
|
primary_params |
Numeric vector of parameters for the
primary distribution.
Only used when |
stan |
A list of stan options as generated by |
max_value |
Numeric, maximum delay value for PMF. If not provided, inferred from data. |
obs_time_threshold |
Numeric, multiplier for the
obs-time-to-Inf heuristic. Observations where
|
verbose |
Logical, print progress messages? Defaults to FALSE. |
The model fits an interval-censored delay distribution while accounting for:
Primary event censoring (e.g., daily reporting of exposure)
Secondary event censoring (e.g., daily reporting of symptom onset)
Right truncation (observation window effects)
Per-observation truncation times (via obs_date)
When a data frame with date columns is provided, observations
are aggregated by unique combinations of (delay_lwr, delay_upr, pwindow, relative_obs_time) to reduce the number
of likelihood evaluations.
Observations where the relative observation time is much
larger than the maximum observed delay are treated as
untruncated (observation time set to infinity).
The primarycensored Stan functions are vendored (included
in the package), so the model is pre-compiled and runs without
needing primarycensored at runtime.
Delay distributions are limited to lognormal, gamma, normal, exponential, and weibull.
The primary event distribution is limited to uniform or exponential growth with a fixed rate. Primary event parameters are not estimated.
Left truncation is not yet exposed (internally set to -Inf).
An <estimate_dist> object (inheriting from
<epinowfit>) with components:
The Stan fit object.
The Stan data list used for fitting.
The input data.
Use get_parameters() to extract the fitted <dist_spec>.
Park SW, et al. (2024) "Estimating epidemiological delay distributions for infectious diseases." doi:10.1101/2024.01.12.24301247
Charniga K, Park SW, et al. (2024) "Best practices for estimating and reporting epidemiological delay distributions of infectious diseases." PLoS Comput Biol 20(10): e1012520. doi:10.1371/journal.pcbi.1012520
Please cite primarycensored if you use this function;
see citation("primarycensored").
vignette("estimate_dist_workflow", package = "EpiNow2") for
a worked example, and
primarycensored::primarycensored-package for the underlying
censoring methodology.
# Fit lognormal distribution from date-based linelist
if (requireNamespace("primarycensored", quietly = TRUE)) {
set.seed(1)
n <- 100
D <- 30
pdate_lwr <- as.Date("2023-01-01") + rpois(n, 5)
delays_sim <- primarycensored::rprimarycensored(
n = n, rdist = rlnorm,
meanlog = log(5), sdlog = 0.5,
pwindow = 1, D = D
)
linelist <- data.frame(
pdate_lwr = pdate_lwr,
sdate_lwr = pdate_lwr + delays_sim,
obs_date = pdate_lwr + D
)
result <- estimate_dist(linelist, dist = "lognormal")
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.