summaryrefslogtreecommitdiff
path: root/R/WP_known.R
diff options
context:
space:
mode:
authorhannajankowski <hkj@yorku.ca>2022-06-09 17:57:31 -0400
committerhannajankowski <hkj@yorku.ca>2022-06-09 17:57:31 -0400
commit14ec98c9bfc49f963e30159dc7db9f554088fb44 (patch)
treeccdd49f5dd1cda78357bf7c9d0a7c80b25ca3130 /R/WP_known.R
Testing testing 123
Diffstat (limited to 'R/WP_known.R')
-rw-r--r--R/WP_known.R27
1 files changed, 27 insertions, 0 deletions
diff --git a/R/WP_known.R b/R/WP_known.R
new file mode 100644
index 0000000..40f1ded
--- /dev/null
+++ b/R/WP_known.R
@@ -0,0 +1,27 @@
+#' 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.
+#'
+#' @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)]
+# 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)
+ return(list(Rhat=Rhat))
+
+}
+
+