summaryrefslogtreecommitdiff
path: root/R/WP_known.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/WP_known.R
parent05e34d4b65141e741e98cf1dcec67b0ff3d24626 (diff)
Fix code formatting and remove unnecessary comments
Diffstat (limited to 'R/WP_known.R')
-rw-r--r--R/WP_known.R30
1 files changed, 13 insertions, 17 deletions
diff --git a/R/WP_known.R b/R/WP_known.R
index 40f1ded..6b0e2ea 100644
--- a/R/WP_known.R
+++ b/R/WP_known.R
@@ -1,27 +1,23 @@
#' WP method background function WP_known
#'
-#' This is a background/internal function called by \code{WP}. It computes the maximum likelihood estimator of R0 assuming that the serial distribution is known and finite discrete.
+#' This is a background/internal function called by \code{WP}. It computes the maximum
+#' likelihood estimator of R0 assuming that the serial distribution is known and finite discrete.
#'
#' @param NT vector of case counts
#' @param p discretized version of the serial distribution
#' @return The function returns \code{Rhat}, the maximum likelihood estimator of R0.
+#'
#' @export
-#
+WP_known <- function(NT, p) {
+ 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)
+ }
-WP_known <- function(NT, p){
-
- 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)
- }
- Rhat <- sum(NT[-1])/sum(mu_t)
+ Rhat <- sum(NT[-1]) / sum(mu_t)
return(list(Rhat=Rhat))
-
}
-
-