]> nmode's Git Repositories - Rnaught/blob - R/WP_known.R
Update WP.R
[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 likelihood estimator of R0 assuming that the serial distribution is known and finite discrete.
4 #'
5 #' @param NT vector of case counts
6 #' @param p discretized version of the serial distribution
7 #' @return The function returns \code{Rhat}, the maximum likelihood estimator of R0.
8 #' @export
9 #
10
11 WP_known <- function(NT, p){
12
13 k <- length(p)
14 TT <- length(NT)-1
15 mu_t <- rep(0, TT)
16 for(i in 1:TT){
17 Nt <- NT[i:max(1,i-k+1)]
18 # print(Nt)
19 # print(p[1:min(k,i)])
20 mu_t[i] <- sum(p[1:min(k,i)]*Nt)
21 }
22 Rhat <- sum(NT[-1])/sum(mu_t)
23 return(list(Rhat=Rhat))
24
25 }
26
27