]> nmode's Git Repositories - Rnaught/blob - R/computeLL.R
6acfc786e34401e6f4f43543000f6d76b07a1ec6
[Rnaught] / R / computeLL.R
1 #' WP method background function computeLL
2 #'
3 #' This is a background/internal function called by \code{WP}. It computes the log-likelihood.
4 #'
5 #' @param NT vector of case counts
6 #' @param p discretized version of the serial distribution
7 #' @param R0 basic reproductive ratio
8 #' @return The function returns the variable \code{LL} which is the log-likelihood at the input variables and parameters.
9 #'
10 #' @export
11 computeLL <- function(p, NT, R0) {
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 mu_t <- R0 * mu_t
22 LL <- sum(NT[-1] * log(mu_t)) - sum(mu_t)
23
24 return(LL)
25 }