]> nmode's Git Repositories - Rnaught/blob - R/computeLL.R
Testing testing 123
[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 #
12 computeLL <- function(p, NT, R0){
13
14 k <- length(p)
15 TT <- length(NT)-1
16 mu_t <- rep(0, TT)
17 for(i in 1:TT){
18 Nt <- NT[i:max(1,i-k+1)]
19 # print(Nt)
20 # print(p[1:min(k,i)])
21 mu_t[i] <- sum(p[1:min(k,i)]*Nt)
22 }
23 mu_t <- R0*mu_t
24 LL <- -sum(mu_t)+sum(NT[-1]*log(mu_t))
25
26 return(LL)
27
28 }
29
30