#' \code{inputs} is a list of the original input variables \code{NT, mu}.\r
#'\r
#' @examples\r
-#'\r
#' ## ===================================================== ##\r
#' ## Illustrate on weekly data ##\r
#' ## ===================================================== ##\r
#'\r
#' NT <- c(1, 4, 10, 5, 3, 4, 19, 3, 3, 14, 4)\r
#' ## obtain Rhat when serial distribution has mean of five days\r
-#' res1 <- ID(NT=NT, mu=5/7)\r
-#' res1$Rhat\r
+#' ID(NT=NT, mu=5/7)\r
#' ## obtain Rhat when serial distribution has mean of three days\r
-#' res2 <- ID(NT=NT, mu=3/7)\r
-#' res2$Rhat\r
+#' ID(NT=NT, mu=3/7)\r
#'\r
#' ## ========================================================= ##\r
#' ## Compute Rhat using only the first five weeks of data ##\r
#' ## ========================================================= ##\r
#'\r
-#'\r
-#' res3 <- ID(NT=NT[1:5], mu=5/7) # serial distribution has mean of five days\r
-#' res3$Rhat\r
+#' ID(NT=NT[1:5], mu=5/7) # serial distribution has mean of five days\r
#'\r
#' @export\r
ID <- function(NT, mu) {\r
\r
R0_ID <- exp(sum(y) / TT)\r
\r
- return(list=c(Rhat=R0_ID, inputs=list(NT=NT, mu=mu)))\r
+ return(R0_ID)\r
}\r
#' \code{inputs} is a list of the original input variables \code{NT, mu}.\r
#'\r
#' @examples\r
-#'\r
#' ## ===================================================== ##\r
#' ## Illustrate on weekly data ##\r
#' ## ===================================================== ##\r
#'\r
#' NT <- c(1, 4, 10, 5, 3, 4, 19, 3, 3, 14, 4)\r
#' ## obtain Rhat when serial distribution has mean of five days\r
-#' res1 <- IDEA(NT=NT, mu=5/7)\r
-#' res1$Rhat\r
+#' IDEA(NT=NT, mu=5/7)\r
#' ## obtain Rhat when serial distribution has mean of three days\r
-#' res2 <- IDEA(NT=NT, mu=3/7)\r
-#' res2$Rhat\r
+#' IDEA(NT=NT, mu=3/7)\r
#'\r
#' ## ========================================================= ##\r
#' ## Compute Rhat using only the first five weeks of data ##\r
#' ## ========================================================= ##\r
#'\r
-#'\r
-#' res3 <- IDEA(NT=NT[1:5], mu=5/7) # serial distribution has mean of five days\r
-#' res3$Rhat\r
+#' IDEA(NT=NT[1:5], mu=5/7) # serial distribution has mean of five days\r
#'\r
#' @export\r
IDEA <- function(NT, mu) {\r
IDEA2 <- TT * sum(y2) - sum(s)^2\r
IDEA <- exp(IDEA1 / IDEA2)\r
\r
- return(list(Rhat=IDEA, inputs=list(NT=NT, mu=mu)))\r
+ return(IDEA)\r
}\r
}\r
#' res3 <- WP(NT=NT)
#' res3$Rhat
#' ## find mean of estimated serial distribution
-#' serial <- res3$SD
-#' sum(serial$supp*serial$pmf)
+#' serial <- res3$SD
+#' sum(serial$supp * serial$pmf)
#'
#' ## ========================================================= ##
#' ## Compute Rhat using only the first five weeks of data ##
#' ## ========================================================= ##
#'
-#' res4 <- WP(NT=NT[1:5], mu=5/7, method="known") # serial distribution has mean of five days
+#' res4 <- WP(NT=NT[1:5], mu=5/7, method="known") # serial distribution has mean of five days
#' res4$Rhat
#'
#' @export
p <- diff(pexp(0:range.max, 1/mu))
p <- p / sum(p)
res <- WP_known(NT=NT, p=p)
- Rhat <- res$Rhat
+ Rhat <- res
JJ <- NA
}
}
- return(list(Rhat=Rhat, check=length(JJ), SD=list(supp=1:range.max, pmf=p), inputs=list(NT=NT, mu=mu, method=method, search=search, tol=tol)))
+ return(list(Rhat=Rhat, check=length(JJ), SD=list(supp=1:range.max, pmf=p)))
}
}
Rhat <- sum(NT[-1]) / sum(mu_t)
- return(list(Rhat=Rhat))
+ return(Rhat)
}
p <- diff(pgamma(0:range.max, shape=shape[i], scale=scale[j]))
p <- p / sum(p)
mle <- WP_known(NT, p)
- resLL[i,j] <- computeLL(p, NT, mle$R)
- resR0[i,j] <- mle$R
+ resLL[i,j] <- computeLL(p, NT, mle)
+ resR0[i,j] <- mle
}
}
#' ## ============================================================= ##
#'
#' Rpost <- res1$posterior
-#' loc <- which(Rpost$pmf==max(Rpost$pmf))
-#' Rpost$supp[loc] # posterior mode
-#' res1$Rhat # compare with posterior mean
+#' loc <- which(Rpost$pmf == max(Rpost$pmf))
+#' Rpost$supp[loc] # posterior mode
+#' res1$Rhat # compare with posterior mean
#'
-#' par(mfrow=c(2,1), mar=c(2,2,1,1))
+#' par(mfrow=c(2, 1), mar=c(2, 2, 1, 1))
#' plot(Rpost$supp, Rpost$pmf, col="black", type="l", xlab="", ylab="")
#' abline(h=1/(20/0.01+1), col="red")
#' abline(v=res1$Rhat, col="blue")
#' abline(v=Rpost$supp[loc], col="purple")
#' legend("topright", legend=c("prior", "posterior", "posterior mean (Rhat)", "posterior mode"), col=c("red", "black", "blue", "purple"), lty=1)
-#' plot(Rpost$supp, Rpost$pmf, col="black", type="l", xlim=c(0.5,1.5), xlab="", ylab="")
+#' plot(Rpost$supp, Rpost$pmf, col="black", type="l", xlim=c(0.5, 1.5), xlab="", ylab="")
#' abline(h=1/(20/0.01+1), col="red")
#' abline(v=res1$Rhat, col="blue")
#' abline(v=Rpost$supp[loc], col="purple")
#' ## ========================================================= ##
#' ## Compute Rhat using only the first five weeks of data ##
#' ## ========================================================= ##
-#'
#'
#' res3 <- seqB(NT=NT[1:5], mu=5/7) # serial distribution has mean of five days
#' res3$Rhat
Rhat <- sum(R * posterior)
- return(list(Rhat=Rhat, posterior=list(supp=R, pmf=posterior), group=group, inputs=list(NT=NT, mu=mu, kappa=kappa)))
+ return(list(Rhat=Rhat, posterior=list(supp=R, pmf=posterior), group=group))
}
}