From bc98e15605f7e32a872ff89201ba5403c216913d Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Tue, 9 Jan 2024 15:47:09 +0000 Subject: [PATCH 01/75] Removing text about hard-coded gamma distribution --- .../rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd index 737f88f..d042895 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd @@ -384,8 +384,7 @@ probability distribution. This distribution is a key input to methods use for estimating the reproduction number ($R$). Here, we assume that the mean and standard deviation of the $si$ is known, and -provided as an input by the user. We model the $si$ distribution as a -discretized Gamma. +provided as an input by the user. ## Results From 73eab39aa1132c6ed85bdc64e1a55e714172e0f6 Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Tue, 9 Jan 2024 16:03:54 +0000 Subject: [PATCH 02/75] Changing "dat" to actual name of file "dat_raw" --- inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd index d042895..cb7c312 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd @@ -281,7 +281,7 @@ dat_raw <- data_path %>% mutate(across(where(\(x) inherits(x, "POSIXct")), as.Date)) ``` -Once imported into __R__, the dataset called `dat` includes: +Once imported into __R__, the dataset called `dat_raw` includes: * `date`: the date of admission * `region`: the NHS region From 8b9c2ab7027940c33e9d2b4193da3d9a51a8793c Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Tue, 30 Jan 2024 11:35:21 +0000 Subject: [PATCH 03/75] Update description of report parameters "incomplete_days" and "r_estim_window" --- .../templates/transmissibility/skeleton/skeleton.Rmd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd index cb7c312..72b4b11 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd @@ -13,10 +13,10 @@ params: label: "An integer or character indicating the (fixed) size of the time interval used for computing the incidence. Passed as the `interval` argument in `incidence2::incidence()`." value: "week" incomplete_days: - label: "Number of days to exclude from the estimation of Rt since data is likely to still be incomplete." + label: "Number of most recent days days to be excluded from the dataset when estimating Rt, as these data may not be fully complete at the time of reporting" value: 7 r_estim_window: - label: "Number of days to include to get the latest observed value of Rt." + label: "Number of days to include to get the latest observed value of Rt, excluding the most recent days specified by the parameter incomplete_days" value: 21 use_epiparameter_database: label: "Should the serial interval distribution be extracted directly from the epiparameter package?" From 822a8b3cbcb8a4a2b04f46ed200c811166cb5552 Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Tue, 30 Jan 2024 11:37:24 +0000 Subject: [PATCH 04/75] Updating description of parameter "data_file" --- inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd index 72b4b11..2edfdb2 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd @@ -34,7 +34,7 @@ params: label: "Choice of probability distribution for serial interval if not using value from epiparameter. Ignored if `use_epiparameter_database = TRUE`." value: "gamma" choices: ["beta", "binom", "cauchy", "chisq", "exp", "f", "gamma", "geom", "hyper", "lnorm", "logis", "nbinom", "norm", "pois", "smirnov", "t", "tukey", "unif", "weibull", "wilcox"] - data_file: + data_file: label: "Name of file containing case data, whether a line list or incidence data" value: "data/covid_linelist_england.rds" input: file From 2b85920ee727db2df07c15ca77e3fc0d5d7b0442 Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Tue, 30 Jan 2024 11:38:13 +0000 Subject: [PATCH 05/75] Updating description of report as seen when rendered --- inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd index 2edfdb2..2c41b68 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd @@ -192,7 +192,7 @@ showtext::showtext_auto() ## Estimating transmissibility from stratified population -This report provides a template for estimating transmissibility (i.e., how fast +This report estimates disease transmissibility (i.e., how fast a disease spreads) from a stratified population. It performs basic descriptive analyses, and uses different approaches for estimating transmissibility. The key steps of the report include: From a993ec31fe7b5c0f041b5b26100230a4e89cd77a Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Tue, 30 Jan 2024 11:44:40 +0000 Subject: [PATCH 06/75] Moved description of code about loading libraries inside corresponding rmd chunk --- .../templates/transmissibility/skeleton/skeleton.Rmd | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd index 2c41b68..77393ce 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd @@ -209,13 +209,11 @@ knitr::include_graphics("transmissibility_pipeline.svg") # Data preparation -## Loading libraries +```{r, include=FALSE} +#The following code loads required packages; missing packages will be installed +#automatically, but will require a working internet connection for the +#installation to be successful. -The following code loads required packages; missing packages will be installed -automatically, but will require a working internet connection for the -installation to be successful. - -```{r} library(dplyr) library(ggplot2) library(forcats) From b49501c5d1f997d26d63fdc2b47e20d7421093d6 Mon Sep 17 00:00:00 2001 From: Hugo Gruson Date: Mon, 29 Jan 2024 19:10:36 +0100 Subject: [PATCH 07/75] Simplify and add flexibility to generation time definition Fix #113 --- .../skeleton/rmdchunks/EpiNow2.Rmd | 28 ++++--------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd index ef5c6be..b0cc2ce 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd @@ -13,25 +13,8 @@ library(EpiNow2) ### Results ```{r rt-wrappers-prep} -# Approximate serial interval with gamma distribution since this is what EpiNow2 -# will use for generation_time -si_gamma <- epiparameter::extract_param( - type = "range", - values = c(median(si$prob_dist$r(1e3)), - min(si$prob_dist$r(1e3)), - max(si$prob_dist$r(1e3))), - distribution = params$si_dist, - samples = 1e3 -) -si_gamma <- epiparameter::convert_params_to_summary_stats( - distribution = "gamma", shape = si_gamma[[1]], scale = si_gamma[[2]]) - -generation_time <- list( - mean = si_gamma$mean, - mean_sd = 0, - sd = si_gamma$sd, - sd_sd = 0, - max = max(si_x) +generation_time <- generation_time_opts( + dist_spec(pmf = si$prob_dist$d(si_x)) ) ``` @@ -50,9 +33,10 @@ associated 95% credibility intervals # for a long time! res_epinow2_global <- dat_i_day %>% regroup() %>% - dplyr::rename( - confirm = .data[[count_var]], - date = date_index + dplyr::mutate( + confirm = count, + date = as.Date(date_index), + .keep = "unused" ) %>% epinow( generation_time = generation_time, From 44e472f0bdeadf1428be7444571ed750200feda3 Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Tue, 30 Jan 2024 11:56:10 +0000 Subject: [PATCH 08/75] Moving code description about changing the data_file parameter inside corresponding rmd chunk --- inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd | 2 ++ 1 file changed, 2 insertions(+) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd index 77393ce..630293e 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd @@ -265,6 +265,8 @@ the *data/* folder. To adapt this report to another dataset, change the name of the file in the `data_file` parameter at the top of this document. ```{r} +# To adapt this report to another dataset, change the name of +# the file in the `data_file` parameter at the top of this document. data_path <- params$data_file ``` From 87a46dd7a7fb53d1b12f134713a5c1ddfe9f6824 Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Tue, 30 Jan 2024 15:20:47 +0000 Subject: [PATCH 09/75] Replacing description of data with template to be filled by users --- .../transmissibility/skeleton/skeleton.Rmd | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd index 630293e..485297b 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd @@ -254,15 +254,13 @@ apt install libsodium-dev cmake ## Importing the data -To illustrate the different analyses, we use real data reporting line list -(individual level) data of Covid-19 cases in England in the second half of 2020. -The data was downloaded from : +To illustrate the different analyses, we use data reporting daily numbers of +[enter disease name] in [enter location] during [enter timeframe], +and is stratified by [enter region level]. +The data is available from [enter data source]. -> Xu, B., Gutierrez, B., Mekaru, S. et al. Epidemiological data from the COVID-19 outbreak, real-time case information. Sci Data 7, 106 (2020). https://doi.org/10.1038/s41597-020-0448-0 - -The data file is named "*covid_linelist_england.rds*" and is located in -the *data/* folder. To adapt this report to another dataset, change the name of -the file in the `data_file` parameter at the top of this document. +The data file is named "*file_name.rds*" and is located in +the *data/* folder. ```{r} # To adapt this report to another dataset, change the name of From 18092b2980ce74deef473e79c222ea372b8c93b2 Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Tue, 30 Jan 2024 15:26:11 +0000 Subject: [PATCH 10/75] Changing description of NHS data to template to be filled in by users --- .../templates/transmissibility/skeleton/skeleton.Rmd | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd index 485297b..188047b 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd @@ -281,12 +281,9 @@ dat_raw <- data_path %>% Once imported into __R__, the dataset called `dat_raw` includes: -* `date`: the date of admission -* `region`: the NHS region -* `org_name`: the full name of the NHS trust -* `org_code`: a short code for the NHS trust -* `n`: number of new, confirmed COVID-19 cases admitted, including inpatients - who tested positive on that day, and new admissions with a positive test +* `date`: the date of [enter description] +* `region`: the region of [enter description] +* `n`: number of new cases of [enter description] ## Identifying key data From 8f90373d91615176394cdd69a24d39a584bf29b1 Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Tue, 30 Jan 2024 15:37:00 +0000 Subject: [PATCH 11/75] Adding visualisation of dataset heading --- .../templates/transmissibility/skeleton/skeleton.Rmd | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd index 188047b..b933fe3 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd @@ -285,6 +285,10 @@ Once imported into __R__, the dataset called `dat_raw` includes: * `region`: the region of [enter description] * `n`: number of new cases of [enter description] +```{r} +head(dat_raw) +``` + ## Identifying key data __Note__: this is not used for now, as there is no integration of linelist with From 38180e5f58b65a58a4dbad4fdbc19489ae84b186 Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Tue, 30 Jan 2024 16:51:37 +0000 Subject: [PATCH 12/75] Changing count_var object to column name to fix error when estimating rt --- .../templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd index b0cc2ce..26a18d0 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd @@ -85,7 +85,7 @@ res_epinow2_global$estimates$summarised %>% ```{r rt-estim-group, message = FALSE} res_epinow2_group <- dat_i_day %>% dplyr::rename( - confirm = .data[[count_var]], + confirm = .data[["count"]], date = date_index, region = .data[[group_var]] ) %>% From 86065c63d317a43db29cfdbcaf5d7d454cbef9c4 Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Fri, 9 Feb 2024 13:07:09 +0000 Subject: [PATCH 13/75] Updating EpiNow2 generation time parameter --- .../templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd index 26a18d0..ca6fd74 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd @@ -90,7 +90,7 @@ res_epinow2_group <- dat_i_day %>% region = .data[[group_var]] ) %>% regional_epinow( - generation_time = generation_time, + generation_time = generation_time_opts(generation_time), stan = stan_opts(samples = 1e3, chains = 2), rt = rt_opts(gp_on = "R0"), horizon = 0, From c69fcaca9ddf1a5c26e4a999e38b31d13d06a6fc Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Fri, 23 Feb 2024 12:22:38 +0000 Subject: [PATCH 14/75] Fixing lintr indentation --- .../skeleton/rmdchunks/R0.Rmd | 36 +++++++++---------- .../transmissibility/skeleton/skeleton.Rmd | 7 ++-- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/R0.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/R0.Rmd index fd34981..1ecf36c 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/R0.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/R0.Rmd @@ -44,12 +44,12 @@ associated 95% credibility intervals res_r0_global <- dat_i_day %>% regroup() %>% mutate(r0_quantiles(estimate.R( - get_count_value(.), - mGT, - date_index, - begin = 1L, end = length(date_index), - nsim = 1e4, method = "TD" - )$estimates$TD) + get_count_value(.), + mGT, + date_index, + begin = 1L, end = length(date_index), + nsim = 1e4, method = "TD" + )$estimates$TD) ) ``` @@ -129,18 +129,18 @@ res_r0_group %>% na.omit() %>% filter(date_index == max(date_index)) %>% ggplot(aes(y = .data[[group_var]]), fill = custom_grey) + - geom_point(aes(x = median), color = dark_green) + - geom_errorbar(aes(xmin = lower, xmax = upper), color = dark_green) + - geom_vline(xintercept = 1, color = dark_pink) + - labs( - title = "Latest estimates of Rt", - subtitle = sprintf( - "As of %s", - format(max(get_dates(dat_i_day)), "%d %B %Y") - ), - y = "", - x = "Instantaneous Reproduction Number (Rt)" - ) + geom_point(aes(x = median), color = dark_green) + + geom_errorbar(aes(xmin = lower, xmax = upper), color = dark_green) + + geom_vline(xintercept = 1, color = dark_pink) + + labs( + title = "Latest estimates of Rt", + subtitle = sprintf( + "As of %s", + format(max(get_dates(dat_i_day)), "%d %B %Y") + ), + y = "", + x = "Instantaneous Reproduction Number (Rt)" + ) ``` ```{r rt-table-group} diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd index b933fe3..43e5871 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd @@ -409,8 +409,11 @@ si_epidist <- epidist( disease = params$disease_name, epi_dist = "serial_interval", prob_distribution = params$si_dist, - summary_stats = create_epidist_summary_stats(mean = params$si_mean, - sd = params$si_sd) + summary_stats = create_epidist_summary_stats( + mean = params$si_mean, + sd = params$si_sd + ), + auto_calc_params = TRUE ) ``` From 0aa288a0c968b876e6959c351e1d2df10ea2148d Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Fri, 23 Feb 2024 12:23:03 +0000 Subject: [PATCH 15/75] Fixing lintr indentation --- .../skeleton/rmdchunks/EpiEstim.Rmd | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiEstim.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiEstim.Rmd index ba8855b..c49d45f 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiEstim.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiEstim.Rmd @@ -123,8 +123,8 @@ res_epiestim_group <- dat_i_day %>% mutate( res_epiestim = map(data, ~ wrap_res( estimate_R(.x$count, config = ee_config), - dat_i_day) - ) + dat_i_day + )) ) %>% unnest(res_epiestim) %>% dplyr::select(-data) @@ -150,18 +150,18 @@ ggplot(res_epiestim_group, aes(x = end)) + res_epiestim_group %>% filter(end == max(end)) %>% ggplot(aes(y = .data[[group_var]]), fill = custom_grey) + - geom_point(aes(x = median), color = dark_green) + - geom_errorbar(aes(xmin = lower, xmax = upper), color = dark_green) + - geom_vline(xintercept = 1, color = dark_pink) + - labs( - title = "Latest estimates of Rt", - subtitle = sprintf( - "As of %s", - format(max(get_dates(dat_i_day)), "%d %B %Y") - ), - y = "", - x = "Instantaneous Reproduction Number (Rt)" - ) + geom_point(aes(x = median), color = dark_green) + + geom_errorbar(aes(xmin = lower, xmax = upper), color = dark_green) + + geom_vline(xintercept = 1, color = dark_pink) + + labs( + title = "Latest estimates of Rt", + subtitle = sprintf( + "As of %s", + format(max(get_dates(dat_i_day)), "%d %B %Y") + ), + y = "", + x = "Instantaneous Reproduction Number (Rt)" + ) ``` ```{r rt-table-group} From 730e413107ce532f63bb0577fcc2742edaf43ccb Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Fri, 23 Feb 2024 12:23:52 +0000 Subject: [PATCH 16/75] Updating use of density function with epiparameter from $d to density() --- .../templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd index ca6fd74..90fdf3c 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd @@ -14,7 +14,7 @@ library(EpiNow2) ```{r rt-wrappers-prep} generation_time <- generation_time_opts( - dist_spec(pmf = si$prob_dist$d(si_x)) + dist_spec(pmf = density(si, at = si_x)) ) ``` From c4130d49d9694e6d4dd8b5e548c7696c58107f7e Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Tue, 9 Apr 2024 12:35:39 +0100 Subject: [PATCH 17/75] Fixing typo (duplicated "days") --- inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd index 43e5871..33b0a2d 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd @@ -13,7 +13,7 @@ params: label: "An integer or character indicating the (fixed) size of the time interval used for computing the incidence. Passed as the `interval` argument in `incidence2::incidence()`." value: "week" incomplete_days: - label: "Number of most recent days days to be excluded from the dataset when estimating Rt, as these data may not be fully complete at the time of reporting" + label: "Number of most recent days to be excluded from the dataset when estimating Rt, as these data may not be fully complete at the time of reporting" value: 7 r_estim_window: label: "Number of days to include to get the latest observed value of Rt, excluding the most recent days specified by the parameter incomplete_days" From 2e1f1d91d91e9aa30382f6e24dbc1b92fa34e566 Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Tue, 9 Apr 2024 12:36:16 +0100 Subject: [PATCH 18/75] Replacing "group" by "region" to match variables in the dataset --- inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd index 33b0a2d..bd6294d 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd @@ -344,7 +344,7 @@ dat_i %>% ## Numbers of cases -This graph shows the total number of cases per group: +This graph shows the total number of cases per region: ```{r } total_cases <- dat_i %>% From 91f62d774e82ccb1a48a05c5e277c4561a0825fa Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Tue, 9 Apr 2024 12:37:53 +0100 Subject: [PATCH 19/75] Updating si parameter description for user to choose between manually provided mean/sd and when these are obtained from {epiparameter} --- .../templates/transmissibility/skeleton/skeleton.Rmd | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd index bd6294d..f29f521 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd @@ -378,12 +378,12 @@ total_cases %>% The _serial interval_ ($si$) is the delay between the date of symptom onsets of primary case and the secondary cases they have infected. Because this delay varies from -one transmission pair to another, we will characterise this variation using a -probability distribution. This distribution is a key input to methods use for +one transmission pair to another, this report characterises this variation using a +probability distribution. This distribution is a key input to methods used for estimating the reproduction number ($R$). -Here, we assume that the mean and standard deviation of the $si$ is known, and -provided as an input by the user. +In this report, the mean and standard deviation of the $si$ have been [provided as an input by the author/ +obtained from a library of epidemiological parameters from the {epiparameter} R package] ## Results From 3563cf37c25f54cd9a626a5ae770cb5efa651620 Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Tue, 9 Apr 2024 12:39:23 +0100 Subject: [PATCH 20/75] Updating description of time period included in table with Rt estimates so it's understandable by external readers --- .../templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd index 90fdf3c..854fbc4 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd @@ -26,7 +26,8 @@ stratification. Results include: * a graph of the estimates of $R_t$ of the observed data over time, with associated 95% credibility intervals -* a table summarising these results for the last `r params$r_estim_window` days +* a table summarising $R_t$ estimates for those dates with complete data, i.e., +after excluding the most recent time points in the dataset. ```{r rt-estim-global} # Warning, this step will take 2 cores of your computer and may be running From 07e9dc842f47dd6b9413720bccac47697fb44703 Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Tue, 9 Apr 2024 12:40:03 +0100 Subject: [PATCH 21/75] Adding description to the code chunk used to generate table with Rt estimates for days defined by "r_estim_window" --- .../templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd index 854fbc4..76a1bd3 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd @@ -63,6 +63,10 @@ plot(res_epinow2_global, "R") + ``` ```{r rt-table-global} +#This code generates a table that contains Rt estimates for days in the +#dataset (dat_i_day) with complete data, i.e., defined by the parameter +#"params$r_estim_window" + res_epinow2_global$estimates$summarised %>% dplyr::filter(variable == "R") %>% tail(params$r_estim_window) %>% From 9ad75ba024beff37a22e1d934e8ba0c539f049d6 Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Tue, 9 Apr 2024 14:04:43 +0100 Subject: [PATCH 22/75] Keeping only columns needed by EpiNow2 to avoid errors --- .../templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd | 1 + 1 file changed, 1 insertion(+) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd index 76a1bd3..cb7a227 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd @@ -89,6 +89,7 @@ res_epinow2_global$estimates$summarised %>% ```{r rt-estim-group, message = FALSE} res_epinow2_group <- dat_i_day %>% + select("date_index", "region", "count") %>% dplyr::rename( confirm = .data[["count"]], date = date_index, From 2d6d453cd0c5212d5b0af548dc82daa263682413 Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Tue, 9 Apr 2024 14:05:12 +0100 Subject: [PATCH 23/75] Ensure the date column's class is correct to avoid errors with regional epinow --- .../templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd | 1 + 1 file changed, 1 insertion(+) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd index cb7a227..1f3f510 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd @@ -95,6 +95,7 @@ res_epinow2_group <- dat_i_day %>% date = date_index, region = .data[[group_var]] ) %>% + dplyr::mutate(date = as.Date(date)) %>% regional_epinow( generation_time = generation_time_opts(generation_time), stan = stan_opts(samples = 1e3, chains = 2), From 0d9f5542f5cb41b035d06db34685cc90f75a03cd Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Fri, 12 Apr 2024 13:01:30 +0100 Subject: [PATCH 24/75] Plotting si allowing negative values (relevant mainly only for normal dist) --- inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd index f29f521..fcdcdc8 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd @@ -419,7 +419,7 @@ si_epidist <- epidist( ```{r} si <- discretise(si_epidist) -si_x <- seq(1L, to = quantile(si, 0.999), by = 1L) +si_x <- seq(quantile(si, 0.01), to = quantile(si, 0.999), by = 1L) ``` ```{r} From b68ba4876ef04693f02815f6d4d82d7478dfae01 Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Fri, 12 Apr 2024 13:02:09 +0100 Subject: [PATCH 25/75] Updating use of incidence2 from "daily" to 1L --- inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd index fcdcdc8..76c752c 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd @@ -460,7 +460,7 @@ i_recent <- dat_raw %>% ```{r} dat_i_day <- dat_raw %>% incidence("date", - interval = "daily", + interval = 1L, counts = count_var, groups = group_var ) %>% From 0d59ef72396a90e5ac33cb187b1d6d3aa3bde052 Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Tue, 23 Apr 2024 13:47:39 +0100 Subject: [PATCH 26/75] Reverting description of grouping variable to "group" so users can group data according to different variables --- inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd index 76c752c..583e9e2 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd @@ -282,7 +282,7 @@ dat_raw <- data_path %>% Once imported into __R__, the dataset called `dat_raw` includes: * `date`: the date of [enter description] -* `region`: the region of [enter description] +* `group`: [enter description of grouping variable, e.g., region, age, gender] * `n`: number of new cases of [enter description] ```{r} From f6e246d4196e182d973b5b73e5b6ba0887feb6b2 Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Tue, 23 Apr 2024 13:48:29 +0100 Subject: [PATCH 27/75] Adding code to specify that both epicurves are now included, and mention grouping variable name --- inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd index 583e9e2..f45ac3f 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd @@ -320,7 +320,7 @@ dat <- dat_raw %>% ## Epidemic curves -This section creates epidemic curves ("_epicurves_"), with or without stratification. +This section creates epidemic curves ("_epicurves_"), with and without stratification by [name of grouping variable]. ```{r} # convert daily incidence into weekly incidence using incidence2 From cf2405a3a3d5fa8b2f6cef4d9f93b5610b2219d6 Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Tue, 23 Apr 2024 13:50:40 +0100 Subject: [PATCH 28/75] Adding code to plot global epicurve (as it appeared in episoap vignette) --- .../templates/transmissibility/skeleton/skeleton.Rmd | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd index f45ac3f..bb8a2e8 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd @@ -336,10 +336,19 @@ n_groups <- dplyr::n_distinct(get_groups(dat_i)[[1]]) small_counts <- max(get_count_value(dat_i)) < 20 ``` +```{r} +#Plot to visualise an epicurve with total cases of disease over time +dat_i %>% + plot(fill = group_var, angle = 45, colour_palette = muted) + + labs( + title = "Weekly incidence of disease cases", x = "", y = "Incidence") +``` + ```{r fig.height = 5 / 3 * n_groups} +#Plot to generate epicurves stratified by group_var dat_i %>% plot(alpha = 1, nrow = n_groups) + - labs(title = "Incidence of cases over time") + labs(x = "", y = "Incidence") ``` ## Numbers of cases From 99cd92544966f3d921a61f263bc161aa0e5b3b3a Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Tue, 23 Apr 2024 14:46:23 +0100 Subject: [PATCH 29/75] Adding incidence2 to list of loaded packages --- .../transmissibility/skeleton/skeleton.Rmd | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd index bb8a2e8..e122385 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd @@ -223,9 +223,9 @@ library(rio) library(linelist) library(janitor) library(kableExtra) -library(incidence2) library(grateful) library(epiparameter) +library(incidence2) ``` ```{r} @@ -320,7 +320,7 @@ dat <- dat_raw %>% ## Epidemic curves -This section creates epidemic curves ("_epicurves_"), with and without stratification by [name of grouping variable]. +This section creates epidemic curves ("_epicurves_"), with or without stratification. ```{r} # convert daily incidence into weekly incidence using incidence2 @@ -336,19 +336,10 @@ n_groups <- dplyr::n_distinct(get_groups(dat_i)[[1]]) small_counts <- max(get_count_value(dat_i)) < 20 ``` -```{r} -#Plot to visualise an epicurve with total cases of disease over time -dat_i %>% - plot(fill = group_var, angle = 45, colour_palette = muted) + - labs( - title = "Weekly incidence of disease cases", x = "", y = "Incidence") -``` - ```{r fig.height = 5 / 3 * n_groups} -#Plot to generate epicurves stratified by group_var dat_i %>% plot(alpha = 1, nrow = n_groups) + - labs(x = "", y = "Incidence") + labs(title = "Incidence of cases over time") ``` ## Numbers of cases From 8813852a47cbf668e3c8adc85d2fef9519dc485f Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Tue, 23 Apr 2024 14:51:26 +0100 Subject: [PATCH 30/75] Removing redundant comma --- .../transmissibility/skeleton/rmdchunks/i2extras.Rmd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/i2extras.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/i2extras.Rmd index 3de517e..6108f08 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/i2extras.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/i2extras.Rmd @@ -21,8 +21,8 @@ and retain a total of `r params$r_estim_window` days to estimate the growth rate. Growth rates can be interpreted as the percent change in daily -incidence. Positive numbers indicate growth, while negative numbers indicate -decline, of the epidemic. For instance: +incidence. Positive numbers indicate growth, while negative numbers indicate a +decline of the epidemic. For instance: * $r = 0.02$ means that the number of new cases increases on average by 2% each day * $r = -0.13$ means that the number of new cases decreases on average by 13% each day From dbdd3a536d69ee3fb61e05021201b8d210742d07 Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Wed, 24 Apr 2024 16:34:21 +0100 Subject: [PATCH 31/75] Adding info about epicurves with stratification by group_var --- inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd index e122385..513d3e0 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd @@ -320,7 +320,7 @@ dat <- dat_raw %>% ## Epidemic curves -This section creates epidemic curves ("_epicurves_"), with or without stratification. +This section creates epidemic curves ("_epicurves_"), with and without stratification by [name of chosen grouping variable]. ```{r} # convert daily incidence into weekly incidence using incidence2 From f80b2ac4efdd1d1cd88fee14241fc1fb7969f33b Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Wed, 24 Apr 2024 16:35:59 +0100 Subject: [PATCH 32/75] Specifying that the data_file parameter should be a path and not just the file name to avoid confusion --- inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd index 513d3e0..07cfc46 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd @@ -35,7 +35,7 @@ params: value: "gamma" choices: ["beta", "binom", "cauchy", "chisq", "exp", "f", "gamma", "geom", "hyper", "lnorm", "logis", "nbinom", "norm", "pois", "smirnov", "t", "tukey", "unif", "weibull", "wilcox"] data_file: - label: "Name of file containing case data, whether a line list or incidence data" + label: "Path to file containing case data, whether a line list or incidence data" value: "data/covid_linelist_england.rds" input: file rt_estimator: From 307122259ada068cba475f2676c18dce269882fa Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Wed, 24 Apr 2024 16:37:18 +0100 Subject: [PATCH 33/75] Adding specific details on how to select column for count_var so it's easier to understand for users --- .../templates/transmissibility/skeleton/skeleton.Rmd | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd index 07cfc46..61b631e 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd @@ -304,9 +304,9 @@ Here we identify the key data needed in the analyses, including: ```{r} date_var <- "date" group_var <- "region" -# Leave count_var as NULL if the data is really a linelist / patient-level data. -# Update count_var to a character string with the name of the column if the data -# is already aggregated. +# Leave count_var as NULL if your data is really a linelist/patient-level data. +# Update count_var to a character string with the name of the column that +# contains case counts if your data is already aggregated. count_var <- NULL dat <- dat_raw %>% From b8769d46cf93dc90eb33101427edd4ed0142f750 Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Wed, 24 Apr 2024 16:38:15 +0100 Subject: [PATCH 34/75] Adding plot for epicurve with total cases (as it appears on episoap vignette) --- .../templates/transmissibility/skeleton/skeleton.Rmd | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd index 61b631e..4931948 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd @@ -336,6 +336,14 @@ n_groups <- dplyr::n_distinct(get_groups(dat_i)[[1]]) small_counts <- max(get_count_value(dat_i)) < 20 ``` +```{r} +#Plot to visualise an epicurve with total cases of disease over time +dat_i %>% + plot(fill = group_var, angle = 45, colour_palette = muted) + + labs( + title = "Weekly incidence of disease cases", x = "", y = "Incidence") +``` + ```{r fig.height = 5 / 3 * n_groups} dat_i %>% plot(alpha = 1, nrow = n_groups) + From 504ac07e06929d14c6a2589465740b5200bc5529 Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Wed, 24 Apr 2024 16:39:13 +0100 Subject: [PATCH 35/75] Adding info about stratified epicurves and removing unnecessary labs from plot --- .../rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd index 4931948..c510166 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd @@ -345,9 +345,10 @@ dat_i %>% ``` ```{r fig.height = 5 / 3 * n_groups} +#Plot to generate epicurves stratified by group_var dat_i %>% plot(alpha = 1, nrow = n_groups) + - labs(title = "Incidence of cases over time") + labs(x = "", y = "Incidence") ``` ## Numbers of cases From f81bd57120cd2bacd6370071d143f29429c57bdb Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Wed, 24 Apr 2024 16:39:46 +0100 Subject: [PATCH 36/75] Reverting to saying "group" instead of "region" since users might want to group their data by different variables --- inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd index c510166..b0c51d9 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd @@ -353,7 +353,7 @@ dat_i %>% ## Numbers of cases -This graph shows the total number of cases per region: +This graph shows the total number of cases per group: ```{r } total_cases <- dat_i %>% From e2936374a4d5b63dd959b68e47dad1635a226885 Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Wed, 24 Apr 2024 17:20:16 +0100 Subject: [PATCH 37/75] Adding info about supported file types --- inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd | 2 ++ 1 file changed, 2 insertions(+) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd index b0c51d9..3fe7ace 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd @@ -265,6 +265,8 @@ the *data/* folder. ```{r} # To adapt this report to another dataset, change the name of # the file in the `data_file` parameter at the top of this document. +# Supported file types include .xlsx, .csv, and many others, please visit +# https://gesistsa.github.io/rio/#supported-file-formats for more information. data_path <- params$data_file ``` From fe7624b3dc410698782e12a4553a3d24d11e1488 Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Fri, 26 Apr 2024 11:11:41 +0100 Subject: [PATCH 38/75] Removing code chunks from rendering that are not relevant for reader --- .../templates/transmissibility/skeleton/skeleton.Rmd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd index 3fe7ace..12f55fa 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd @@ -203,7 +203,7 @@ steps of the report include: * estimating the growth rate and doubling time from epidemic curves * estimating the instantaneous reproduction number from epidemic curves -```{r} +```{r, include=FALSE} knitr::include_graphics("transmissibility_pipeline.svg") ``` @@ -228,7 +228,7 @@ library(epiparameter) library(incidence2) ``` -```{r} +```{r, include=FALSE} custom_grey <- "#505B5B" green_grey <- "#5E7E80" pale_green <- "#B2D1CC" From 6999bb584e45ae24c8db026337165866226bb597 Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Fri, 26 Apr 2024 11:13:41 +0100 Subject: [PATCH 39/75] Adding brief explanation for package user of what the code in each chunk is doing --- .../transmissibility/skeleton/skeleton.Rmd | 32 ++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd index 12f55fa..57c279f 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd @@ -267,10 +267,13 @@ the *data/* folder. # the file in the `data_file` parameter at the top of this document. # Supported file types include .xlsx, .csv, and many others, please visit # https://gesistsa.github.io/rio/#supported-file-formats for more information. +# The following code is used to rename your input data set as `dat_raw`. data_path <- params$data_file ``` ```{r} +# This code imports the input dataset from the data path specified by the user +# (params$data_path) dat_raw <- data_path %>% import() %>% tibble() %>% @@ -288,6 +291,7 @@ Once imported into __R__, the dataset called `dat_raw` includes: * `n`: number of new cases of [enter description] ```{r} +# This is what the data looks like: head(dat_raw) ``` @@ -304,6 +308,9 @@ Here we identify the key data needed in the analyses, including: not already aggregated counts ```{r} +# This code identifies key variables for analysis in the input dataset and, +# when working with a linelist, uses the package {linelist} to tag columns in +# the dataset that correspond to these key variables. date_var <- "date" group_var <- "region" # Leave count_var as NULL if your data is really a linelist/patient-level data. @@ -325,7 +332,7 @@ dat <- dat_raw %>% This section creates epidemic curves ("_epicurves_"), with and without stratification by [name of chosen grouping variable]. ```{r} -# convert daily incidence into weekly incidence using incidence2 +# This code converts daily incidence into weekly incidence using {incidence2} dat_i <- dat_raw %>% incidence("date", interval = params$epicurve_unit, @@ -333,13 +340,13 @@ dat_i <- dat_raw %>% groups = group_var ) -# general variables for automatic customisation of plots +# This code creates general variables for automatic customisation of plots n_groups <- dplyr::n_distinct(get_groups(dat_i)[[1]]) small_counts <- max(get_count_value(dat_i)) < 20 ``` ```{r} -#Plot to visualise an epicurve with total cases of disease over time +# Plot to visualise an epicurve with total cases of disease over time dat_i %>% plot(fill = group_var, angle = 45, colour_palette = muted) + labs( @@ -347,7 +354,7 @@ dat_i %>% ``` ```{r fig.height = 5 / 3 * n_groups} -#Plot to generate epicurves stratified by group_var +# Plot to generate epicurves stratified by group_var dat_i %>% plot(alpha = 1, nrow = n_groups) + labs(x = "", y = "Incidence") @@ -358,6 +365,9 @@ dat_i %>% This graph shows the total number of cases per group: ```{r } +# This code selects relevant variables in the weekly incidence dataset (dat_i), +# group the incidence by variable specified by "group_var", and generate a plot +# that shows the total number of cases, stratified by "group_var". total_cases <- dat_i %>% select(any_of(c(group_var, "count"))) %>% group_by(.data[[group_var]]) %>% @@ -371,6 +381,9 @@ ggplot(total_cases, aes(x = cases, y = group_var)) + geom_col(fill = green_grey) + labs(x = "Total number of cases", y = NULL) +# This code generates a table where total cases are shown, stratified by +# "group_var", as well as the proportion of cases corresponding to each level +# of "group_var". total_cases %>% mutate( percentage = sprintf("%.2f%%", cases / sum(cases) * 100) @@ -399,6 +412,9 @@ obtained from a library of epidemiological parameters from the {epiparameter} R ## Results ```{r, eval = params$use_epiparameter_database} +# If params$use_epiparameter_database=TRUE, this code accesses the +# {epiparameter} package library of epidemiological parameters to obtain a si +# distribution for params$disease_name, and creates an `epidist` object. si_epidist <- epidist_db( disease = params$disease_name, epi_dist = "serial_interval", @@ -413,6 +429,8 @@ si_sd <- si_params["sd"] ``` ```{r, eval = !params$use_epiparameter_database} +# If params$use_epiparameter_database=FALSE, this code takes the mean and sd for +# the si provided by the user and creates an epidist object si_mean <- params$si_mean si_sd <- params$si_sd si_dist <- params$si_dist @@ -429,11 +447,15 @@ si_epidist <- epidist( ``` ```{r} +# This code ensures that the si distribution is discretised, and formats the +# si for plotting si <- discretise(si_epidist) si_x <- seq(quantile(si, 0.01), to = quantile(si, 0.999), by = 1L) ``` ```{r} +# Plot to visualise the si distribution for the disease of interest +# (params$disease_name) ggplot( data.frame(delay = si_x, prob = si$prob_dist$d(si_x)), aes(x = delay, y = prob) @@ -469,6 +491,8 @@ i_recent <- dat_raw %>% ``` ```{r} +# This code creates a dataset with daily incidence data, which is needed for +# Rt estimation dat_i_day <- dat_raw %>% incidence("date", interval = 1L, From 5eac0668b2b25b7f224cce5b6adc8d2a8c16e0fe Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Fri, 26 Apr 2024 11:16:06 +0100 Subject: [PATCH 40/75] Removing "group_var" from table for reader, since the column "region" is already included --- inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd | 1 + 1 file changed, 1 insertion(+) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd index 57c279f..804f4c1 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd @@ -389,6 +389,7 @@ total_cases %>% percentage = sprintf("%.2f%%", cases / sum(cases) * 100) ) %>% adorn_totals() %>% + select(-group_var) %>% mutate(cases = format(cases, scientific = FALSE, big.mark = " ")) %>% set_names(toupper) %>% kbl() %>% From 5cafd66ad5d4753e59aa86dde0dee660b841871d Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Fri, 26 Apr 2024 11:20:55 +0100 Subject: [PATCH 41/75] Adding explanation for reader about transmissibility by group results included in EpiEstim chunk --- .../transmissibility/skeleton/rmdchunks/EpiEstim.Rmd | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiEstim.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiEstim.Rmd index c49d45f..c8c66e5 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiEstim.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiEstim.Rmd @@ -116,6 +116,15 @@ res_epiestim_global %>% #### Transmissibility by group +These analyses present Rt results for the stratified incidence.Results include: + +* a graph of the estimates of $R_t$ of the observed data over time per group, with +associated 95% credibility intervals + +* a plot with the latest $R_t$ estimate per group, with associated 95% credibility intervals + +* a table with the latest $R_t$ estimates per group, with associated 95% credibility intervals + ```{r rt-estim-group} # Get results by group, keeping only the last 14 days of data res_epiestim_group <- dat_i_day %>% From 356c2ff4cfff928853d3e224d3164a3edafabcd2 Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Fri, 26 Apr 2024 11:22:15 +0100 Subject: [PATCH 42/75] Removing "count_variable" from output table for reader as it's a column with "date" on each row, which isn't helpful or nice --- .../templates/transmissibility/skeleton/rmdchunks/EpiEstim.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiEstim.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiEstim.Rmd index c8c66e5..0a3d941 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiEstim.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiEstim.Rmd @@ -185,7 +185,7 @@ res_epiestim_group %>% upper ) ) %>% - dplyr::select(-c(sd, lower, upper)) %>% + dplyr::select(-c(sd, lower, upper, count_variable)) %>% rename( "mean $R$" = mean, "median $R$" = median From a6ab15d8126a06c882558362aa2f519ed5432544 Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Fri, 26 Apr 2024 11:23:14 +0100 Subject: [PATCH 43/75] Adding small explanation about what each code chunk is doing for package user --- .../skeleton/rmdchunks/EpiEstim.Rmd | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiEstim.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiEstim.Rmd index 0a3d941..d79402b 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiEstim.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiEstim.Rmd @@ -69,6 +69,8 @@ associated 95% credibility intervals * a table summarising these results for the last `r params$r_estim_window` days ```{r rt-estim-global} +# This code uses the {EpiEstim} function `estimate_R` to generate an estimate of +# the global Rt over time res_epiestim_global <- dat_i_day %>% regroup() %>% get_count_value() %>% @@ -77,7 +79,7 @@ res_epiestim_global <- dat_i_day %>% ``` ```{r rt-plot-global} -# Graph of all values over time +# Plot to visualise the global Rt over time ggplot(res_epiestim_global, aes(x = end)) + geom_ribbon(aes(ymin = lower, ymax = upper), fill = pale_green) + geom_line(aes(y = median), color = dark_green) + @@ -91,7 +93,7 @@ ggplot(res_epiestim_global, aes(x = end)) + ``` ```{r rt-table-global} -# Table +# This code generates a table with Rt values on the last params$r_estim_window res_epiestim_global %>% tail(params$r_estim_window) %>% mutate( @@ -126,7 +128,7 @@ associated 95% credibility intervals * a table with the latest $R_t$ estimates per group, with associated 95% credibility intervals ```{r rt-estim-group} -# Get results by group, keeping only the last 14 days of data +# This code estimates Rt by group_var, keeping only the last 14 days of data res_epiestim_group <- dat_i_day %>% nest(data = c(get_date_index_name(.), get_count_value_name(.))) %>% mutate( @@ -140,7 +142,7 @@ res_epiestim_group <- dat_i_day %>% ``` ```{r rt-plot-group, fig.height = 5 / 3 * n_groups} -# Graph of all values over time +# Plot of Rt estimates for each group_var over time ggplot(res_epiestim_group, aes(x = end)) + geom_ribbon(aes(ymin = lower, ymax = upper), fill = pale_green) + geom_line(aes(y = median), color = dark_green) + @@ -155,7 +157,7 @@ ggplot(res_epiestim_group, aes(x = end)) + ``` ```{r rt-plot-estimates-group} -# Plot of latest estimates +# Plot of latest estimates of Rt for each group_var res_epiestim_group %>% filter(end == max(end)) %>% ggplot(aes(y = .data[[group_var]]), fill = custom_grey) + @@ -174,6 +176,7 @@ res_epiestim_group %>% ``` ```{r rt-table-group} +# This code generates a table with the latest Rt estimates for each group_var res_epiestim_group %>% filter(end == max(end)) %>% mutate( From 250f472c30dd7e14a1e767bbf13fd4940f53b78c Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Fri, 26 Apr 2024 12:07:59 +0100 Subject: [PATCH 44/75] Adding Explanation section to EpiEstim to match i2extras chunk --- .../transmissibility/skeleton/rmdchunks/EpiEstim.Rmd | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiEstim.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiEstim.Rmd index d79402b..2ba1a9a 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiEstim.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiEstim.Rmd @@ -10,6 +10,16 @@ library(EpiEstim) ### Explanations +The package *EpiEstim* is used to estimate the time varying reproduction number, $Rt$, +using a branching process method that requires daily incidence data and an estimate of the disease's serial interval. Through this method, $Rt$ is estimated over weekly sliding windows, i.e., successive overlapping 7-day periods. $Rt$ estimates can be biased by reporting delays. For this reason, this report excludes the last `r params$incomplete_days` days included in the incidence data as incomplete, +and retains a total of `r params$r_estim_window` days to estimate the time varying reproduction number. + + +$Rt$ is defined as the average number of secondary cases that an infected individual would infect if +conditions remained as they were at time _t_. It represents the transmission potential of a disease at a specified timepoint. Observing changes in $Rt$ provides valuable information about variations in transmissibility during an epidemic, and can be used to assess the effectiveness of control interventions aimed at reducing virus transmission. +For more information on *Rt* and its interpretation, see [this paper by the Royal Society](https://royalsociety.org/-/media/policy/projects/set-c/set-covid-19-R-estimates.pdf). + + ### Results ```{r rt-wrappers-prep} From 09a8058cae199a26a4bdeb16f3d82afed0a65ac5 Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Fri, 26 Apr 2024 14:39:10 +0100 Subject: [PATCH 45/75] Adding myself as author of template --- inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd index 804f4c1..f5be56b 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd @@ -1,6 +1,6 @@ --- title: "Estimating transmissibility with population stratification" -author: Thibaut Jombart, Hugo Gruson +author: Thibaut Jombart, Hugo Gruson, Carmen Tamayo date: "`r Sys.Date()`" output: rmarkdown::html_document: From 538d1739c215bdfb11d6d6fcd4dba13930db8d09 Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Fri, 26 Apr 2024 14:44:41 +0100 Subject: [PATCH 46/75] Adding explanation for EpiNow2 to match i2extras --- .../transmissibility/skeleton/rmdchunks/EpiNow2.Rmd | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd index 1f3f510..60b0daa 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd @@ -10,6 +10,13 @@ library(EpiNow2) ### Explanations +The package *EpiNow2* is used to estimate the time-varying reproduction number, $Rt$, using a Bayesian inference method that requires data on observed infections, and an estimate of the generation time, which is approximated using the disease's serial interval distribution. $Rt$ estimates can be biased by reporting delays. For this reason, this report excludes the last `r params$incomplete_days` days included in the incidence data as incomplete, +and retains a total of `r params$r_estim_window` days to estimate the time varying reproduction number. + +$Rt$ is defined as the average number of secondary cases that an infected individual would infect if +conditions remained as they were at time _t_. It represents the transmission potential of a disease at a specified timepoint. Observing changes in $Rt$ provides valuable information about variations in transmissibility during an epidemic, and can be used to assess the effectiveness of control interventions aimed at reducing virus transmission. +For more information on *Rt* and its interpretation, see [this paper by the Royal Society](https://royalsociety.org/-/media/policy/projects/set-c/set-covid-19-R-estimates.pdf). + ### Results ```{r rt-wrappers-prep} From da13d0be52eca57f4aef034ca826ac59bd9cc77f Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Fri, 26 Apr 2024 14:53:06 +0100 Subject: [PATCH 47/75] Adding explanations for the code for pkg users in EpiNow2 chunk --- .../skeleton/rmdchunks/EpiNow2.Rmd | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd index 60b0daa..a0f9633 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd @@ -20,6 +20,8 @@ For more information on *Rt* and its interpretation, see [this paper by the Roya ### Results ```{r rt-wrappers-prep} +# This code takes the serial interval distribution of params$disease_name and +# uses it to approximate the disease's generation time generation_time <- generation_time_opts( dist_spec(pmf = density(si, at = si_x)) ) @@ -37,6 +39,8 @@ associated 95% credibility intervals after excluding the most recent time points in the dataset. ```{r rt-estim-global} +# This code uses {EpiNow2}'s function `epinow()` to estimate Rt over time +# from daily incidence data # Warning, this step will take 2 cores of your computer and may be running # for a long time! res_epinow2_global <- dat_i_day %>% @@ -59,6 +63,7 @@ res_epinow2_global <- dat_i_day %>% ``` ```{r rt-plot-global} +# Plot of Rt values over time for global incidence data (without stratification) plot(res_epinow2_global, "R") + scale_x_date(breaks = scales::pretty_breaks(n = 8), date_label = "%d %b %Y") + theme(axis.text.x = element_text(angle = 45, vjust = 1, hjust = 1)) + @@ -70,10 +75,8 @@ plot(res_epinow2_global, "R") + ``` ```{r rt-table-global} -#This code generates a table that contains Rt estimates for days in the -#dataset (dat_i_day) with complete data, i.e., defined by the parameter -#"params$r_estim_window" - +# This code generates a table that contains Rt estimates for the last +# params$r_estim_window res_epinow2_global$estimates$summarised %>% dplyr::filter(variable == "R") %>% tail(params$r_estim_window) %>% @@ -95,6 +98,10 @@ res_epinow2_global$estimates$summarised %>% #### Transmissibility by group ```{r rt-estim-group, message = FALSE} +# This code uses {EpiNow2}'s function `epinow()` to estimate Rt over time +# from daily incidence data, stratified by group_var +# Warning, this step will take 2 cores of your computer and may be running +# for a long time! res_epinow2_group <- dat_i_day %>% select("date_index", "region", "count") %>% dplyr::rename( @@ -116,6 +123,7 @@ res_epinow2_group <- dat_i_day %>% ``` ```{r rt-plot-group} +# Plot of Rt estimates over time, stratified by group_var res_epinow2_group$summary$plots$R ``` @@ -124,6 +132,7 @@ res_epinow2_group$summary$plots$R ``` ```{r rt-table-group} +# This code generates a table with an overall estimate of Rt per group_var res_epinow2_group$summary$summarised_results$data %>% dplyr::filter(metric == "Effective reproduction no.") %>% dplyr::select(region, mean, median, lower_95, upper_95) %>% From b7beb1888ed86c3755ff108d1d4e344857ebac04 Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Fri, 26 Apr 2024 14:53:48 +0100 Subject: [PATCH 48/75] Removing empty code chunk --- .../templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd | 4 ---- 1 file changed, 4 deletions(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd index a0f9633..2e8cac3 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd @@ -127,10 +127,6 @@ res_epinow2_group <- dat_i_day %>% res_epinow2_group$summary$plots$R ``` -```{r rt-plot-estimates-group} -# Missing for now -``` - ```{r rt-table-group} # This code generates a table with an overall estimate of Rt per group_var res_epinow2_group$summary$summarised_results$data %>% From ffca06d0045d4bf844c7eb2a7c51b4fd05f27ea8 Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Fri, 26 Apr 2024 14:55:08 +0100 Subject: [PATCH 49/75] Adding description of results for the transmissibility by group section in EpiNow2 chunk --- .../transmissibility/skeleton/rmdchunks/EpiNow2.Rmd | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd index 2e8cac3..527c7f8 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd @@ -97,6 +97,12 @@ res_epinow2_global$estimates$summarised %>% #### Transmissibility by group +These analyses present results for stratified incidence, i.e., by `r group_var`. Results include: + +* a graph of the estimates of $R_t$ of the observed data over time, with associated 95% credibility intervals, stratified by `r group_var` + +* a table with $Rt$ estimates for each `r group_var`, excluding the most recent `r params$incomplete_days` days from the available data + ```{r rt-estim-group, message = FALSE} # This code uses {EpiNow2}'s function `epinow()` to estimate Rt over time # from daily incidence data, stratified by group_var From cf29e92ca75eb9127eeddcf8e7e1633b9c848591 Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Fri, 26 Apr 2024 14:56:09 +0100 Subject: [PATCH 50/75] Updating incorrect description of table in global tx section of EpiNow2 chunk --- .../templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd index 527c7f8..9278969 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd @@ -35,8 +35,7 @@ stratification. Results include: * a graph of the estimates of $R_t$ of the observed data over time, with associated 95% credibility intervals -* a table summarising $R_t$ estimates for those dates with complete data, i.e., -after excluding the most recent time points in the dataset. +* a table summarising $Rt$ values for the last `r params$r_estim_window` days of available data ```{r rt-estim-global} # This code uses {EpiNow2}'s function `epinow()` to estimate Rt over time From 6b53b338f369e0257c72fc856205eb86f9d3c8b3 Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Fri, 26 Apr 2024 16:19:07 +0100 Subject: [PATCH 51/75] Adding code to automatically print whether the si has been provided by the author or obtained from {epiparameter} --- .../rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd index f5be56b..fad5bc7 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd @@ -407,8 +407,7 @@ one transmission pair to another, this report characterises this variation using probability distribution. This distribution is a key input to methods used for estimating the reproduction number ($R$). -In this report, the mean and standard deviation of the $si$ have been [provided as an input by the author/ -obtained from a library of epidemiological parameters from the {epiparameter} R package] +In this report, the mean and standard deviation of the $si$ have been `r ifelse(params$use_epiparameter_database, "obtained from a library of epidemiological parameters from the {epiparameter} R package", "provided as an input by the author")`. ## Results From 56757bc76dbcddfbace3f0a7a0322d07dc1403c0 Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Fri, 26 Apr 2024 16:53:35 +0100 Subject: [PATCH 52/75] Removing data preparation section as it didn't contain any text and the chunks of code are now hidden --- inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd | 2 -- 1 file changed, 2 deletions(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd index fad5bc7..4294e32 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd @@ -207,8 +207,6 @@ steps of the report include: knitr::include_graphics("transmissibility_pipeline.svg") ``` -# Data preparation - ```{r, include=FALSE} #The following code loads required packages; missing packages will be installed #automatically, but will require a working internet connection for the From 597dc59d1291154892ea1f6797a1150573074cdc Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Fri, 26 Apr 2024 16:56:25 +0100 Subject: [PATCH 53/75] Modifying Identifying key data section so that variables are only described once and objects can be knitted directly --- .../transmissibility/skeleton/skeleton.Rmd | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd index 4294e32..4300e83 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd @@ -282,15 +282,13 @@ dat_raw <- data_path %>% mutate(across(where(\(x) inherits(x, "POSIXct")), as.Date)) ``` -Once imported into __R__, the dataset called `dat_raw` includes: - -* `date`: the date of [enter description] -* `group`: [enter description of grouping variable, e.g., region, age, gender] -* `n`: number of new cases of [enter description] +Once imported into __R__, the dataset used in this report is named `dat_raw`, and contains the following variables: ```{r} -# This is what the data looks like: -head(dat_raw) +# This is what the data used in this report, `dat_raw`, looks like: +knitr::kable(head(dat_raw), + align = "lccc" +) ``` ## Identifying key data @@ -298,13 +296,6 @@ head(dat_raw) __Note__: this is not used for now, as there is no integration of linelist with other existing tools. -Here we identify the key data needed in the analyses, including: - -* the dates to be used, here, dates of hospital admission -* the strata of the population, here, coarse geographic locations (NHS regions) -* the case counts; this would not be needed if the data was a raw linelist, and - not already aggregated counts - ```{r} # This code identifies key variables for analysis in the input dataset and, # when working with a linelist, uses the package {linelist} to tag columns in @@ -315,6 +306,8 @@ group_var <- "region" # Update count_var to a character string with the name of the column that # contains case counts if your data is already aggregated. count_var <- NULL +# Enter the geographical location where cases in your data took place +country <- "the UK" dat <- dat_raw %>% make_linelist( @@ -322,6 +315,18 @@ dat <- dat_raw %>% location = group_var ) ``` +```{r, include=FALSE} +min_date <- min(dat_raw$date) +max_date <- max(dat_raw$date) +``` + +The data used in this report contains cases of `r params$disease_name` in `r country`, during a time period from `r min_date` to `r max_date`. Cases are stratified by `r group_var`. + +Key variables included in this dataset that are used in this report's analyses include: + +* the dates to be used, here, _dates of hospital admission._ +* the strata of the population, here _coarse geographic locations (NHS regions)._ +* the case data, here `r if (is.null(count_var)){"each case constitutes a row of the dataset."} else {"rows contain the number of cases on each date."}` # Descriptive analyses From 39467e953d4021d1c6332cd4d9f7eb244cfac818 Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Fri, 26 Apr 2024 17:02:21 +0100 Subject: [PATCH 54/75] Improve description of results in "Number of cases" section --- inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd index 4300e83..d3b8c8b 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd @@ -365,7 +365,7 @@ dat_i %>% ## Numbers of cases -This graph shows the total number of cases per group: +This section shows the total number of cases per `r group_var`, as a bar chart and as a table. ```{r } # This code selects relevant variables in the weekly incidence dataset (dat_i), From e666ae97feb46e0e98eee8536f4bbe30a0b8c882 Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Fri, 26 Apr 2024 17:03:10 +0100 Subject: [PATCH 55/75] Replacing text with object that's rendered automatically to indicate the grouping variable in the report --- inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd index d3b8c8b..3fac2d6 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd @@ -332,7 +332,7 @@ Key variables included in this dataset that are used in this report's analyses i ## Epidemic curves -This section creates epidemic curves ("_epicurves_"), with and without stratification by [name of chosen grouping variable]. +This section creates epidemic curves ("_epicurves_"), with and without stratification by `r group_var`. ```{r} # This code converts daily incidence into weekly incidence using {incidence2} From 1c27da73893bbe41abc8439f029db02504e8cf26 Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Fri, 26 Apr 2024 17:11:44 +0100 Subject: [PATCH 56/75] Changing description in "Importing the data" to address the reader --- inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd index 3fac2d6..38fbdc0 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd @@ -282,7 +282,7 @@ dat_raw <- data_path %>% mutate(across(where(\(x) inherits(x, "POSIXct")), as.Date)) ``` -Once imported into __R__, the dataset used in this report is named `dat_raw`, and contains the following variables: +Data used in this report _are available to the reader at https://doi.org/10.1038/s41597-020-0448-0 _, and contains the following variables: ```{r} # This is what the data used in this report, `dat_raw`, looks like: From dd14007479826c2170ac2dacc5b7a819eb95577e Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Fri, 26 Apr 2024 17:12:17 +0100 Subject: [PATCH 57/75] Removing text describing the data since this is now done at section "Identifying key data" --- .../templates/transmissibility/skeleton/skeleton.Rmd | 8 -------- 1 file changed, 8 deletions(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd index 38fbdc0..d62a361 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd @@ -252,14 +252,6 @@ apt install libsodium-dev cmake ## Importing the data -To illustrate the different analyses, we use data reporting daily numbers of -[enter disease name] in [enter location] during [enter timeframe], -and is stratified by [enter region level]. -The data is available from [enter data source]. - -The data file is named "*file_name.rds*" and is located in -the *data/* folder. - ```{r} # To adapt this report to another dataset, change the name of # the file in the `data_file` parameter at the top of this document. From fd556f3597c39ed85bad19504a30230fe679d481 Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Fri, 26 Apr 2024 17:12:51 +0100 Subject: [PATCH 58/75] Fixing typo in EpiEstim chunk --- .../templates/transmissibility/skeleton/rmdchunks/EpiEstim.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiEstim.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiEstim.Rmd index 2ba1a9a..195cd33 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiEstim.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiEstim.Rmd @@ -128,7 +128,7 @@ res_epiestim_global %>% #### Transmissibility by group -These analyses present Rt results for the stratified incidence.Results include: +These analyses present Rt results for the stratified incidence. Results include: * a graph of the estimates of $R_t$ of the observed data over time per group, with associated 95% credibility intervals From b841278fc2b336e5d85289a6ad9fa3ce3fc235de Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Tue, 30 Apr 2024 10:50:47 +0100 Subject: [PATCH 59/75] Removing note about {linelist} not being used --- .../rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd | 3 --- 1 file changed, 3 deletions(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd index d62a361..58eefda 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd @@ -285,9 +285,6 @@ knitr::kable(head(dat_raw), ## Identifying key data -__Note__: this is not used for now, as there is no integration of linelist with -other existing tools. - ```{r} # This code identifies key variables for analysis in the input dataset and, # when working with a linelist, uses the package {linelist} to tag columns in From 63fc5902b3bf35bbcb427054a9702a2b66b3cbe1 Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Tue, 30 Apr 2024 10:51:38 +0100 Subject: [PATCH 60/75] Removing chunk where object "last_date" was created as it is not used in the template --- .../transmissibility/skeleton/skeleton.Rmd | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd index 58eefda..d737299 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd @@ -466,22 +466,6 @@ ggplot( # Growth rate ($r$) and reproduction number ($R$) -```{r} -last_date <- dat %>% - pull(date) %>% - max() - -# version using keep_first and keep_last from i2extras -days_to_keep <- params$incomplete_days + params$r_estim_window -i_recent <- dat_raw %>% - incidence("date", - counts = count_var, - groups = group_var - ) %>% - keep_last(days_to_keep) %>% # keep data for fitting - keep_first(params$r_estim_window) # remove incomplete data -``` - ```{r} # This code creates a dataset with daily incidence data, which is needed for # Rt estimation From c089fc0568d6e8f6f228b1d4d65c5a0be386d27c Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Tue, 30 Apr 2024 10:52:33 +0100 Subject: [PATCH 61/75] Updating EpiEstim explanation to mention effective Rt and clarify which dates are used in the analysis --- .../transmissibility/skeleton/rmdchunks/EpiEstim.Rmd | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiEstim.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiEstim.Rmd index 195cd33..12fb8c1 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiEstim.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiEstim.Rmd @@ -10,9 +10,8 @@ library(EpiEstim) ### Explanations -The package *EpiEstim* is used to estimate the time varying reproduction number, $Rt$, -using a branching process method that requires daily incidence data and an estimate of the disease's serial interval. Through this method, $Rt$ is estimated over weekly sliding windows, i.e., successive overlapping 7-day periods. $Rt$ estimates can be biased by reporting delays. For this reason, this report excludes the last `r params$incomplete_days` days included in the incidence data as incomplete, -and retains a total of `r params$r_estim_window` days to estimate the time varying reproduction number. +The package *EpiEstim* is used to estimate the effective, time-varying reproduction number, $Rt$, +using a branching process method that requires daily incidence data and an estimate of the disease's serial interval. Through this method, $Rt$ is estimated over weekly sliding windows, i.e., successive overlapping 7-day periods. $Rt$ estimates can be biased by reporting delays. For this reason, this report excludes the last `r params$incomplete_days` days included in the incidence data as incomplete, and retains a total of `r params$r_estim_window` days to obtain the most recent estimate of the time varying reproduction number. $Rt$ is defined as the average number of secondary cases that an infected individual would infect if From 44e91117e249c11236023ea03d68f361b77ef488 Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Tue, 30 Apr 2024 10:53:01 +0100 Subject: [PATCH 62/75] Updating Epinow2 explanation to mention effective Rt and clarify which dates are used in the analysis --- .../templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd index 9278969..0ad7637 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd @@ -10,8 +10,8 @@ library(EpiNow2) ### Explanations -The package *EpiNow2* is used to estimate the time-varying reproduction number, $Rt$, using a Bayesian inference method that requires data on observed infections, and an estimate of the generation time, which is approximated using the disease's serial interval distribution. $Rt$ estimates can be biased by reporting delays. For this reason, this report excludes the last `r params$incomplete_days` days included in the incidence data as incomplete, -and retains a total of `r params$r_estim_window` days to estimate the time varying reproduction number. +The package *EpiNow2* is used to estimate the effective, time-varying reproduction number, $Rt$, using a Bayesian inference method that requires data on observed infections, and an estimate of the generation time, which is approximated using the disease's serial interval distribution. $Rt$ estimates can be biased by reporting delays. For this reason, this report excludes the last `r params$incomplete_days` days included in the incidence data as incomplete, +and retains a total of `r params$r_estim_window` days to obtain the most recent estimate of the time varying reproduction number. $Rt$ is defined as the average number of secondary cases that an infected individual would infect if conditions remained as they were at time _t_. It represents the transmission potential of a disease at a specified timepoint. Observing changes in $Rt$ provides valuable information about variations in transmissibility during an epidemic, and can be used to assess the effectiveness of control interventions aimed at reducing virus transmission. From a64a2b8a1803be5166ee0e600fc53864fe33351a Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Tue, 30 Apr 2024 11:32:52 +0100 Subject: [PATCH 63/75] Adding missing column with grouping variable to table displaying growth rates --- .../templates/transmissibility/skeleton/rmdchunks/i2extras.Rmd | 1 + 1 file changed, 1 insertion(+) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/i2extras.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/i2extras.Rmd index 6108f08..d308f56 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/i2extras.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/i2extras.Rmd @@ -102,6 +102,7 @@ last_trends %>% ) ) %>% dplyr::select( + group_var, "Daily growth rate" = r, "Growth rate (95% CI)" = r_ci, "period type", From 4a901bc47a06e50b6a480a02a82ff16496197eb5 Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Tue, 30 Apr 2024 11:33:57 +0100 Subject: [PATCH 64/75] Adding brief description of what each code section is doing in i2extras chunk --- .../skeleton/rmdchunks/i2extras.Rmd | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/i2extras.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/i2extras.Rmd index d308f56..fd4be5f 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/i2extras.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/i2extras.Rmd @@ -46,6 +46,9 @@ intervals (CI) halving time); all results show point estimates and their 95% CI ```{r fig.height = 5 / 3 * n_groups} +# This code uses the {i2extras} function `fit_curve()` to fit a poisson model to +# the epicurves by group_var that represent incidence data for cases included in +# params$data_file last_counts <- dat_i_day %>% keep_last(params$r_estim_window + params$incomplete_days) @@ -64,6 +67,9 @@ plot(last_trends, ``` ```{r} +# This code uses the {i2extras} function `growth_rate()` to estimate and plot +# growth rates for the last params$r_estim_window + params$incomplete_days days +# included in params$data_file last_trends %>% growth_rate() %>% ggplot(aes(y = .data[[group_var]]), fill = custom_grey) + @@ -82,6 +88,9 @@ last_trends %>% x = "Daily rate of change" ) +# This code generates a table where estimated growth rates and doubling/halving +# times are displayed per group_var over the last params$r_estim_window + +# params$incomplete_days days included in params$data_file last_trends %>% growth_rate() %>% dplyr::select(-c(1, 3)) %>% @@ -145,6 +154,9 @@ This section contains: * a table summarizing the estimated distributions of $R$ values ```{r } +# This code generates a violin plot that displays R values per group_var for the +# last params$r_estim_window + params$incomplete_days days included in +# params$data_file res_R_wl <- last_trends %>% mutate(R = map(model, epitrix::lm2R0_sample, w = si$prob_dist$d(si_x))) %>% dplyr::select({{ group_var }}, R) %>% @@ -179,6 +191,9 @@ res_R_wl %>% x = "Reproduction number" ) +# This code generates a table with estimates of the reproduction number by +# group_var for the last params$r_estim_window + params$incomplete_days days +# included in params$data_file res_R_wl_smry %>% mutate( mean = round(mean, 2), From 0d55b0dc666409eb55c94afe9f8092c9a395ca9f Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Tue, 30 Apr 2024 11:38:42 +0100 Subject: [PATCH 65/75] Adding info about grouping variable used to the descriptions of plots/tables in i2extras chunk --- .../transmissibility/skeleton/rmdchunks/i2extras.Rmd | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/i2extras.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/i2extras.Rmd index fd4be5f..5faa48c 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/i2extras.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/i2extras.Rmd @@ -37,13 +37,13 @@ For more information on growth rates, see this [blog post by Pr Julia Gog](https This section contains: -* graphs showing the models fitted to epidemic curves, with their associated 95% confidence +* graphs showing the models fitted to epidemic curves by `r group_var`, with their associated 95% confidence intervals (CI) -* graphs showing the estimates of the growth rates ($r$) with their 95% CI +* graphs showing the estimates of the growth rates ($r$) with their 95% CI for each `r group_var` * a table summarizing estimates of $r$ and the associated period (doubling or - halving time); all results show point estimates and their 95% CI + halving time) for each `r group_var`; all results show point estimates and their 95% CI ```{r fig.height = 5 / 3 * n_groups} # This code uses the {i2extras} function `fit_curve()` to fit a poisson model to @@ -146,12 +146,12 @@ with the provided serial interval. This section contains: * a graph showing the distribution of $R$ values estimated from the daily growth - rates; each violin shows the density of values based on a sample of 500 from + rates by `r group_var`; each violin shows the density of values based on a sample of 500 from the Student distribution associated with the estimate of $r$; the line range represents the 95% confidence interval (horizontal segment) and the median (dot) -* a table summarizing the estimated distributions of $R$ values +* a table summarizing the estimated distributions of $R$ values for each `r group_var` ```{r } # This code generates a violin plot that displays R values per group_var for the From cd158195287f567b41d10cdaabc9f4913e1cd290 Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Tue, 30 Apr 2024 12:43:59 +0100 Subject: [PATCH 66/75] Adding Explanation section to R0 chunk --- .../templates/transmissibility/skeleton/rmdchunks/R0.Rmd | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/R0.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/R0.Rmd index 1ecf36c..cab8d60 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/R0.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/R0.Rmd @@ -10,6 +10,13 @@ library(R0) ### Explanations +The package *R0* is used to estimate the effective, time-varying reproduction number, $Rt$, implementing a time-dependent method, described by [Wallinga and Teunis](https://academic.oup.com/aje/article/160/6/509/79472?login=false). This method requires incidence data and an estimate of the generation time, which here is approximated using the disease's serial interval distribution. +$Rt$ estimates can be biased by reporting delays. For this reason, this report excludes the last `r params$incomplete_days` days included in the incidence data as incomplete. + +$Rt$ is defined as the average number of secondary cases that an infected individual would infect if +conditions remained as they were at time _t_. It represents the transmission potential of a disease at a specified timepoint. Observing changes in $Rt$ provides valuable information about variations in transmissibility during an epidemic, and can be used to assess the effectiveness of control interventions aimed at reducing virus transmission. +For more information on *Rt* and its interpretation, see [this paper by the Royal Society](https://royalsociety.org/-/media/policy/projects/set-c/set-covid-19-R-estimates.pdf). + ### Results ```{r rt-wrappers-prep} From bd20b49985181e33ab43498213c520519cf42f29 Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Tue, 30 Apr 2024 12:45:39 +0100 Subject: [PATCH 67/75] Adding code explanations for user to R0 chunk --- .../transmissibility/skeleton/rmdchunks/R0.Rmd | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/R0.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/R0.Rmd index cab8d60..cb6dd72 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/R0.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/R0.Rmd @@ -20,6 +20,7 @@ For more information on *Rt* and its interpretation, see [this paper by the Roya ### Results ```{r rt-wrappers-prep} +# This code uses the serial interval to approximate the generation time mGT <- generation.time("empirical", si$prob_dist$d(si_x)) # Helper function to get R0 outputs in a tidy format, compatible with pipelines @@ -48,6 +49,8 @@ associated 95% credibility intervals * a table summarising these results for the last `r params$r_estim_window` days ```{r rt-estim-global} +# This code uses the {R0} function `estimate.R()` to generate Rt estimates over +# time using daily incidence data (dat_i_day) res_r0_global <- dat_i_day %>% regroup() %>% mutate(r0_quantiles(estimate.R( @@ -61,6 +64,8 @@ res_r0_global <- dat_i_day %>% ``` ```{r rt-plot-global} +# Plot of global Rt estimates over time for daily incidence data included in +# dat_i_day res_r0_global %>% na.omit() %>% ggplot(aes(x = date_index, y = median, ymin = lower, ymax = upper)) + @@ -76,6 +81,8 @@ res_r0_global %>% ``` ```{r rt-table-global} +# This code generates a table with Rt estimates for the last +# `r params$r_estim_window` days included in dat_i_day res_r0_global %>% tail(params$r_estim_window) %>% mutate( @@ -99,6 +106,8 @@ res_r0_global %>% #### Transmissibility by group ```{r rt-estim-group} +# This code uses the {R0} function `estimate_R()` to obtain Rt estimates by +# group_var over time res_r0_group <- dat_i_day %>% regroup(groups = get_group_names(.)) %>% arrange(date_index) %>% @@ -115,6 +124,7 @@ res_r0_group <- dat_i_day %>% ``` ```{r rt-plot-group} +# Plot of Rt estimates over time by group_var res_r0_group %>% na.omit() %>% ggplot(aes(x = date_index, y = median, ymin = lower, ymax = upper)) + @@ -131,7 +141,7 @@ res_r0_group %>% ``` ```{r rt-plot-estimates-group} -# Plot of latest estimates +# Plot of latest estimates of Rt, defined by params$incompolete_days res_r0_group %>% na.omit() %>% filter(date_index == max(date_index)) %>% @@ -151,6 +161,8 @@ res_r0_group %>% ``` ```{r rt-table-group} +# This code generates a table with latest estimates of Rt, defined by +# params$incomplete_days res_r0_group %>% na.omit() %>% filter(date_index == max(date_index)) %>% From f803057b05b003f4508a23f41cafbc19a6801768 Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Tue, 30 Apr 2024 12:46:14 +0100 Subject: [PATCH 68/75] Adding row.names=FALSE when generating table since these were being printed in the report --- .../templates/transmissibility/skeleton/rmdchunks/R0.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/R0.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/R0.Rmd index cb6dd72..88718a6 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/R0.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/R0.Rmd @@ -99,7 +99,7 @@ res_r0_global %>% "median $R$" = median ) %>% set_names(toupper) %>% - kbl() %>% + kbl(row.names = FALSE) %>% kable_paper("striped", font_size = 18, full_width = FALSE) ``` From 161faafe385122a8442879e7f1eeefe82829b542 Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Tue, 30 Apr 2024 12:57:46 +0100 Subject: [PATCH 69/75] Updating description of Rt estimates per group with latest dates available --- .../templates/transmissibility/skeleton/rmdchunks/R0.Rmd | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/R0.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/R0.Rmd index 88718a6..3350189 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/R0.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/R0.Rmd @@ -141,7 +141,7 @@ res_r0_group %>% ``` ```{r rt-plot-estimates-group} -# Plot of latest estimates of Rt, defined by params$incompolete_days +# Plot of latest estimates of Rt by group_var res_r0_group %>% na.omit() %>% filter(date_index == max(date_index)) %>% @@ -161,8 +161,7 @@ res_r0_group %>% ``` ```{r rt-table-group} -# This code generates a table with latest estimates of Rt, defined by -# params$incomplete_days +# This code generates a table with latest estimates of Rt by group_var res_r0_group %>% na.omit() %>% filter(date_index == max(date_index)) %>% From db845016fe6eced201f590df487c5c1b95cfa695 Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Tue, 30 Apr 2024 12:58:09 +0100 Subject: [PATCH 70/75] Adding brief description of transmissibility by group results in R0 chunk --- .../templates/transmissibility/skeleton/rmdchunks/R0.Rmd | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/R0.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/R0.Rmd index 3350189..b316f00 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/R0.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/R0.Rmd @@ -105,6 +105,15 @@ res_r0_global %>% #### Transmissibility by group +These analyses present results for incidence stratified by `r group_var`. Results in this section include: + +* a graph of the estimates of $R_t$ of the observed data over time for each `r group_var`, with +associated 95% credibility intervals + +* a plot with the latest $R_t$ results by `r group_var` + +* a table with the latest $R_t$ estimates by `r group_var` + ```{r rt-estim-group} # This code uses the {R0} function `estimate_R()` to obtain Rt estimates by # group_var over time From 3778eaa3563daf5ee1f99a483d4e1da318030952 Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Thu, 2 May 2024 10:24:16 +0100 Subject: [PATCH 71/75] Update inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd Co-authored-by: Hugo Gruson <10783929+Bisaloo@users.noreply.github.com> --- .../templates/transmissibility/skeleton/skeleton.Rmd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd index d737299..a1a2d0f 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd @@ -305,8 +305,8 @@ dat <- dat_raw %>% ) ``` ```{r, include=FALSE} -min_date <- min(dat_raw$date) -max_date <- max(dat_raw$date) +min_date <- min(dat_raw[[date_var]]) +max_date <- max(dat_raw[[date_var]]) ``` The data used in this report contains cases of `r params$disease_name` in `r country`, during a time period from `r min_date` to `r max_date`. Cases are stratified by `r group_var`. From 9f8064489ea51dd360874965f3d5e04aaf01b920 Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Thu, 2 May 2024 10:47:37 +0100 Subject: [PATCH 72/75] Using kbl for better output of data heade --- .../templates/transmissibility/skeleton/skeleton.Rmd | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd index a1a2d0f..d5256c6 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd @@ -278,9 +278,9 @@ Data used in this report _are available to the reader at https://doi.org/10.1038 ```{r} # This is what the data used in this report, `dat_raw`, looks like: -knitr::kable(head(dat_raw), - align = "lccc" -) +head(dat_raw) %>% + kbl() %>% + kable_styling() ``` ## Identifying key data From 367ccc31158d25c380cf63c2af78c5db69ea618f Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Thu, 2 May 2024 10:50:28 +0100 Subject: [PATCH 73/75] Removing include=FALSE to make all rmd chunks visible to reader again --- .../templates/transmissibility/skeleton/skeleton.Rmd | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd index d5256c6..a2a28b9 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/skeleton.Rmd @@ -203,11 +203,11 @@ steps of the report include: * estimating the growth rate and doubling time from epidemic curves * estimating the instantaneous reproduction number from epidemic curves -```{r, include=FALSE} +```{r} knitr::include_graphics("transmissibility_pipeline.svg") ``` -```{r, include=FALSE} +```{r} #The following code loads required packages; missing packages will be installed #automatically, but will require a working internet connection for the #installation to be successful. @@ -226,7 +226,7 @@ library(epiparameter) library(incidence2) ``` -```{r, include=FALSE} +```{r} custom_grey <- "#505B5B" green_grey <- "#5E7E80" pale_green <- "#B2D1CC" From 65dbb1128fd20ac91346060c51ac9c51990c8e86 Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Thu, 2 May 2024 12:13:18 +0100 Subject: [PATCH 74/75] Increasing fig.height for Rt estimates by group_var in RO chunk --- .../templates/transmissibility/skeleton/rmdchunks/R0.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/R0.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/R0.Rmd index b316f00..9640308 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/R0.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/R0.Rmd @@ -132,7 +132,7 @@ res_r0_group <- dat_i_day %>% ) ``` -```{r rt-plot-group} +```{r rt-plot-group, fig.height=15} # Plot of Rt estimates over time by group_var res_r0_group %>% na.omit() %>% From c2dcaf9d30b08ea0ec668393d5864a688a3c856e Mon Sep 17 00:00:00 2001 From: CarmenTamayo Date: Tue, 28 May 2024 09:59:34 +0100 Subject: [PATCH 75/75] Update inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd Co-authored-by: Hugo Gruson <10783929+Bisaloo@users.noreply.github.com> --- .../templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd index 0ad7637..87bb26d 100644 --- a/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd +++ b/inst/rmarkdown/templates/transmissibility/skeleton/rmdchunks/EpiNow2.Rmd @@ -110,7 +110,7 @@ These analyses present results for stratified incidence, i.e., by `r group_var`. res_epinow2_group <- dat_i_day %>% select("date_index", "region", "count") %>% dplyr::rename( - confirm = .data[["count"]], + confirm = count, date = date_index, region = .data[[group_var]] ) %>%