estimate_Rt | R Documentation |
Given a case-tracking dataset, determine the basic reproduction index over time.
estimate_Rt( df, filter_expression, cases_column = "count", date_column = "date", method, config, cumulative = TRUE, estimation_family = "epiestim", invert = FALSE, quiet = TRUE, ... )
df |
a data.frame containing at least a date column and a cases column, describing
the cumulative cases at each date. Note that dates MUST NOT REPEAT and the function
will check that this is the case. Use the |
filter_expression |
a |
cases_column |
character(1) name of (cumulative) cases column in the input data.frame |
date_column |
character(1) name of date column in the input data.frame |
method |
character(1) passed to |
config |
list() passed to |
cumulative |
logical(1) whether the case counts are cumulative (TRUE) or are daily incidence (FALSE) |
estimation_family |
One of |
invert |
Unused default FALSE, but if TRUE, returns 1/R(t) or related estimate, useful for plotting, since we are often most interested in looking at R(t) near or below 1. |
quiet |
logical(1) whether or not to provide messages, etc. |
... |
passed to the estimation method |
For the epiestim method, returns a data.frame with columns: - Mean(R) - Std(R) - Quantile.0.025(R) - Quantile.0.05(R) - Quantile.0.25(R) - Median(R) - Quantile.0.75(R) - Quantile.0.95(R) - Quantile.0.975(R)" - date_start - date_end
Other analysis:
bulk_estimate_Rt()
Other case-tracking:
align_to_baseline()
,
beoutbreakprepared_data()
,
bulk_estimate_Rt()
,
combined_us_cases_data()
,
coronadatascraper_data()
,
covidtracker_data()
,
ecdc_data()
,
jhu_data()
,
nytimes_county_data()
,
owid_data()
,
plot_epicurve()
,
test_and_trace_data()
,
usa_facts_data()
,
who_cases()
nyt = nytimes_state_data() head(nyt) nystate_Rt = estimate_Rt( nyt, filter_expression = state=='New York' & subset=='confirmed', estimation_family='epiestim', cumulative=TRUE, method = 'parametric_si', config = list(mean_si=3.96, std_si=4.75)) head(nystate_Rt) library(ggplot2) p = ggplot(nystate_Rt, aes(x=date_start,y=`Mean(R)`)) + geom_line() p p + geom_ribbon(aes(ymin=`Quantile.0.05(R)`, ymax=`Quantile.0.95(R)`), alpha=0.5) # plot 1/Rt to expand region around 1 since that is typically what # is most interesting with respect to controls p = ggplot(nystate_Rt, aes(x=date_start,y=1/`Mean(R)`)) + geom_line() p p + geom_ribbon(aes(ymax=1/`Quantile.0.05(R)`, ymin=1/`Quantile.0.95(R)`), alpha=0.5) # and simple loess smoothing p + geom_smooth() # super-cool use of tidyr, purrr, and dplyr to perform # calculations over all states: ## Not run: library(dplyr) library(tidyr) est_by = function(df) { estimate_Rt( df, estimation_family='epiestim', cumulative=TRUE, method = 'parametric_si', config = list(mean_si=3.96, std_si=4.75)) } z = nyt %>% dplyr::filter(subset=='confirmed') %>% tidyr::nest(-state) %>% dplyr::mutate(rt_df = purrr::map(data, est_by)) %>% tidyr::unnest(cols=rt_df) p = ggplot(z,aes(x=date_start,y=1/`Mean(R)`, color=state)) + ylim(c(0.5,1.25)) + geom_smooth(se = FALSE) p library(plotly) ggplotly(p) ## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.