]> nmode's Git Repositories - Rnaught/blob - R/WP_known.R
Remove input args from output lists
[Rnaught] / R / WP_known.R
1 #' WP method background function WP_known
2 #'
3 #' This is a background/internal function called by \code{WP}. It computes the maximum
4 #' likelihood estimator of R0 assuming that the serial distribution is known and finite discrete.
5 #'
6 #' @param NT vector of case counts
7 #' @param p discretized version of the serial distribution
8 #' @return The function returns \code{Rhat}, the maximum likelihood estimator of R0.
9 #'
10 #' @export
11 WP_known <- function(NT, p) {
12 k <- length(p)
13 TT <- length(NT) - 1
14 mu_t <- rep(0, TT)
15
16 for (i in 1:TT) {
17 Nt <- NT[i:max(1, i-k+1)]
18 mu_t[i] <- sum(p[1:min(k, i)] * Nt)
19 }
20
21 Rhat <- sum(NT[-1]) / sum(mu_t)
22 return(Rhat)
23 }