Skip to content

Commit

Permalink
add examples for analysis results
Browse files Browse the repository at this point in the history
  • Loading branch information
sbfnk committed Sep 27, 2023
1 parent 15d137d commit 104c034
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 0 deletions.
18 changes: 18 additions & 0 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,21 @@
#' An example data frame of observed cases
#' @format A data frame containing cases reported on each date.
"example_confirmed"

#' Example estimate_infections output
#'
#' @description `r lifecycle::badge("stable")`
#' An example output of `estimate_infections` containing 200 samples.
#' See here for details:
#' https://github.com/epiforecasts/EpiNow2/blob/main/data-raw/estimate_infections.R # nolint
#' @format An `estimate_infections` object with the results
"example_estimate_infections"

#' Example regional_epinow output
#'
#' @description `r lifecycle::badge("stable")`
#' An example output of `regional_epinow` containing 200 samples per region.
#' See here for details:
#' https://github.com/epiforecasts/EpiNow2/blob/main/data-raw/estimate_infections.R # nolint
#' @format A list with the results
"example_regional_epinow"
47 changes: 47 additions & 0 deletions data-raw/estimate-infections.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
library("EpiNow2")
library("here")

# 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
)

# 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),
rt = rt_opts(prior = list(mean = 2, sd = 0.1)),
stan = stan_opts(samples = 200, control = list(adapt_delta = 0.95))
)

cases <- example_confirmed[1:60]
cases <- data.table::rbindlist(list(
data.table::copy(cases)[, region := "testland"],
cases[, region := "realland"]
))

example_regional_epinow <- regional_epinow(
reported_cases = cases,
generation_time = generation_time_opts(generation_time),
delays = delay_opts(incubation_period + reporting_delay),
rt = rt_opts(prior = list(mean = 2, sd = 0.2)),
stan = stan_opts( samples = 200, control = list(adapt_delta = 0.95))
)

usethis::use_data(example_estimate_infections, overwrite = TRUE)
usethis::use_data(example_regional_epinow, overwrite = TRUE)
Binary file added data/example_estimate_infections.rda
Binary file not shown.
Binary file added data/example_regional_epinow.rda
Binary file not shown.
19 changes: 19 additions & 0 deletions man/example_estimate_infections.Rd

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

19 changes: 19 additions & 0 deletions man/example_regional_epinow.Rd

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

0 comments on commit 104c034

Please sign in to comment.