summaryrefslogtreecommitdiff
path: root/R/computeLL.R
diff options
context:
space:
mode:
authorNaeem Model <me@nmode.ca>2023-06-21 05:38:42 +0000
committerNaeem Model <me@nmode.ca>2023-06-21 05:38:42 +0000
commit9c1a5668803e735f034700c55028ffc0146f1e93 (patch)
tree53954bf0b642f1d09fb452bd2dd16e0381234395 /R/computeLL.R
parent05e34d4b65141e741e98cf1dcec67b0ff3d24626 (diff)
Fix code formatting and remove unnecessary comments
Diffstat (limited to 'R/computeLL.R')
-rw-r--r--R/computeLL.R31
1 files changed, 13 insertions, 18 deletions
diff --git a/R/computeLL.R b/R/computeLL.R
index 0730399..6acfc78 100644
--- a/R/computeLL.R
+++ b/R/computeLL.R
@@ -3,28 +3,23 @@
#' 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 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){
+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)
+ }
- 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))
+ mu_t <- R0 * mu_t
+ LL <- sum(NT[-1] * log(mu_t)) - sum(mu_t)
return(LL)
-
}
-
-