Skip to content

Commit

Permalink
replace get functions with examples
Browse files Browse the repository at this point in the history
  • Loading branch information
sbfnk committed Oct 10, 2023
1 parent 7db4b0e commit 08c0646
Show file tree
Hide file tree
Showing 24 changed files with 93 additions and 251 deletions.
19 changes: 5 additions & 14 deletions R/epinow.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,11 @@
#' # set number of cores to use
#' old_opts <- options()
#' options(mc.cores = ifelse(interactive(), 4, 1))
#' # construct example distributions
#' generation_time <- get_generation_time(
#' disease = "SARS-CoV-2", source = "ganyani"
#' )
#' incubation_period <- get_incubation_period(
#' disease = "SARS-CoV-2", source = "lauer"
#' )
#' reporting_delay <- dist_spec(
#' mean = convert_to_logmean(2, 1),
#' mean_sd = 0.1,
#' sd = convert_to_logsd(2, 1),
#' sd_sd = 0.1,
#' max = 10
#' )
#'
#' # get example delays
#' generation_time <- example_generation_time
#' incubation_period <- example_incubation_period
#' reporting_delay <- example_reporting_delay
#'
#' # example case data
#' reported_cases <- example_confirmed[1:40]
Expand Down
20 changes: 4 additions & 16 deletions R/estimate_infections.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,10 @@
#' # get example case counts
#' reported_cases <- example_confirmed[1:60]
#'
#' # set up example generation time
#' generation_time <- get_generation_time(
#' disease = "SARS-CoV-2", source = "ganyani", fixed = TRUE
#' )
#' # set delays between infection and case report
#' incubation_period <- get_incubation_period(
#' disease = "SARS-CoV-2", source = "lauer", fixed = TRUE
#' )
#' # delays between infection and case report, with uncertainty
#' incubation_period_uncertain <- get_incubation_period(
#' disease = "SARS-CoV-2", source = "lauer"
#' )
#' reporting_delay <- dist_spec(
#' mean = convert_to_logmean(2, 1), mean_sd = 0,
#' sd = convert_to_logsd(2, 1), sd_sd = 0, max = 10
#' )
#' # get example delays
#' generation_time <- example_generation_time
#' incubation_period <- example_incubation_period
#' reporting_delay <- example_reporting_delay
#'
#' # for more examples, see the "estimate_infections examples" vignette
#' def <- estimate_infections(reported_cases,
Expand Down
4 changes: 2 additions & 2 deletions R/opts.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
#' dist_spec(mean = 3, sd = 2, mean_sd = 1, sd_sd = 0.5, max = 15)
#' )
#'
#' # A generation time sourced from the literature
#' dist <- get_generation_time(disease = "SARS-CoV-2", source = "ganyani")
#' # An example generation time
#' dist <- example_generation_time
#' generation_time_opts(dist)
generation_time_opts <- function(dist = dist_spec(mean = 1), ...,
disease, source, max = 15L, fixed = FALSE,
Expand Down
17 changes: 4 additions & 13 deletions R/regional_epinow.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,10 @@
#' old_opts <- options()
#' options(mc.cores = ifelse(interactive(), 4, 1))
#'
#' # construct example distributions
#' generation_time <- get_generation_time(
#' disease = "SARS-CoV-2", source = "ganyani"
#' )
#' incubation_period <- get_incubation_period(
#' disease = "SARS-CoV-2", source = "lauer"
#' )
#' reporting_delay <- dist_spec(
#' mean = convert_to_logmean(2, 1),
#' mean_sd = 0.1,
#' sd = convert_to_logsd(2, 1),
#' sd_sd = 0.1, max = 15
#' )
#' # use example distributions
#' generation_time <- example_generation_time
#' incubation_period <- example_incubation_period
#' reporting_delay <- example_reporting_delay
#'
#' # uses example case vector
#' cases <- example_confirmed[1:60]
Expand Down
15 changes: 4 additions & 11 deletions R/report.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,10 @@
#' # define example cases
#' cases <- example_confirmed[1:40]
#'
#' # set up example delays
#' generation_time <- get_generation_time(
#' disease = "SARS-CoV-2", source = "ganyani"
#' )
#' incubation_period <- get_incubation_period(
#' disease = "SARS-CoV-2", source = "lauer"
#' )
#' reporting_delay <- dist_spec(
#' mean = convert_to_logmean(2, 1), mean_sd = 0.1,
#' sd = convert_to_logsd(2, 1), sd_sd = 0.1, max = 10
#' )
#' # get example delays
#' generation_time <- example_generation_time
#' incubation_period <- example_incubation_period
#' reporting_delay <- example_reporting_delay
#'
#' # Instead of running them model we use example
#' # data for speed in this example.
Expand Down
15 changes: 4 additions & 11 deletions R/simulate_infections.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,11 @@
#' # get example case counts
#' reported_cases <- example_confirmed[1:50]
#'
#' # set up example generation time
#' generation_time <- get_generation_time(
#' disease = "SARS-CoV-2", source = "ganyani"
#' )
#' # use example generation times provided with the package
#' generation_time <- example_generation_time
#' # set delays between infection and case report
#' incubation_period <- get_incubation_period(
#' disease = "SARS-CoV-2", source = "lauer"
#' )
#' reporting_delay <- dist_spec(
#' mean = convert_to_logmean(2, 1), mean_sd = 0.1,
#' sd = convert_to_logsd(2, 1), sd_sd = 0.1, max = 15
#' )
#' incubation_period <- example_incubation_period
#' reporting_delay <- example_reporting_delay
#'
#' # fit model to data to recover Rt estimates
#' est <- estimate_infections(reported_cases,
Expand Down
15 changes: 4 additions & 11 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,14 @@ reporting_delay <- estimate_delay(
If data was not available we could instead make an informed estimate of the likely delay (*this is a synthetic example and not applicable to real world use cases and we have not included uncertainty to decrease runtimes*),

```{r}
reporting_delay <- dist_spec(
mean = convert_to_logmean(2, 1), sd = convert_to_logsd(2, 1), max = 10,
dist = "lognormal"
)
reporting_delay <- example_reporting_delay
```

Here we define the incubation period and generation time based on literature estimates for Covid-19 (see [here](https://github.com/epiforecasts/EpiNow2/tree/main/data-raw) for the code that generates these estimates). *Note that these distributions may not be applicable for your use case and that we have not included uncertainty here to reduce the runtime of this example but in most settings this is not recommended.*
Here we define the incubation period and generation time based on example literature estimates for Covid-19 (see [here](https://github.com/epiforecasts/EpiNow2/tree/main/data-raw) for the code that generates these estimates). *These distributions are unlikely to be applicable for your use case and do not have uncertainty associated with them. We strongly recommend investigating what might be the best distributions to use in any given use case.*

```{r}
generation_time <- get_generation_time(
disease = "SARS-CoV-2", source = "ganyani", max = 10, fixed = TRUE
)
incubation_period <- get_incubation_period(
disease = "SARS-CoV-2", source = "lauer", max = 10, fixed = TRUE
)
generation_time <- example_generation_time
incubation_period <- example_incubation_period
```

### [epinow()](https://epiforecasts.io/EpiNow2/reference/epinow.html)
Expand Down
21 changes: 4 additions & 17 deletions data-raw/estimate-infections.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,11 @@ options(mc.cores = 4)
# get example case counts
reported_cases <- example_confirmed[1:60]

# set up example generation time
generation_time <- get_generation_time(
disease = "SARS-CoV-2", source = "ganyani", fixed = TRUE
)
# set delays between infection and case report
incubation_period <- get_incubation_period(
disease = "SARS-CoV-2", source = "lauer", fixed = TRUE
)
# delays between infection and case report, with uncertainty
incubation_period_uncertain <- get_incubation_period(
disease = "SARS-CoV-2", source = "lauer"
)
reporting_delay <- dist_spec(
mean = convert_to_logmean(2, 1), mean_sd = 0,
sd = convert_to_logsd(2, 1), sd_sd = 0, max = 10
)
#' # use example distributions
generation_time <- example_generation_time
incubation_period <- example_incubation_period
reporting_delay <- example_reporting_delay

# default settings but assuming that delays are fixed rather than uncertain
example_estimate_infections <- estimate_infections(reported_cases,
generation_time = generation_time_opts(generation_time),
delays = delay_opts(incubation_period + reporting_delay),
Expand Down
12 changes: 4 additions & 8 deletions inst/dev/recover-synthetic/rt.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@ source(here::here("inst", "dev", "recover-synthetic", "plot.R"))
old_opts <- options()
options(mc.cores = 4)

# set up example generation time
generation_time <- get_generation_time(disease = "SARS-CoV-2", source = "ganyani")
# set delays between infection and case report
incubation_period <- get_incubation_period(disease = "SARS-CoV-2", source = "lauer")
reporting_delay <- dist_spec(
mean = convert_to_logmean(2, 1), mean_sd = 0.1,
sd = convert_to_logsd(2, 1), sd_sd = 0.1, max = 15
)
#' get example delays
generation_time <- example_generation_time
incubation_period <- example_incubation_period
reporting_delay <- example_reporting_delay

obs <- obs_opts(scale = list(mean = 0.1, sd = 0.025), return_likelihood = TRUE)

Expand Down
19 changes: 5 additions & 14 deletions man/epinow.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 4 additions & 16 deletions man/estimate_infections.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/generation_time_opts.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 4 additions & 13 deletions man/regional_epinow.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 4 additions & 11 deletions man/report_cases.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 4 additions & 11 deletions man/simulate_infections.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 4 additions & 8 deletions tests/testthat/test-epinow.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
skip_on_cran()


generation_time <- get_generation_time(disease = "SARS-CoV-2", source = "ganyani", max_value = 15)
incubation_period <- get_incubation_period(disease = "SARS-CoV-2", source = "lauer", max_value = 15)
reporting_delay <- dist_spec(
mean = convert_to_logmean(2, 1), mean_sd = 0.1,
sd = convert_to_logsd(2, 1), sd_sd = 0.1,
max = 10
)
# get example delays
generation_time <- example_generation_time
incubation_period <- example_incubation_period
reporting_delay <- example_reporting_delay

reported_cases <- EpiNow2::example_confirmed[1:30]

Expand Down
11 changes: 5 additions & 6 deletions tests/testthat/test-estimate_infections.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

futile.logger::flog.threshold("FATAL")

# get example delays
generation_time <- example_generation_time
incubation_period <- example_incubation_period
reporting_delay <- example_reporting_delay

reported_cases <- EpiNow2::example_confirmed[1:30]
generation_time <- get_generation_time(disease = "SARS-CoV-2", source = "ganyani", max_value = 10)
incubation_period <- get_incubation_period(disease = "SARS-CoV-2", source = "lauer", max_value = 10)
reporting_delay <- dist_spec(
mean = convert_to_logmean(2, 1), mean_sd = 0.1,
sd = convert_to_logsd(2, 1), sd_sd = 0.1, max = 10
)

default_estimate_infections <- function(..., add_stan = list(), delay = TRUE) {
futile.logger::flog.threshold("FATAL")
Expand Down
10 changes: 3 additions & 7 deletions tests/testthat/test-models/estimate_infections.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@

reported_cases <- EpiNow2::example_confirmed[1:30]
generation_time <- get_generation_time(
disease = "SARS-CoV-2", source = "ganyani", max_value = 10
)
incubation_period <- get_incubation_period(
disease = "SARS-CoV-2", source = "lauer", max_value = 10
)
#' get example delays
generation_time <- example_generation_time
incubation_period <- example_incubation_period

# static model
fit <- estimate_infections(
Expand Down
Loading

0 comments on commit 08c0646

Please sign in to comment.