]> nmode's Git Repositories - Rnaught/blob - R/id.R
91fa5cab727b43681cb14713333389640a5a1f7e
[Rnaught] / R / id.R
1 #' Incidence Decay (ID)
2 #'
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.
5 #'
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.
9 #'
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.
16 #'
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`.
24 #'
25 #' @return An estimate of the basic reproduction number (R0).
26 #'
27 #' @references [Fisman et al. (PloS One, 2013)](
28 #' https://doi.org/10.1371/journal.pone.0083622)
29 #'
30 #' @seealso [idea()] for a similar method.
31 #'
32 #' @export
33 #'
34 #' @examples
35 #' # Weekly data.
36 #' cases <- c(1, 4, 10, 5, 3, 4, 19, 3, 3, 14, 4)
37 #'
38 #' # Obtain R0 when the serial distribution has a mean of five days.
39 #' id(cases, mu = 5 / 7)
40 #'
41 #' # Obtain R0 when the serial distribution has a mean of three days.
42 #' id(cases, mu = 3 / 7)
43 id <- function(cases, mu) {
44 exp(sum((log(cases) * mu) / seq_along(cases)) / length(cases))
45 }