forked from epiforecasts/ringbp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoutbreak_setup.R
50 lines (46 loc) · 1.7 KB
/
outbreak_setup.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#' Set up initial cases for branching process
#' @author Joel Hellewell
#'
#' @inheritParams outbreak_model
#' @inheritParams outbreak_step
#'
#' @return `data.table` of cases in outbreak so far. `data.table` columns are:
#' * `$exposure`: `numeric`
#' * `$asym`: `logical`
#' * `$caseid`: `integer`
#' * `$infector`: `numeric`
#' * `$missed`: `logical`
#' * `$onset`: `numeric`
#' * `$new_cases`: `logical`
#' * `$isolated_time`: `numeric`
#' * `$isolated`: `logical`
#' @export
#' @importFrom data.table data.table
#' @importFrom stats rbinom
#'
#' @examples
#'
#'\dontrun{
#' # incubation period sampling function
#' incfn <- dist_setup(dist_shape = 2.322737,dist_scale = 6.492272)
#' # delay distribution sampling function
#' delayfn <- dist_setup(delay_shape, delay_scale)
#' outbreak_setup(num.initial.cases = 5,incfn,delayfn,k=1.95,prop.asym=0)
#'}
outbreak_setup <- function(num.initial.cases, incfn, delayfn, k, prop.asym) {
# Set up table of initial cases
inc_samples <- incfn(num.initial.cases)
case_data <- data.table(exposure = rep(0, num.initial.cases), # Exposure time of 0 for all initial cases
asym = as.logical(rbinom(num.initial.cases, 1, prop.asym)),
caseid = 1:(num.initial.cases), # set case id
infector = 0,
missed = TRUE,
onset = inc_samples,
new_cases = NA)
# set isolation time for cluster to minimum time of onset of symptoms + draw from delay distribution
case_data <- case_data[, isolated_time := onset + delayfn(1)
][, isolated := FALSE]
case_data$isolated_time[case_data$asym] <- Inf
# return
return(case_data)
}