View source: R/get_time_delay.R
get_time_delay | R Documentation |
The output is a list
containing summary statistics of time delay between two date/datetime vectors.
This can be especially useful in estimating reporting delay for example.
data - A data frame containing the origin, end and calculated time delay.
unit - The chosen time unit.
num - The number of time units.
summary - tibble
with summary statistics.
delay - tibble
containing the empirical cumulative distribution function
values by time delay.
plot - A ggplot
of the time delay distribution.
get_time_delay(
data,
origin,
end,
timespan = 1L,
min_delay = -Inf,
max_delay = Inf,
probs = c(0.25, 0.5, 0.75, 0.95),
.by = NULL,
include_plot = TRUE,
x_scales = "fixed",
bw = "sj",
...
)
data |
A data frame. |
origin |
Origin date variable. |
end |
End date variable. |
timespan |
timespan. |
min_delay |
The minimum acceptable delay,
all delays less than this are removed before calculation.
Default is |
max_delay |
The maximum acceptable delay,
all delays greater than this are removed before calculation.
Default is |
probs |
Probabilities used in the quantile summary.
Default is |
.by |
(Optional). A selection of columns to group by for this operation. Columns are specified using tidy-select. |
include_plot |
Should a |
x_scales |
Option to control how the x-axis is displayed for multiple facets. Choices are "fixed" or "free_x". |
bw |
The smoothing bandwidth selector for the Kernel Density estimator.
If numeric, the standard deviation of the smoothing kernel.
If character, a rule to choose the bandwidth. See |
... |
Further arguments to be passed on to |
A list containing summary data, summary statistics and an optional ggplot
.
library(timeplyr)
library(outbreaks)
library(dplyr)
ebola_linelist <- ebola_sim_clean$linelist
# Incubation period distribution
# 95% of individuals experienced an incubation period of <= 26 days
inc_distr_days <- ebola_linelist %>%
get_time_delay(date_of_infection,
date_of_onset,
time = "days")
head(inc_distr_days$data)
inc_distr_days$unit
inc_distr_days$num
inc_distr_days$summary
head(inc_distr_days$delay) # ECDF and freq by delay
inc_distr_days$plot
# Can change bandwidth selector
inc_distr_days <- ebola_linelist %>%
get_time_delay(date_of_infection,
date_of_onset,
time = "day",
bw = "nrd")
inc_distr_days$plot
# Can choose any time units
inc_distr_weeks <- ebola_linelist %>%
get_time_delay(date_of_infection,
date_of_onset,
time = "weeks",
bw = "nrd")
inc_distr_weeks$plot
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.