]> nmode's Git Repositories - Rnaught/blob - R/computeLL.R
Edit docs
[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 #'
9 #' @return This function returns the log-likelihood at the input variables and parameters.
10 #'
11 #' @export
12 computeLL <- function(p, NT, R0) {
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 mu_t <- R0 * mu_t
23 LL <- sum(NT[-1] * log(mu_t)) - sum(mu_t)
24
25 return(LL)
26 }