Description Usage Arguments Value Examples
Approximate Sampling a Distribution using Counts
1 2 3 4 5 6 7 8 9 |
cases |
A dataframe of cases (in date order) with the following variables:
|
dist_fn |
Function that takes two arguments with the first being numeric and the second being logical (and
defined as |
max_value |
Numeric, maximum value to allow. Defaults to 120 days |
earliest_allowed_mapped |
A character string representing a date ("2020-01-01"). Indicates the earlies allowed mapped value. |
direction |
Character string, defato "backwards". Direction in which to map cases. Supports either "backwards" or "forwards". |
type |
Character string indicating the method to use to transfrom counts. Supports either "sample" which approximates sampling or "median" would shift by the median of the distribution. |
truncate_future |
Logical, should cases be truncted if they occur after the first date reported in the data.
Defaults to |
A data.table
of cases by date of onset
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | cases <- data.table::as.data.table(EpiSoon::example_obs_cases)
cases <- cases[, cases := as.integer(cases)]
## Reported case distribution
print(cases)
## Total cases
sum(cases$cases)
delay_fn <- function(n, dist, cum) {
if(dist) {
pgamma(n + 0.9999, 2, 1) - pgamma(n - 1e-5, 2, 1)
}else{
as.integer(rgamma(n, 2, 1))
}
}
onsets <- sample_approx_dist(cases = cases,
dist_fn = delay_fn)
## Estimated onset distribution
print(onsets)
## Check that sum is equal to reported cases
total_onsets <- median(
purrr::map_dbl(1:1000,
~ sum(sample_approx_dist(cases = cases,
dist_fn = delay_fn)$cases)))
total_onsets
## Map from onset cases to reported
reports <- sample_approx_dist(cases = cases,
dist_fn = delay_fn,
direction = "forwards")
## Map from onset cases to reported using a mean shift
reports <- sample_approx_dist(cases = cases,
dist_fn = delay_fn,
direction = "forwards",
type = "median")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.