Skip to content

Commit

Permalink
Spatial branch for merge of main (#152)
Browse files Browse the repository at this point in the history
* Adding class and methods for wwinference model fit (#58)

* Starting off refactoring (expected to fail) [skip ci]

* Adding new method

* Fixing bug in fit_model (was exploiting scoping)

* Updating docs (fixing S3 methods)

* 49 output class creation (#59)

* add a space

* add first test of first check

* add tests for all of the check/assert functions

* run precommit

* check bug in passing output of checkmate to cliabort

* initial tests of preprocess_ww_data

* add custum utils function for autoescaping brackets to pass to glue

* add a bunch of tests for preprocessing wastewater data

* add one more test of site lab indexing

* fix bugs caught in CI

* fix lab site spacing

* fix spacing in name again

* add test to hospital admissions preprocessing

* add additional test to ensure character to indexing of sites and labs

* remove bug in expected number of unique lab site indices

* add tests to make sure data is daily and test to checkers

* add a bunch of validation checks to the joint datasets and the user specifications

* replace with new way of getting stan data

* fix examples, add test, add warning

* fix examples, add test, add warning

* change from hosp -> count everywhere except stan and  vignette/examples

* add tests for pmfs

* fix bugs in documentation

* add padding value as a function arg

* change pmf size check to a warning not an error

* fix bug

* make initialization function more generic

* update changelog

* modify to test

* fix typo from merge

* fix parsing of cmdstan object

* change parsing of fit obj

* Update R/checkers.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update R/checkers.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update R/checkers.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update R/checkers.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update R/checkers.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update R/checkers.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update R/checkers.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update R/checkers.R

Co-authored-by: Dylan H. Morris <[email protected]>

* some tweaks to checkers

* Update R/checkers.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update R/checkers.R

Co-authored-by: Dylan H. Morris <[email protected]>

* fix documentation

* fix typo

* fix typo

* change outputs from wwinference() function

* fix typos, add documentation

* fix bug missing stan args

* exclude t columns in data join

* fix vignette bug

* add the ww_output documentation

* document ...

* fix missing comma

* move documentation of params around

* Update R/checkers.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update R/checkers.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update R/checkers.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update R/checkers.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update R/checkers.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update R/checkers.R

Co-authored-by: Dylan H. Morris <[email protected]>

* change syntax and filenames

* Update R/preprocessing.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update R/wwinference.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update R/wwinference.R

Co-authored-by: Dylan H. Morris <[email protected]>

* change naming and internal checking

* change syntax

* move around documentation

* fix check

* fix tests, fix documentation

* rename assert function to specify within a certain frame

* add element to text

* fix bug in function name

* tweak to inference function

* fix two bugs

* adjust tests based on updated get stan data function which breaks up generation of input data

* Update get_stan_data.R example

* update documentation after fixing example

* add example to wwinference wrapper function

* attempt to move around documentation for wwinference methods

* play around with the documentation of the default and the S3 method functions

* export S3 method function

* add back in exporting functions to get input data formatted for stan

* make first argument of function have same name as class object

* fix bug in how max generation time is found

* update vignette to explain wwinference_fit class object vs explicit function calling, add diagnostics and show both ways

* fix naming blocks adding comma when needed

* dont export autoescape brackets function

* fix same bug

* update test and preprocessing to count at LOD values at below LOD

* fix internal call to diagnostic flags function

* Update R/validate.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update tests/testthat/test_preprocess_count_data.R

Co-authored-by: Dylan H. Morris <[email protected]>

* implement DMs suggestions

* run pre-commit

* export default functions

* Add test-coverage.yaml from epinowcast

* remove test coverage

* remove example, function not exported

* export default function

* export both diagnostics functions

* add documentation of additional arguments

* Update R/validate.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update R/validate.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update R/validate.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update tests/testthat/test_checkers.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update tests/testthat/test_checkers.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update tests/testthat/test_preprocess_count_data.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update tests/testthat/test_preprocess_ww_data.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update R/validate.R

Co-authored-by: Dylan H. Morris <[email protected]>

* manually input some suggestions

* Update tests/testthat/test_checkers.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update tests/testthat/test_checkers.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update tests/testthat/test_preprocess_count_data.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update tests/testthat/test_preprocess_count_data.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update tests/testthat/test_preprocess_count_data.R

Co-authored-by: Dylan H. Morris <[email protected]>

* add more checknames

* run pre-commit locally

* fix typo

* add some very minimal tests

* fix wwinference function

* fix bug

* fix bug

* Update tests/testthat/test_preprocess_count_data.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update tests/testthat/test_preprocess_count_data.R

Co-authored-by: Dylan H. Morris <[email protected]>

* run pre-commit locally

* fix bugs in tests

* fix error in tests

* move forecast date, calib time, horizon time to args to wrapper function

* fix hosp only example in vignette

* fix error in example

* add dont run to examples

* check -> expect in checkmate, confirm tests pass locally

---------

Co-authored-by: Dylan H. Morris <[email protected]>
Co-authored-by: George G. Vega Yon <[email protected]>

* Making pre-commit happy

* Reworking cross-references and print method

* Removing copy of fit_model

* Fixing function call

* Addressing PR comments

* Forgot to save some changes

* Change output names (#86)

* change names of outputs of wwinference wrapper function

* fix a few other missed replacements

* fix pre-commit

* Fixing R CMD check

* Pre-commit

* Removing diagnostics_summary

---------

Co-authored-by: George G. Vega Yon <[email protected]>

* Update vignettes/wwinference.Rmd

Co-authored-by: Kaitlyn Johnson <[email protected]>

* Update vignettes/wwinference.Rmd

Co-authored-by: Kaitlyn Johnson <[email protected]>

* Adding example of summary and print in the vignette. Addressing some minor comments

* fix test for expected names after changing function args

* set seed in tests

---------

Co-authored-by: Kaitlyn Johnson <[email protected]>
Co-authored-by: Dylan H. Morris <[email protected]>
Co-authored-by: kaitejohnson <[email protected]>

* Addressing R CMD check notes due to tidyeval syntax (#108)

* Starting to use .data and others

* Removing more warnings

* Think almost all issues are now solved

* License warning and passing params as expected

* Removing  prefix

* Fixing note on license and news file

* Using str2lang in spread_draws

* Update R/get_draws_df.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Fixing R CMD check

* fixed intercept in figures

* Update R/generate_simulated_data.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Apply suggestions from code review by @dylanhmorris

Co-authored-by: Dylan H. Morris <[email protected]>

* Update R/preprocessing.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update R/get_stan_data.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update R/preprocessing.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update R/preprocessing.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update R/preprocessing.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update R/preprocessing.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update R/preprocessing.R

Co-authored-by: Dylan H. Morris <[email protected]>

* remove call to utils::globalVariables()

* Update R/preprocessing.R

* Update R/generate_simulated_data.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update R/preprocessing.R

Co-authored-by: Dylan H. Morris <[email protected]>

* Update R/get_stan_data.R

Co-authored-by: Dylan H. Morris <[email protected]>

---------

Co-authored-by: Dylan H. Morris <[email protected]>
Co-authored-by: Kaitlyn Johnson <[email protected]>
Co-authored-by: kaitejohnson <[email protected]>

* update hierarchical estimate of sigma_site in `model_definition` (#120)

* add a space

* update hierarchical estimate of sigma_site

* update prior table

* run pre-commit

* update comment when transforming to site level standard deviations

* add to change log

* Update inst/stan/wwinference.stan

Co-authored-by: Dylan H. Morris <[email protected]>

* Update model_definition.md

Co-authored-by: Dylan H. Morris <[email protected]>

* Update model_definition.md

Co-authored-by: Dylan H. Morris <[email protected]>

* Update model_definition.md

Co-authored-by: Dylan H. Morris <[email protected]>

* update notation for mode and sd of stdevs

* Update model_definition.md

Co-authored-by: Dylan H. Morris <[email protected]>

* Update model_definition.md

Co-authored-by: Dylan H. Morris <[email protected]>

* Update model_definition.md

Co-authored-by: Dylan H. Morris <[email protected]>

* tweaks to formatting

* Update model_definition.md

Co-authored-by: Dylan H. Morris <[email protected]>

---------

Co-authored-by: Dylan H. Morris <[email protected]>

* Vignette tweaks (#141)

* fix typo in indicate ww exclusions documentation

* fix typos/language in vignette

* Update R/preprocessing.R

Co-authored-by: Chirag Kumar <[email protected]>

* update docs

---------

Co-authored-by: Chirag Kumar <[email protected]>

* actually set seed

* Set seeds in test_get_stan_data (#146)

Co-authored-by: Kaitlyn Johnson <[email protected]>

* Modify package to expect log scale concentration values and LODs (#122)

* Tweaks to model definition (#134)

* Fix check for required wastewater columns (#127)

* Switch to placing prior on and inferring `i/n` at the first observed timepoint (#85)

* update vignette to reflect default NULL seed in mcmcoptions (#125)

* Fix NEWS.md (#126)

* hot fix to readme

* Update NEWS.md

* run pre-commit

* Update NEWS.md (#144)

* run pre-commit locally

* Update NEWS.md

---------

Co-authored-by: George G. Vega Yon <[email protected]>

* 2024-09-09 update : fixing check-package error.

* 2024-09-09 update : fixing check-package error.

* 2024-09-09 update : removing test_ww_model.

---------

Co-authored-by: George G. Vega Yon <[email protected]>
Co-authored-by: Kaitlyn Johnson <[email protected]>
Co-authored-by: Dylan H. Morris <[email protected]>
Co-authored-by: kaitejohnson <[email protected]>
Co-authored-by: Chirag Kumar <[email protected]>
  • Loading branch information
6 people authored Sep 9, 2024
1 parent d6b5155 commit a6d1d10
Show file tree
Hide file tree
Showing 66 changed files with 1,503 additions and 798 deletions.
12 changes: 12 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,15 @@
^\.github$
^.*\.Rproj$
^\.Rproj\.user$

# Misc
^data-raw$
^model_definition\.md$
^scratch$

# Hidden files/folders
^\..+

# Because R doesn't like having a copy of this
# type of license in the package.
LICENSE
14 changes: 14 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Generated by roxygen2: do not edit by hand

S3method(get_draws_df,data.frame)
S3method(get_draws_df,default)
S3method(get_draws_df,wwinference_fit)
S3method(get_model_diagnostic_flags,default)
S3method(get_model_diagnostic_flags,wwinference_fit)
S3method(print,wwinference_fit)
S3method(summary,wwinference_fit)
export(add_pmfs)
export(add_time_indexing)
export(calc_rt)
Expand Down Expand Up @@ -32,6 +39,7 @@ export(get_ww_data_sizes)
export(get_ww_values)
export(independence_corr_func)
export(indicate_ww_exclusions)
export(parameter_diagnostics)
export(preprocess_count_data)
export(preprocess_ww_data)
export(spatial_rt_process)
Expand All @@ -58,13 +66,15 @@ importFrom(dplyr,ungroup)
importFrom(expm,sqrtm)
importFrom(fs,path_package)
importFrom(ggplot2,aes)
importFrom(ggplot2,element_text)
importFrom(ggplot2,facet_grid)
importFrom(ggplot2,facet_wrap)
importFrom(ggplot2,geom_bar)
importFrom(ggplot2,geom_hline)
importFrom(ggplot2,geom_line)
importFrom(ggplot2,geom_point)
importFrom(ggplot2,geom_ribbon)
importFrom(ggplot2,geom_step)
importFrom(ggplot2,geom_vline)
importFrom(ggplot2,ggplot)
importFrom(ggplot2,ggtitle)
Expand All @@ -74,9 +84,13 @@ importFrom(ggplot2,scale_fill_discrete)
importFrom(ggplot2,scale_x_date)
importFrom(ggplot2,scale_y_continuous)
importFrom(ggplot2,theme)
importFrom(ggplot2,theme_bw)
importFrom(ggplot2,xlab)
importFrom(ggplot2,ylab)
importFrom(lubridate,ymd)
importFrom(posterior,as_draws_list)
importFrom(posterior,subset_draws)
importFrom(rlang,.data)
importFrom(rlang,sym)
importFrom(stats,dnbinom)
importFrom(stats,dweibull)
Expand Down
22 changes: 12 additions & 10 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# wwinference
# wwinference 0.0.1 (dev)

This will serve as our change-log

- Add functionality to fit the wastewater-informed model to an example fitting COVID-19 hospital admissions and wastewater from a few sites
- Implemented forward simulation of spatially correlated subpopulations given a distance matrix, to be added as an option in the generate_simulated_data() function
- 2024-07-12: Add functionality to fit the wastewater-informed model to an example fitting COVID-19 hospital admissions and wastewater from a few sites
- 2024-07-19: Add an example in the vignette to fit the model to only the hospital admissions. Plus a few small tweaks to the vignette.
- 2024-08-05: Add input data validation with informative error messaging
- 2024-08-09: Add testing and additional validation of the data being passed into the model
- 2024-08-22: Update `generate_simulated_data()` function to modularize the model components, adding additional
forward simulation functions.
This is the first major release, focused on providing an initial version of the package.
Note the package is still flagged as in development, though the authors plan on using it for production work in the coming weeks.
As it's written, the package is intended to allow users to do the following:

- Provide basic functionality to fit the wastewater-informed model to an example fitting COVID-19 hospital admissions and wastewater from a few sites ([#5](https://github.com/CDCgov/ww-inference-model/issues/5))
- Performs basic post-processing and plotting of data and modeled outputs, including calibrated, nowcasted, and forecasted count data (in the example, hospital admissions), wastewater concentrations, global R(t) estimates and subpopulation-level R(t) estimates
- Provide an example in the vignette to fit the model to only the hospital admissions ([#24](https://github.com/CDCgov/ww-inference-model/issues/24))
- Validate input data validation with informative error messaging ([#37](https://github.com/CDCgov/ww-inference-model/issues/37), [#54](https://github.com/CDCgov/ww-inference-model/issues/54))
- Provide a wrapper function to generate forward simulated data with user-specified variables. It calls a number of functions to perform specific model components ([#27](https://github.com/CDCgov/ww-inference-model/issues/27))
- Contains S3 class methods applied to the output of the main model wrapper function, the `wwinference_fit` class object ([#58](https://github.com/CDCgov/ww-inference-model/issues/58)).
- Wastewater concentration data is expected to be in log scale ([#122](https://onetakeda.box.com/s/pju273g5khx3y3cwoae2zwv3e7vu03x3)).
39 changes: 18 additions & 21 deletions R/checkers.R
Original file line number Diff line number Diff line change
Expand Up @@ -292,22 +292,18 @@ throw_type_error <- function(object,
#' traceback.
#'
#' @return NULL, invisibly
check_req_ww_cols_present <- function(ww_data,
conc_col_name,
lod_col_name,
add_req_col_names = c(
"date", "site",
"lab", "site_pop"
),
call = rlang::caller_env()) {
assert_req_ww_cols_present <- function(ww_data,
conc_col_name,
lod_col_name,
add_req_col_names = c(
"date", "site",
"lab", "site_pop"
),
call = rlang::caller_env()) {
column_names <- colnames(ww_data)
expected_col_names <- c(
{
conc_col_name
},
{
lod_col_name
},
{{ conc_col_name }},
{{ lod_col_name }},
add_req_col_names
)

Expand All @@ -317,10 +313,11 @@ check_req_ww_cols_present <- function(ww_data,
)
if (!isTRUE(name_check_result)) {
cli::cli_abort(
message = c(
"Required columns are missing from the wastewater data. ",
autoescape_brackets(name_check_result)
),
message =
c(
"Required columns are missing from the wastewater data. ",
autoescape_brackets(name_check_result)
),
class = "wwinference_input_data_error",
call = call
)
Expand Down Expand Up @@ -582,10 +579,10 @@ assert_equivalent_indexing <- function(first_data,
call = rlang::caller_env(),
add_err_msg = "") {
first_index <- first_data |>
dplyr::distinct(date, t)
dplyr::distinct(.data$date, .data$t)
second_index <- second_data |>
dplyr::distinct(date, t) |>
dplyr::rename(second_t = t)
dplyr::distinct(.data$date, .data$t) |>
dplyr::rename("second_t" = "t")


test_df <- first_index |>
Expand Down
2 changes: 1 addition & 1 deletion R/compile_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#' This function reads in and optionally compiles a Stan model.
#' It is written to search the installed package `stan` directory
#' for additional source files to include. Within each stan file,
#' use #include {path to your file with the `stan` directory}.stan
#' use `#include {path to your file with the stan directory}.stan`
#'
#'
#' @details The code for this function has been adapted
Expand Down
27 changes: 14 additions & 13 deletions R/data.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#' Example wastewater dataset with site correlations from exp. corr. func.
#'
#' A dataset containing the simulated wastewater concentrations
#' (labeled here as `genome_copies_per_ml`) by sample collection date (`date`),
#' the site where the sample was collected (`site`) and the lab where the
#' samples were processed (`lab`). Additional columns that are required
#' attributes needed for the model are the limit of detection for that lab on
#' each day (labeled here as `lod`) and the population size of the wastewater
#' catchment area represented by the wastewater concentrations in each `site`.
#' (labeled here as `log_genome_copies_per_ml`) by sample collection date
#' (`date`), the site where the sample was collected (`site`) and the lab
#' where the samples were processed (`lab`). Additional columns that are
#' required attributes needed for the model are the limit of detection for
#' that lab on each day (labeled here as `log_lod`) and the population size of
#' the wastewater catchment area represented by the wastewater concentrations
#' in each `site`.
#'
#' This data is generated via the default values in the
#' `generate_simulated_data()` function. They represent the bare minumum
Expand All @@ -22,13 +23,13 @@
#' YYYY-MM-DD}
#' \item{site}{The wastewater treatment plant where the sample was collected}
#' \item{lab}{The lab where the sample was processed}
#' \item{genome_copies_per_ml}{The wastewater concentration measured on the
#' date specified, collected in the site specified, and processed in the lab
#' specified. The default parameters assume that this quantity is reported
#' as the genome copies per mL, on a natural scale.}
#' \item{lod}{The limit of detection in the site and lab on a particular day
#' of the quantification device (e.g. PCR). This is also by default reported
#' in terms of the genome copies per mL.}
#' \item{log_genome_copies_per_ml}{The natural log of the wastewater
#' concentration measured on the date specified, collected in the site
#' specified, and processed in the lab specified. The package expects
#' this quantity in units of log estimated genome copies per mL.}
#' \item{log_lod}{The log of the limit of detection in the site and lab on a
#' particular day of the quantification device (e.g. PCR). This should be in
#' units of log estimated genome copies per mL.}
#' \item{site_pop}{The population size of the wastewater catchment area
#' represented by the site variable}
#' }
Expand Down
2 changes: 1 addition & 1 deletion R/delay_distribs.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' Simulate daily double censored PMF. From {epinowcast}:
#' Simulate daily double censored PMF. From epinowcast:
#' https://package.epinowcast.org/dev/reference/simulate_double_censored_pmf.html #nolint
#'
#' This function simulates the probability mass function of a daily
Expand Down
55 changes: 30 additions & 25 deletions R/figures.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,23 @@ get_plot_forecasted_counts <- function(draws,
sampled_draws <- sample(1:max(draws$draw), n_draws_to_plot)

draws_to_plot <- draws |> dplyr::filter(
name == "pred_counts",
draw %in% !!sampled_draws
.data$name == "predicted counts",
.data$draw %in% !!sampled_draws
)

p <- ggplot(draws_to_plot) +
geom_line(aes(x = date, y = pred_value, group = draw),
geom_line(
aes(x = .data$date, y = .data$pred_value, group = .data$draw),
color = "red4", alpha = 0.1, linewidth = 0.2
) +
geom_point(
data = count_data_eval,
aes(x = date, y = .data[[count_data_eval_col_name]]),
aes(x = .data$date, y = .data[[count_data_eval_col_name]]),
shape = 21, color = "black", fill = "white"
) +
geom_point(aes(x = date, y = observed_value)) +
geom_vline(aes(xintercept = lubridate::ymd(forecast_date)),
geom_point(aes(x = .data$date, y = .data$observed_value)) +
geom_vline(
xintercept = lubridate::ymd(forecast_date),
linetype = "dashed"
) +
xlab("") +
Expand Down Expand Up @@ -95,8 +97,8 @@ get_plot_ww_conc <- function(draws,

draws_to_plot <- draws |>
dplyr::filter(
name == "pred_ww",
draw %in% !!sampled_draws
.data$name == "predicted wastewater",
.data$draw %in% !!sampled_draws
) |>
dplyr::mutate(
site_lab_name = glue::glue("{subpop}, Lab: {lab}")
Expand All @@ -105,22 +107,23 @@ get_plot_ww_conc <- function(draws,
p <- ggplot(draws_to_plot) +
geom_line(
aes(
x = date, y = log(pred_value),
color = subpop,
group = draw
x = .data$date, y = .data$pred_value,
color = .data$subpop,
group = .data$draw
),
alpha = 0.1, linewidth = 0.2,
show.legend = FALSE
) +
geom_point(aes(x = date, y = log(observed_value)),
geom_point(aes(x = .data$date, y = .data$observed_value),
color = "black", show.legend = FALSE
) +
facet_wrap(~site_lab_name, scales = "free") +
geom_vline(aes(xintercept = lubridate::ymd(forecast_date)),
geom_vline(
xintercept = lubridate::ymd(forecast_date),
linetype = "dashed"
) +
xlab("") +
ylab("Log(Genome copies/mL)") +
ylab("Log genome copies/mL") +
ggtitle("Lab-site level wastewater concentration") +
scale_x_date(
date_breaks = "2 weeks",
Expand Down Expand Up @@ -163,17 +166,18 @@ get_plot_global_rt <- function(draws,
sampled_draws <- sample(1:max(draws$draw), n_draws_to_plot)

draws_to_plot <- draws |> dplyr::filter(
name == "global R(t)",
draw %in% !!sampled_draws
.data$name == "global R(t)",
.data$draw %in% !!sampled_draws
)

# R(t) timeseries
p <- ggplot(draws_to_plot) +
ggplot2::geom_step(
aes(x = date, y = pred_value, group = draw),
geom_step(
aes(x = .data$date, y = .data$pred_value, group = .data$draw),
color = "blue4", alpha = 0.1, linewidth = 0.2
) +
geom_vline(aes(xintercept = lubridate::ymd(forecast_date)),
geom_vline(
xintercept = lubridate::ymd(forecast_date),
linetype = "dashed"
) +
geom_hline(aes(yintercept = 1), linetype = "dashed") +
Expand Down Expand Up @@ -221,20 +225,21 @@ get_plot_subpop_rt <- function(draws,
sampled_draws <- sample(1:max(draws$draw), n_draws_to_plot)

draws_to_plot <- draws |> dplyr::filter(
name == "subpop R(t)",
draw %in% !!sampled_draws
.data$name == "subpopulation R(t)",
.data$draw %in% !!sampled_draws
)

p <- ggplot(draws_to_plot) +
ggplot2::geom_step(
geom_step(
aes(
x = date, y = pred_value, group = draw,
color = subpop
x = .data$date, y = .data$pred_value, group = .data$draw,
color = .data$subpop
),
alpha = 0.1, linewidth = 0.2,
show.legend = FALSE
) +
geom_vline(aes(xintercept = lubridate::ymd(forecast_date)),
geom_vline(
xintercept = lubridate::ymd(forecast_date),
linetype = "dashed",
show.legend = FALSE
) +
Expand Down
Loading

0 comments on commit a6d1d10

Please sign in to comment.