diff --git a/R/calc_new_immunity.R b/R/calc_new_immunity.R index 26d314d..aa0547f 100644 --- a/R/calc_new_immunity.R +++ b/R/calc_new_immunity.R @@ -66,6 +66,21 @@ assert_valid_targeting <- function(x, name = deparse(substitute(x))) { ##' @return A dataframe containing the `popim_population` aggregated by age. ##' @author Tini Garske ##' @export +##' @examples +##' ## set up population and vaccination activities: +##' pop <- popim_population(region = "UK", year_min = 2000, year_max = 2005, +##' age_min = 0, age_max = 10) +##' vacc <- popim_vacc_activities(region = "UK", year = c(2001, 2002), +##' age_first = 0, age_last = 0, +##' coverage = 0.8, doses = NA, +##' targeting = "random") +##' +##' ## update the population immunity based on the vaccination activities: +##' pop <- apply_vacc(pop, vacc) +##' +##' ## calculate the population immunity aggregated across ages: +##' pop_aggregated <- calc_pop_immunity(pop) +##' calc_pop_immunity <- function(pop) { assert_population(pop) diff --git a/R/plotting.R b/R/plotting.R index 711dea5..a362e74 100644 --- a/R/plotting.R +++ b/R/plotting.R @@ -24,6 +24,24 @@ NULL ##' @rdname plotting ##' @export ##' @author Tini Garske +##' @examples +##' ## set up population and vaccination activities: +##' pop <- popim_population(region = "UK", year_min = 2000, year_max = 2005, +##' age_min = 0, age_max = 10) +##' vacc <- popim_vacc_activities(region = "UK", year = c(2001, 2002), +##' age_first = 0, age_last = 0, +##' coverage = 0.8, doses = NA, +##' targeting = "random") +##' +##' ## update the population immunity based on the vaccination activities: +##' pop <- apply_vacc(pop, vacc) +##' +##' ## plot the population size by age and time: +##' plot_pop_size(pop) +##' +##' ## plot the population immunity by age and time: +##' plot_immunity(pop) +##' plot_immunity <- function(pop) { assert_population(pop) diff --git a/R/popim_vacc_activities.R b/R/popim_vacc_activities.R index bbfb8d7..71c347a 100644 --- a/R/popim_vacc_activities.R +++ b/R/popim_vacc_activities.R @@ -226,6 +226,21 @@ as_vacc_activities <- function(df) { ##' updated to have both `doses` and `coverage` information. ##' @author Tini Garske ##' @export +##' @examples +##' ## set up some vaccination activities: +##' vacc <- popim_vacc_activities(region = "UK", year = 2001:2003, +##' age_first = 0, age_last = 0, +##' coverage = c(0.8, 0.8, NA), +##' doses = c(NA, NA, 60), +##' targeting = "random") +##' ## set up a population to which these activities shall apply: +##' pop <- popim_population(region = "UK", year_min = 2000, year_max = 2005, +##' age_min = 0, age_max = 10) +##' pop$pop_size <- 100 ## cohort size of 100 for all cohorts +##' +##' ## fill in missing coverage/doses information based on population size: +##' vacc <- complete_vacc_activities(vacc, pop) +##' complete_vacc_activities <- function(vacc, pop) { validate_vacc_activities(vacc) stopifnot(is_population(pop)) diff --git a/man/calc_pop_immunity.Rd b/man/calc_pop_immunity.Rd index 2be538d..a4fa3fd 100644 --- a/man/calc_pop_immunity.Rd +++ b/man/calc_pop_immunity.Rd @@ -16,6 +16,22 @@ A dataframe containing the \code{popim_population} aggregated by age. \description{ Calculate the overall population immunity (aggregating over age) from the supplied \code{popim_population} object. +} +\examples{ +## set up population and vaccination activities: +pop <- popim_population(region = "UK", year_min = 2000, year_max = 2005, + age_min = 0, age_max = 10) +vacc <- popim_vacc_activities(region = "UK", year = c(2001, 2002), + age_first = 0, age_last = 0, + coverage = 0.8, doses = NA, + targeting = "random") + +## update the population immunity based on the vaccination activities: +pop <- apply_vacc(pop, vacc) + +## calculate the population immunity aggregated across ages: +pop_aggregated <- calc_pop_immunity(pop) + } \author{ Tini Garske diff --git a/man/complete_vacc_activities.Rd b/man/complete_vacc_activities.Rd index b87da57..6a97c49 100644 --- a/man/complete_vacc_activities.Rd +++ b/man/complete_vacc_activities.Rd @@ -23,6 +23,22 @@ using the target population size implied by the \code{popim_population} object supplied. If both coverage and doses are given for any activity, the function checks if they are consistent with the population size, and fails if there are any inconsistencies. +} +\examples{ +## set up some vaccination activities: +vacc <- popim_vacc_activities(region = "UK", year = 2001:2003, + age_first = 0, age_last = 0, + coverage = c(0.8, 0.8, NA), + doses = c(NA, NA, 60), + targeting = "random") +## set up a population to which these activities shall apply: +pop <- popim_population(region = "UK", year_min = 2000, year_max = 2005, + age_min = 0, age_max = 10) +pop$pop_size <- 100 ## cohort size of 100 for all cohorts + +## fill in missing coverage/doses information based on population size: +vacc <- complete_vacc_activities(vacc, pop) + } \author{ Tini Garske diff --git a/man/plotting.Rd b/man/plotting.Rd index 897908a..25df68b 100644 --- a/man/plotting.Rd +++ b/man/plotting.Rd @@ -36,6 +36,25 @@ immune, therefore varying between 0 and 1. As the returned object is a regular \code{ggplot} object, it can be further modified with the ususal \code{ggplot2} syntax. +} +\examples{ +## set up population and vaccination activities: +pop <- popim_population(region = "UK", year_min = 2000, year_max = 2005, + age_min = 0, age_max = 10) +vacc <- popim_vacc_activities(region = "UK", year = c(2001, 2002), + age_first = 0, age_last = 0, + coverage = 0.8, doses = NA, + targeting = "random") + +## update the population immunity based on the vaccination activities: +pop <- apply_vacc(pop, vacc) + +## plot the population size by age and time: +plot_pop_size(pop) + +## plot the population immunity by age and time: +plot_immunity(pop) + } \author{ Tini Garske