diff --git a/R/get_R.R b/R/get_R.R index 446a659..02f2b6c 100644 --- a/R/get_R.R +++ b/R/get_R.R @@ -26,6 +26,17 @@ #' \code{as.data.frame} to double-check that the epicurve includes the last #' 'zeros'. #' +#' @return A list with the \code{earlyR} class, containing the following +#' components: +#' \itemize{ +#' \item +#' +#' \item +#' +#' \item +#' +#' } +#' #' @examples #' #' if (require(incidence)) { @@ -35,7 +46,7 @@ #' x #' as.data.frame(x) #' plot(x) -#' res <- get_R(x) +#' res <- get_R(x, disease = "ebola") #' res #' plot(res) #' plot(res, "lambdas") @@ -186,7 +197,8 @@ get_R.integer <- function(x, disease = NULL, si = NULL, #' @aliases get_R.numeric get_R.numeric <- function(x, ...) { - get_R(as.integer(x), ...) + out <- get_R(as.integer(x), ...) + out$incidence <- x } @@ -219,5 +231,6 @@ get_R.incidence <- function(x, ...) { out$dates <- min(x$dates) - 1 + out$dates } + out$incidence <- x return(out) } diff --git a/R/plot.earlyR.R b/R/plot.earlyR.R index 4cbbb36..102181c 100644 --- a/R/plot.earlyR.R +++ b/R/plot.earlyR.R @@ -22,7 +22,22 @@ #' #' @param ... Further arguments to be passed to other methods (not used). #' - +#' if (require(incidence)) { +#' +#' ## example: onsets on days 1, 5, 6 and 12; estimation on day 24 +#' onset <- c(1, 5, 6, 12) +#' x <- incidence(onset, last_date = 24) +#' x +#' +#' res <- get_R(x, disease = "ebola") +#' res +#' plot(res) +#' plot(res, "lambdas") +#' plot(res, "lambdas", scaling = 5) +#' points(onset, 1:4, cex = 3, pch = 20) +#' +#' } +# plot.earlyR <- function(x, type = c("R", "lambdas"), scale = 1, ...) { type <- match.arg(type) diff --git a/R/sample_R.R b/R/sample_R.R index 64f13fd..6849c7d 100644 --- a/R/sample_R.R +++ b/R/sample_R.R @@ -14,7 +14,7 @@ #' if (require(incidence)) { #' x <- incidence(c(1, 5, 5, 12, 45, 65)) #' plot(x) -#' res <- get_R(x) +#' res <- get_R(x, disease = "ebola") #' res #' plot(res) #' diff --git a/man/get_R.Rd b/man/get_R.Rd index f36a1fc..60c204d 100644 --- a/man/get_R.Rd +++ b/man/get_R.Rd @@ -71,7 +71,7 @@ if (require(incidence)) { x as.data.frame(x) plot(x) - res <- get_R(x) + res <- get_R(x, disease = "ebola") res plot(res) plot(res, "lambdas") diff --git a/man/plot.earlyR.Rd b/man/plot.earlyR.Rd index 5399ecf..e94ccac 100644 --- a/man/plot.earlyR.Rd +++ b/man/plot.earlyR.Rd @@ -19,7 +19,23 @@ the force of infection over time.} \item{scale}{A numeric value indicating the scaling factor for lambdas on the 'y' axis.} -\item{...}{Further arguments to be passed to other methods (not used).} +\item{...}{Further arguments to be passed to other methods (not used). + +if (require(incidence)) { + +## example: onsets on days 1, 5, 6 and 12; estimation on day 24 +onset <- c(1, 5, 6, 12) +x <- incidence(onset, last_date = 24) +x + +res <- get_R(x, disease = "ebola") +res +plot(res) +plot(res, "lambdas") +plot(res, "lambdas", scaling = 5) +points(onset, 1:4, cex = 3, pch = 20) + +}} } \description{ These functions are designed for plotting \code{earlyR} objects, output by diff --git a/man/sample_R.Rd b/man/sample_R.Rd index 64411cf..c075e7a 100644 --- a/man/sample_R.Rd +++ b/man/sample_R.Rd @@ -21,7 +21,7 @@ values of R are directly proportional to their likelihood. if (require(incidence)) { x <- incidence(c(1, 5, 5, 12, 45, 65)) plot(x) - res <- get_R(x) + res <- get_R(x, disease = "ebola") res plot(res) diff --git a/tests/testthat/rds/R_1.rds b/tests/testthat/rds/R_1.rds index dccb34e..ccc5fee 100644 Binary files a/tests/testthat/rds/R_1.rds and b/tests/testthat/rds/R_1.rds differ