summaryrefslogtreecommitdiff
path: root/R/WP_known.R
blob: 2c54bce3d48cb2ececf6fb2cbec45de8dd3a5e96 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#' WP method background function WP_known
#'
#' This is a background/internal function called by \code{WP}. It computes the maximum
#' likelihood estimator of R0 assuming that the serial distribution is known and finite discrete.
#'
#' @param NT Vector of case counts.
#' @param p Discretized version of the serial distribution.
#'
#' @return The function returns the maximum likelihood estimator of R0.
#'
#' @export
WP_known <- function(NT, p) {
    k <- length(p)
    TT <- length(NT) - 1
	mu_t <- rep(0, TT)

    for (i in 1:TT) {
        Nt <- NT[i:max(1, i-k+1)]
        mu_t[i]	<- sum(p[1:min(k, i)] * Nt)
    }

    Rhat <- sum(NT[-1]) / sum(mu_t)
	return(Rhat)
}