get_matrix_from_empirical_delay_distr.Rd
This function takes a record of delays between events and their observations
and builds a discretized delay distribution matrix from this record.
The discretized delay distribution matrix
is required for the application of the Richardson-Lucy algorithm.
The main benefit of providing empirical delay data to an estimateR
analysis,
as opposed to specifiying a delay as a single distribution
(whether a fitted or empirical distribution) is that the variability of
the delays through time is used to inform the analysis and provide more accurate estimates.
If the average of delays has shifted from 5 days to 3 days between the beginning and end
of epidemic of interest, this will be reflected in the recorded empirical delays
and will be accounted for by estimateR
when estimating the reproductive number.
get_matrix_from_empirical_delay_distr( empirical_delays, n_report_time_steps, ref_date = NULL, time_step = "day", min_number_cases = NULL, upper_quantile_threshold = 0.99, min_number_cases_fraction = 0.2, min_min_number_cases = 500, fit = "none", return_fitted_distribution = FALSE, num_steps_in_a_unit = NULL )
empirical_delays | dataframe containing the empirical data. See Details. |
---|---|
n_report_time_steps | integer. Length of the incidence time series in the accompanying analysis. This argument is needed to determine the dimensions of the output matrix. |
ref_date | Date. Optional. Date of the first data entry in |
time_step | string. Time between two consecutive incidence datapoints.
"day", "2 days", "week", "year"... (see |
min_number_cases | integer.
Minimal number of cases to build the empirical distribution from.
If |
upper_quantile_threshold | numeric. Between 0 and 1. Argument for internal use. |
min_number_cases_fraction | numeric. Between 0 and 1.
If |
min_min_number_cases | numeric. Lower bound for number of cases used to build an instant delay distribution. |
fit | string. One of "gamma" or "none". Specifies the type of fit that is applied to the columns of the delay matrix |
return_fitted_distribution | boolean. If TRUE, the function also returns the gamma distribution that was fitted to the respective column. |
num_steps_in_a_unit | Optional argument. Number of time steps in a full time unit (e.g. 7 if looking at weeks). If set, the delays used to build a particular delay distribution will span over a round number of such time units. This option is included for comparison with legacy code. |
a discretized delay distribution matrix.
The ref_date
argument here will be understood as the date of the first record in the incidence data
for which the empirical delay data will be used.
If ref_date
is not provided, the reference date will be taken as being the earliest date in the
event_date
column of empirical_delays
. In other words, the date of the first record in the incidence data
will be assumed to be the same as the date of the first record in the empirical delay data.
If this is not the case in your analysis, make sure to specify a ref_date
argument.
## Basic usage of get_matrix_from_empirical_delay_distr # Obtaining the deconvolved incidence for the full HK incidence data provided in # the package: obtaining the delay matrix and then using it to recover the # deconvolved incidence. smoothed_incidence <- smooth_incidence(HK_incidence_data$case_incidence) shape_incubation = 3.2 scale_incubation = 1.3 delay_incubation <- list(name="gamma", shape = shape_incubation, scale = scale_incubation) delay_matrix_1 <- get_matrix_from_empirical_delay_distr( HK_delay_data, n_report_time_steps = length(smoothed_incidence) ) deconvolved_incidence_1 <- deconvolve_incidence( incidence_data = smoothed_incidence, delay = list(delay_incubation, delay_matrix_1) ) ## Advanced usage of get_matrix_from_empirical_delay_distr # Obtaining the deconvolved incidence for a section of the HK incidence data # provided in the package: computing the delay matrix, fitting gamma distributions # to the columns and then using it to recover the deconvolved incidence for the # time-frame of interest smoothed_partial_incidence <- smooth_incidence(HK_incidence_data[30:90,]$case_incidence) delay_matrix_2 <- get_matrix_from_empirical_delay_distr( HK_delay_data, n_report_time_steps = length(smoothed_partial_incidence), fit = "gamma", ref_date = HK_incidence_data[30,]$date ) deconvolved_incidence_2 <- deconvolve_incidence( incidence_data = smoothed_partial_incidence, delay = list(delay_incubation, delay_matrix_2) )