Skip to content

Commit e0d7bb3

Browse files
Consistent naming of function arguments and variables (#112)
* replace . with _ in function arguments, fixes #88 * replace . with _ for variables and temporary functions, relates #88 * replace arguments with subclin with asymptomatic, relates #99 * replace prop_asym with prop_asymptomatic, relates #99 * replace asym variable and DT column with asymptomatic, relates #99 * replace infector_asym DT column with infector_asymptomatic, relates #99 * replace disp_com function arg with disp_community, relates #99 * replace disp_iso function arg with disp_isolated, relates #99 * replace infector_iso_time DT column with infector_isolation_time, relates #99 * rename control_effectiveness to prop_ascertain in parameter_sweep, relates #99 * rename index_R0 to r0community in parameter_sweep, relates #99 * rename n_sim argument and variable to n * rename num_initial_cases argument to initial_cases * underscore separate r0* arguments * add NEWS item for consistent naming and style * sync prop_ascertain and prop_asymptomatic function argument documentation * fix GH username typo in NEWS.md Co-authored-by: Carl A. B. Pearson <pearsonca@users.noreply.github.com> --------- Co-authored-by: Carl A. B. Pearson <pearsonca@users.noreply.github.com>
1 parent 6815f91 commit e0d7bb3

20 files changed

+413
-402
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# ringbp 0.1.2.9999
22

3+
* Function argument and variable names are consistently named and styled (snake case). Arguments that were abbreviated (e.g. `iso`) now use the full word, and arguments that had aliases (e.g. `prop_ascertain` and `control_effectiveness`) now use a single name. By @joshwlambert in #112 and reviewed by @pearsonca and @sbfnk.
4+
35
* Fixed a bug in the implementation of quarantine, where isolation could happen later than onset + delay, if this was earlier than the isolation time of the infector. By @sbfnk in #107 and reviewed by @pearsonca and @joshwlambert.
46

57
* Changed internal sampling to vector draws in several locations; in some cases, this was an optimization, but in others it was a bug fix correcting the use of single draw where there should have been many. Also incorporates other vectorization changes to improve performance. Because of the bug fix, users should expect results to change. Addresses issues #90, #92, #94, in #98 by @pearsonca (now added as a contributor) with review by @sbfnk and @joshwlambert.

R/aux_functions.R

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ inf_fn <- function(inc_samp = NULL, k = NULL) {
2929
#'
3030
#' @examples
3131
#' res <- scenario_sim(
32-
#' n.sim = 10,
33-
#' num.initial.cases = 1,
34-
#' prop.asym = 0,
35-
#' prop.ascertain = 0.2,
32+
#' n = 10,
33+
#' initial_cases = 1,
34+
#' prop_asymptomatic = 0,
35+
#' prop_ascertain = 0.2,
3636
#' cap_cases = 4500,
3737
#' cap_max_days = 350,
38-
#' r0isolated = 0.5,
39-
#' r0community = 2.5,
40-
#' disp.com = 0.16,
41-
#' disp.iso = 1,
38+
#' r0_isolated = 0.5,
39+
#' r0_community = 2.5,
40+
#' disp_community = 0.16,
41+
#' disp_isolated = 1,
4242
#' onset_to_isolation = \(x) rweibull(n = x, shape = 1.65, scale = 4.28),
4343
#' incubation_period = \(x) rweibull(n = x, shape = 2.322737, scale = 6.492272),
4444
#' k = 0,
@@ -47,10 +47,10 @@ inf_fn <- function(inc_samp = NULL, k = NULL) {
4747
#' extinct_prob(res, cap_cases = 4500)
4848
extinct_prob <- function(outbreak_df_week = NULL, cap_cases = NULL, week_range = 12:16) {
4949

50-
n_sim <- max(outbreak_df_week$sim)
50+
n <- max(outbreak_df_week$sim)
5151

5252
extinct_runs <- detect_extinct(outbreak_df_week, cap_cases, week_range)
53-
out <- sum(extinct_runs$extinct) / n_sim
53+
out <- sum(extinct_runs$extinct) / n
5454

5555
return(out)
5656
}
@@ -73,16 +73,16 @@ extinct_prob <- function(outbreak_df_week = NULL, cap_cases = NULL, week_range
7373
#'
7474
#' @examples
7575
#' res <- scenario_sim(
76-
#' n.sim = 10,
77-
#' num.initial.cases = 1,
78-
#' prop.asym = 0,
79-
#' prop.ascertain = 0.2,
76+
#' n = 10,
77+
#' initial_cases = 1,
78+
#' prop_asymptomatic = 0,
79+
#' prop_ascertain = 0.2,
8080
#' cap_cases = 4500,
8181
#' cap_max_days = 350,
82-
#' r0isolated = 0.5,
83-
#' r0community = 2.5,
84-
#' disp.com = 0.16,
85-
#' disp.iso = 1,
82+
#' r0_isolated = 0.5,
83+
#' r0_community = 2.5,
84+
#' disp_community = 0.16,
85+
#' disp_isolated = 1,
8686
#' onset_to_isolation = \(x) rweibull(n = x, shape = 1.65, scale = 4.28),
8787
#' incubation_period = \(x) rweibull(n = x, shape = 2.322737, scale = 6.492272),
8888
#' k = 0,

R/globals.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@ utils::globalVariables(c(
88
"week", # <outbreak_model>
99
"onset", # <outbreak_model>
1010
"cumulative", # <outbreak_model>
11-
"asym", # <outbreak_setup>
11+
"asymptomatic", # <outbreak_setup>
1212
"isolated_time", # <outbreak_setup>
1313
"onset", # <outbreak_setup>
1414
"new_cases", # <outbreak_step>
1515
"isolated", # <outbreak_step>
16-
"asym", # <outbreak_step>
16+
"asymptomatic", # <outbreak_step>
1717
"onset", # <outbreak_step>
1818
"caseid", # <outbreak_step>
1919
"isolated_time", # <outbreak_step>
2020
"exposure", # <outbreak_step>
21-
"infector_iso_time", # <outbreak_step>
22-
"infector_asym", # <outbreak_step>
21+
"infector_isolation_time", # <outbreak_step>
22+
"infector_asymptomatic", # <outbreak_step>
2323
"missed", # <outbreak_step>
2424
"scenario", # <parameter_sweep>
2525
"sims", # <parameter_sweep>

R/outbreak_model.R

Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
11

22
#' Run a single instance of the branching process model
33
#' @author Joel Hellewell
4-
#' @param disp.iso a positive `numeric` scalar: dispersion parameter for
4+
#' @param disp_isolated a positive `numeric` scalar: dispersion parameter for
55
#' isolated cases (must be >0)
6-
#' @param disp.com a positive `numeric` scalar: dispersion parameter for
6+
#' @param disp_community a positive `numeric` scalar: dispersion parameter for
77
#' non-isolated cases (must be >0)
8-
#' @param disp.subclin a positive `numeric` scalar: dispersion parameter for
9-
#' sub-clincial non-isolated cases (must be >0)
10-
#' @param r0isolated a positive `numeric` scalar: reproduction number for
8+
#' @param disp_asymptomatic a positive `numeric` scalar: dispersion parameter
9+
#' for sub-clincial non-isolated cases (must be >0)
10+
#' @param r0_isolated a positive `numeric` scalar: reproduction number for
1111
#' isolated cases (must be >0)
12-
#' @param r0community a positive `numeric` scalar: reproduction number for
12+
#' @param r0_community a positive `numeric` scalar: reproduction number for
1313
#' non-isolated cases (must be >0)
14-
#' @param r0subclin a positive `numeric` scalar: reproduction number for
14+
#' @param r0_asymptomatic a positive `numeric` scalar: reproduction number for
1515
#' sub-clinical non-isolated cases (must be >0)
16-
#' @param prop.ascertain a nonnegative `numeric` scalar: proportion of
17-
#' infectious contacts ascertained by contact tracing (must be 0<=x<=1)
16+
#' @param prop_ascertain a `numeric` scalar probability (between 0 and 1
17+
#' inclusive): proportion of infectious contacts ascertained by contact
18+
#' tracing
1819
#' @param k a `numeric` scalar: skew parameter for sampling the serial
1920
#' interval from the incubation period
2021
#' @param quarantine a `logical` scalar: whether quarantine is in effect, if
2122
#' `TRUE` then traced contacts are isolated before symptom onset; defaults to
2223
#' `FALSE`
23-
#' @param prop.asym a nonnegative `numeric` scalar: proportion of cases that
24-
#' are completely asymptomatic (sublinical) (between 0 and 1)
24+
#' @param prop_asymptomatic a `numeric` scalar probability (between 0 and 1
25+
#' inclusive): proportion of cases that are completely asymptomatic
26+
#' (subclinical)
2527
#' @param onset_to_isolation a `function`: a random number generating
2628
#' `function` that accepts a single `integer` argument specifying the
2729
#' length of the `function` output.
@@ -30,7 +32,7 @@
3032
#' `function` accepts a single `integer` argument specifying the number of
3133
#' times to sample the incubation period (i.e. length of the `function`
3234
#' output).
33-
#' @param num.initial.cases a nonnegative `integer` scalar: number of initial
35+
#' @param initial_cases a nonnegative `integer` scalar: number of initial
3436
#' or starting cases which are all assumed to be missed.
3537
#' @param cap_cases a positive `integer` scalar: number of cumulative cases at
3638
#' which the branching process (simulation) was terminated
@@ -53,71 +55,71 @@
5355
#' @examples
5456
#' set.seed(1)
5557
#' out <- outbreak_model(
56-
#' num.initial.cases = 1,
57-
#' prop.ascertain = 0.2,
58+
#' initial_cases = 1,
59+
#' prop_ascertain = 0.2,
5860
#' cap_max_days = 350,
5961
#' cap_cases = 4500,
60-
#' r0isolated = 0.5,
61-
#' r0community = 2.5,
62-
#' r0subclin = 2.5,
63-
#' disp.iso = 1,
64-
#' disp.com = 0.16,
65-
#' disp.subclin = 0.16,
62+
#' r0_isolated = 0.5,
63+
#' r0_community = 2.5,
64+
#' r0_asymptomatic = 2.5,
65+
#' disp_isolated = 1,
66+
#' disp_community = 0.16,
67+
#' disp_asymptomatic = 0.16,
6668
#' k = 0,
6769
#' onset_to_isolation = \(x) rweibull(n = x, shape = 1.65, scale = 4.28),
6870
#' incubation_period = \(x) rweibull(n = x, shape = 2.32, scale = 6.49),
69-
#' prop.asym = 0,
71+
#' prop_asymptomatic = 0,
7072
#' quarantine = FALSE
7173
#' )
7274
#' out
73-
outbreak_model <- function(num.initial.cases = NULL, prop.ascertain = NULL,
75+
outbreak_model <- function(initial_cases = NULL, prop_ascertain = NULL,
7476
cap_max_days = NULL, cap_cases = NULL,
75-
r0isolated = NULL, r0community = NULL,
76-
r0subclin = NULL, disp.iso = NULL,
77-
disp.com = NULL, disp.subclin = NULL,
77+
r0_isolated = NULL, r0_community = NULL,
78+
r0_asymptomatic = NULL, disp_isolated = NULL,
79+
disp_community = NULL, disp_asymptomatic = NULL,
7880
k, onset_to_isolation, incubation_period,
79-
prop.asym = NULL, quarantine = FALSE) {
81+
prop_asymptomatic = NULL, quarantine = FALSE) {
8082

8183
# Set initial values for loop indices
82-
total.cases <- num.initial.cases
83-
latest.onset <- 0
84+
total_cases <- initial_cases
85+
latest_onset <- 0
8486
extinct <- FALSE
8587

8688
# Initial setup
87-
case_data <- outbreak_setup(num.initial.cases = num.initial.cases,
89+
case_data <- outbreak_setup(initial_cases = initial_cases,
8890
incubation_period = incubation_period,
8991
onset_to_isolation = onset_to_isolation,
9092
k = k,
91-
prop.asym = prop.asym)
93+
prop_asymptomatic = prop_asymptomatic)
9294

9395
# Preallocate
9496
effective_r0_vect <- c()
9597
cases_in_gen_vect <- c()
9698

9799

98100
# Model loop
99-
while (latest.onset < cap_max_days & total.cases < cap_cases & !extinct) {
101+
while (latest_onset < cap_max_days & total_cases < cap_cases & !extinct) {
100102

101103
out <- outbreak_step(case_data = case_data,
102-
disp.iso = disp.iso,
103-
disp.com = disp.com,
104-
disp.subclin = disp.subclin,
105-
r0isolated = r0isolated,
106-
r0community = r0community,
107-
r0subclin = r0subclin,
104+
disp_isolated = disp_isolated,
105+
disp_community = disp_community,
106+
disp_asymptomatic = disp_asymptomatic,
107+
r0_isolated = r0_isolated,
108+
r0_community = r0_community,
109+
r0_asymptomatic = r0_asymptomatic,
108110
incubation_period = incubation_period,
109111
onset_to_isolation = onset_to_isolation,
110-
prop.ascertain = prop.ascertain,
112+
prop_ascertain = prop_ascertain,
111113
k = k,
112114
quarantine = quarantine,
113-
prop.asym = prop.asym)
115+
prop_asymptomatic = prop_asymptomatic)
114116

115117

116118
case_data <- out[[1]]
117119
effective_r0_vect <- c(effective_r0_vect, out[[2]])
118120
cases_in_gen_vect <- c(cases_in_gen_vect, out[[3]])
119-
total.cases <- nrow(case_data)
120-
latest.onset <- max(case_data$onset)
121+
total_cases <- nrow(case_data)
122+
latest_onset <- max(case_data$onset)
121123
extinct <- all(case_data$isolated)
122124
}
123125

R/outbreak_setup.R

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#'
77
#' @return `data.table` of cases in outbreak so far. `data.table` columns are:
88
#' * `$exposure`: `numeric`
9-
#' * `$asym`: `logical`
9+
#' * `$asymptomatic`: `logical`
1010
#' * `$caseid`: `integer`
1111
#' * `$infector`: `numeric`
1212
#' * `$missed`: `logical`
@@ -25,30 +25,30 @@
2525
#' # delay distribution sampling function
2626
#' onset_to_isolation <- \(x) rweibull(n = x, shape = 1.65, scale = 4.28)
2727
#' out <- outbreak_setup(
28-
#' num.initial.cases = 1,
28+
#' initial_cases = 1,
2929
#' incubation_period = incubation_period,
3030
#' onset_to_isolation = onset_to_isolation,
3131
#' k = 1.95,
32-
#' prop.asym = 0
32+
#' prop_asymptomatic = 0
3333
#' )
3434
#' out
35-
outbreak_setup <- function(num.initial.cases, incubation_period, onset_to_isolation, k, prop.asym) {
35+
outbreak_setup <- function(initial_cases, incubation_period, onset_to_isolation, k, prop_asymptomatic) {
3636
# Set up table of initial cases
3737
case_data <- data.table(
3838
exposure = 0, # Exposure time of 0 for all initial cases
39-
asym = runif(num.initial.cases) < prop.asym,
40-
caseid = seq_len(num.initial.cases), # set case id
39+
asymptomatic = runif(initial_cases) < prop_asymptomatic,
40+
caseid = seq_len(initial_cases), # set case id
4141
infector = 0,
4242
isolated = FALSE,
4343
missed = TRUE,
44-
onset = incubation_period(num.initial.cases),
44+
onset = incubation_period(initial_cases),
4545
new_cases = NA,
4646
isolated_time = Inf
4747
)
4848

4949
# set isolation time for cluster to minimum time of onset of symptoms + draw from delay distribution
5050
case_data <- case_data[
51-
asym == FALSE,
51+
asymptomatic == FALSE,
5252
isolated_time := onset + onset_to_isolation(.N)
5353
]
5454

0 commit comments

Comments
 (0)