]> nmode's Git Repositories - Rnaught/blob - R/ID.R
Re-gen docs and prevent genning of internal functions
[Rnaught] / R / ID.R
1 #' ID method
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 NT Vector of case counts.
18 #' @param mu Mean of the serial distribution. This needs to match case counts
19 #' in time units. For example, if case counts are weekly and the
20 #' serial distribution has a mean of seven days, then \code{mu} should
21 #' be set to one. If case counts are daily and the serial distribution
22 #' has a mean of seven days, then \code{mu} should be set to seven.
23 #'
24 #' @return \code{ID} returns a single value, the estimate of R0.
25 #'
26 #' @examples
27 #' # Weekly data:
28 #' NT <- c(1, 4, 10, 5, 3, 4, 19, 3, 3, 14, 4)
29 #'
30 #' # Obtain R0 when the serial distribution has a mean of five days.
31 #' ID(NT, mu = 5 / 7)
32 #'
33 #' # Obtain R0 when the serial distribution has a mean of three days.
34 #' ID(NT, mu = 3 / 7)
35 #'
36 #' @export
37 ID <- function(NT, mu) {
38 NT <- as.numeric(NT)
39 TT <- length(NT)
40 s <- (1:TT) / mu
41 y <- log(NT) / s
42
43 R0_ID <- exp(sum(y) / TT)
44
45 return(R0_ID)
46 }