]> nmode's Git Repositories - Rnaught/blob - R/WP_known.R
Remove 'shinyjs' dependency
[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 #'
9 #' @return The function returns the maximum likelihood estimator of R0.
10 #'
11 #' @keywords internal
12 WP_known <- function(NT, p) {
13 k <- length(p)
14 TT <- length(NT) - 1
15 mu_t <- rep(0, TT)
16
17 for (i in 1:TT) {
18 Nt <- NT[i:max(1, i-k+1)]
19 mu_t[i] <- sum(p[1:min(k, i)] * Nt)
20 }
21
22 Rhat <- sum(NT[-1]) / sum(mu_t)
23 return(Rhat)
24 }