summaryrefslogtreecommitdiff
path: root/R/computeLL.R
blob: 6acfc786e34401e6f4f43543000f6d76b07a1ec6 (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
25
#' WP method background function computeLL
#'
#' This is a background/internal function called by \code{WP}.  It computes the log-likelihood.
#'
#' @param NT vector of case counts
#' @param p discretized version of the serial distribution
#' @param R0 basic reproductive ratio
#' @return The function returns the variable \code{LL} which is the log-likelihood at the input variables and parameters.
#'
#' @export
computeLL <- function(p, NT, R0) {
    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)
    }

    mu_t <- R0 * mu_t
    LL <- sum(NT[-1] * log(mu_t)) - sum(mu_t)

	return(LL)
}