X-Git-Url: https://git.nmode.ca/Rnaught/blobdiff_plain/14ec98c9bfc49f963e30159dc7db9f554088fb44..c85280a9cfe1f46eb4bc260d7f479a33d86dceff:/R/computeLL.R diff --git a/R/computeLL.R b/R/computeLL.R index 0730399..9047777 100644 --- a/R/computeLL.R +++ b/R/computeLL.R @@ -2,29 +2,25 @@ #' #' 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. - +#' @param NT Vector of case counts. +#' @param p Discretized version of the serial distribution. +#' @param R0 Basic reproductive ratio. +#' +#' @return This function returns the log-likelihood at the input variables and parameters. +#' #' @export -# -computeLL <- function(p, NT, R0){ +computeLL <- function(p, NT, R0) { + k <- length(p) + TT <- length(NT) - 1 + mu_t <- rep(0, TT) - 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)] -# print(Nt) -# print(p[1:min(k,i)]) - mu_t[i] <- sum(p[1:min(k,i)]*Nt) - } - mu_t <- R0*mu_t - LL <- -sum(mu_t)+sum(NT[-1]*log(mu_t)) + 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) - } - -