Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update function documentation #78

Merged
merged 14 commits into from
Mar 4, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.2
Depends:
R (>= 3.5.0)
Imports:
Expand Down
11 changes: 8 additions & 3 deletions R/aux_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ dist_setup <- function(dist_shape = NULL, dist_scale = NULL) {
#' Samples the serial interval for given incubation period samples
#'
#' @param inc_samp vector of samples from the incubation period distribution
#' @param k numeric skew parameter for sampling the serial interval from the incubation period
#' @inheritParams outbreak_model
#'
#' @return a `numeric` vector of equal length to the vector input to `inc_samp`
#' @export
#' @importFrom sn rsn

Expand All @@ -38,6 +39,7 @@ inf_fn <- function(inc_samp = NULL, k = NULL) {
#' Calculate proportion of runs that have controlled outbreak
#'
#' @author Joel Hellewell
#' @return a single `numeric` with the probability of extinction
#' @export
#' @inheritParams detect_extinct
extinct_prob <- function(outbreak_df_week = NULL, cap_cases = NULL, week_range = 12:16) {
Expand All @@ -53,11 +55,14 @@ extinct_prob <- function(outbreak_df_week = NULL, cap_cases = NULL, week_range

#' Calculate whether outbreaks went extinct or not
#' @author Joel Hellewell
#' @param outbreak_df_week data.table weekly cases produced by the outbreak model
#' @param cap_cases integer number of cumulative cases at which the branching process was terminated
#' @param outbreak_df_week `data.table` weekly cases produced by the outbreak model
#' @inheritParams outbreak_model
#' @param week_range integer vector giving the (zero indexed) week range to test for whether an extinction occurred.
#' @importFrom data.table as.data.table fifelse
#'
#' @return A `data.table`, with two columns `sim` and `extinct`, for a binary
#' classification of whether the outbreak went extinct in each simulation
#' replicate. `1` is an outbreak that went extinct, `0` if not.
#' @export
#'
detect_extinct <- function(outbreak_df_week = NULL, cap_cases = NULL, week_range = 12:16) {
Expand Down
17 changes: 13 additions & 4 deletions R/outbreak_model.R
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@

#' Run a single instance of the branching process model
#' @author Joel Hellewell
#' @inheritParams outbreak_step
#' @param disp.iso `numeric` dispersion parameter for isolated cases (must be >0)
#' @param disp.com `numeric` dispersion parameter for non-isolated cases (must be >0)
#' @param disp.subclin `numeric` dispersion parameter for sub-clincial non-isolated cases (must be >0)
#' @param r0isolated `numeric` reproduction number for isolated cases (must be >0)
#' @param r0community `numeric` reproduction number for non-isolated cases (must be >0)
#' @param r0subclin `numeric` reproduction number for sub-clinical non-isolated cases (must be >0)
#' @param prop.ascertain `numeric` proportion of infectious contacts ascertained by contact tracing (must be 0<=x<=1)
#' @param k `numeric` skew parameter for sampling the serial interval from the incubation period
#' @param quarantine `logical` whether quarantine is in effect, if TRUE then traced contacts are isolated before symptom onset
#' @param prop.asym `numeric` proportion of cases that are completely asymptomatic (sublinical) (between 0 and 1)
#' @param delay_shape numeric shape parameter of delay distribution
#' @param delay_scale numeric scale parameter of delay distribution
#' @param num.initial.cases The number of initial or starting cases which are all assumed to be missed.
#' @param cap_cases Stop the simulation when this many cases is reached.
#' @param num.initial.cases `integer` number of initial or starting cases which are all assumed to be missed.
#' @param cap_cases `integer` number of cumulative cases at which the branching process (simulation) was terminated
#' @param cap_max_days Stop the simulation when this many days is reached.
#'
#'
#'
#' @return data.table of cases by week, cumulative cases, and the effective reproduction number of the outreak
#' @return `data.table` of cases by week, cumulative cases, and the effective reproduction number of the outbreak
#' @export
#'
#' @importFrom data.table rbindlist
Expand Down
8 changes: 2 additions & 6 deletions R/outbreak_setup.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
#' Set up initial cases for branching process
#' @author Joel Hellewell
#'
#' @param num.initial.cases Integer number of initial cases
#' @param incfn function that samples from incubation period Weibull distribution; generated using dist_setup
#' @param delayfn function that samples from the onset-to-hospitalisation delay Weibull distribution; generated using dist_setup
#' @param k Numeric skew parameter for sampling the serial interval from the incubation period
#' @param prop.asym Numeric proportion of cases that are sublinical (between 0 and 1)
#' @inheritParams outbreak_model
#'
#' @return data.table of cases in outbreak so far
#' @return `data.table` of cases in outbreak so far
#' @export
#' @importFrom data.table data.table
#' @importFrom stats rbinom
Expand Down
24 changes: 10 additions & 14 deletions R/outbreak_step.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,20 @@
#'
#' @author Joel Hellewell
#'
#' @param case_data data.table of cases in outbreak so far; initially generated by outbreak_setup
#' @param disp.iso numeric dispersion parameter for isolated cases (must be >0)
#' @param disp.com numeric dispersion parameter for non-isolated cases (must be >0)
#' @param disp.subclin numeric dispersion parameter for sub-clincial non-isolated cases (must be >0)
#' @param r0isolated numeric reproduction number for isolated cases (must be >0)
#' @param r0community numeric reproduction number for non-isolated cases (must be >0)
#' @param r0subclin numeric reproduction number for sub-clinical non-isolated cases (must be >0)
#' @param incfn function samples from incubation period; generated by dist_setup
#' @param delayfn function samples from the onset-to-hospitalisation delay; generated by dist_setup
#' @param prop.ascertain numeric proportion of infectious contacts ascertained by contact tracing (must be 0<=x<=1)
#' @param k numeric skew parameter for sampling the serial interval from the incubation period
#' @param quarantine logical whether quarantine is in effect, if TRUE then traced contacts are isolated before symptom onset
#' @param prop.asym proportion of cases that are completely asymptomatic.
#' @param case_data `data.table` of cases in outbreak so far; initially generated by outbreak_setup
#' @inheritParams outbreak_model
#' @param incfn `function` that samples from incubation period Weibull distribution; generated using [dist_setup()]
#' @param delayfn `function` that samples from the onset-to-hospitalisation delay Weibull distribution; generated using [dist_setup()]
#'
#' @importFrom data.table data.table rbindlist
#' @importFrom purrr map2 map2_dbl map_lgl
#' @importFrom stats rbinom
#'
#' @return A `list` with three elements:
#' 1. `$cases`: a `data.table` with case data
#' 2. `$effective_r0`: a `numeric` with the effective reproduction number
#' 3. `$cases_in_gen`: a `numeric` with the number of new cases in that
#' generation
#' @export
#'
#' @examples
Expand Down Expand Up @@ -48,7 +44,7 @@
#'}
outbreak_step <- function(case_data = NULL, disp.iso = NULL, disp.com = NULL,
r0isolated = NULL, r0community = NULL,
prop.asym = NULL, incfn = NULL, delayfn = NULL,
prop.asym = NULL, incfn = NULL, delayfn = NULL,
prop.ascertain = NULL, k = NULL, quarantine = NULL,
r0subclin = NULL, disp.subclin = NULL) {

Expand Down
2 changes: 1 addition & 1 deletion R/parameter_sweep.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#' @param sim_fn Function, defaults to NULL. The vectorised model simulation function - see the examples
#' for usage.
#'
#' @return A nested tibble containing the parameters for each scenario and a nested list of output
#' @return A nested `data.table` containing the parameters for each scenario and a nested list of output
#' from `wuhan_sim`.
#' @export
#' @importFrom future.apply future_lapply
Expand Down
4 changes: 2 additions & 2 deletions R/scenario_sim.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#' @importFrom stats quantile
#' @importFrom stats rweibull
#' @importFrom utils data
#' @return A data.table object returning the results for multiple simulations using
#' @return A `data.table` object returning the results for multiple simulations using
#' the same set of parameters. The table has columns
#' * week: The week in the simulation.
#' * weekly_cases: The number of new cases that week.
Expand Down Expand Up @@ -85,6 +85,6 @@ utils::globalVariables(c(".", ".N", ":=", "asym", "control_effectiveness", "cumu
"new_cases", "num.initial.cases", "onset", "pext", "prob_extinct", "prop.asym",
"r0", "rweibull", "samp", "samples", "scenario", "sim", "sims", "theta", "upper", "value",
"week", "weekly_cases", "x", "y", "y0", "y100", "y25", "y50", "y75"))



9 changes: 7 additions & 2 deletions man/detect_extinct.Rd

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

7 changes: 5 additions & 2 deletions man/extinct_prob.Rd

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

5 changes: 4 additions & 1 deletion man/inf_fn.Rd

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

26 changes: 13 additions & 13 deletions man/outbreak_model.Rd

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

12 changes: 4 additions & 8 deletions man/outbreak_setup.Rd

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

35 changes: 22 additions & 13 deletions man/outbreak_step.Rd

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

2 changes: 1 addition & 1 deletion man/parameter_sweep.Rd

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

Loading
Loading