]>
nmode's Git Repositories - Rnaught/blob - R/id.R
1 #' Incidence Decay (ID)
3 #' This function implements a least squares estimation method of R0 due to
4 #' Fisman et al. (PloS One, 2013). See details for implementation notes.
6 #' The method is based on a straightforward incidence decay model. The estimate
7 #' of R0 is the value which minimizes the sum of squares between observed case
8 #' counts and cases counts expected under the model.
10 #' This method is based on an approximation of the SIR model, which is most
11 #' valid at the beginning of an epidemic. The method assumes that the mean of
12 #' the serial distribution (sometimes called the serial interval) is known. The
13 #' final estimate can be quite sensitive to this value, so sensitivity testing
14 #' is strongly recommended. Users should be careful about units of time (e.g.,
15 #' are counts observed daily or weekly?) when implementing.
17 #' @param cases Vector of case counts. The vector must be non-empty and only
18 #' contain positive integers.
19 #' @param mu Mean of the serial distribution. This must be a positive number.
20 #' The value should match the case counts in time units. For example, if case
21 #' counts are weekly and the serial distribution has a mean of seven days,
22 #' then `mu` should be set to `1`. If case counts are daily and the serial
23 #' distribution has a mean of seven days, then `mu` should be set to `7`.
25 #' @return An estimate of the basic reproduction number (R0).
28 #' [Fisman et al. (PloS One, 2013)](
29 #' https://doi.org/10.1371/journal.pone.0083622)
31 #' @seealso [idea()] for a similar method.
37 #' cases <- c(1, 4, 10, 5, 3, 4, 19, 3, 3, 14, 4)
39 #' # Obtain R0 when the serial distribution has a mean of five days.
40 #' id(cases, mu = 5 / 7)
42 #' # Obtain R0 when the serial distribution has a mean of three days.
43 #' id(cases, mu = 3 / 7)
44 id
<- function(cases
, mu
) {
45 exp(sum((log(cases
) * mu
) / seq_along(cases
)) / length(cases
))