Skip to content

Commit

Permalink
fix issues with examples
Browse files Browse the repository at this point in the history
  • Loading branch information
pearsonca committed Dec 6, 2024
1 parent 693fa2f commit e833d64
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 36 deletions.
11 changes: 5 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@ Authors@R:
comment = c(ORCID = "0000-0002-0380-1503")),
person("Lucy", "Goodfellow", , "lucy.goodfellow@lshtm.ac.uk", role = c("aut"),
comment = c(ORCID = "0009-0004-0434-5863")))
Description: A convenient framework for aggregating
and disaggregating continuously varying parameters (for example, case fatality
ratio, with age) for proper parametrization of lower-resolution compartmental
models (for example, with broad age categories) and subsequent upscaling of
model outputs to high resolution (for example, as needed when calculating
age-sensitive measures like years-life-lost).
Description: A convenient framework for aggregating and disaggregating continuously
varying parameters (for example, case fatality ratio, with age) for proper
parametrization of lower-resolution compartmental models (for example, with
broad age categories) and subsequent upscaling of model outputs to high resolution
(for example, as needed when calculating age-sensitive measures like years-life-lost).
License: MIT + file LICENSE
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
Expand Down
42 changes: 27 additions & 15 deletions R/aggregate.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ utils::globalVariables(c(
#' ifr_levin <- function(age_in_years) {
#' (10^(-3.27 + 0.0524 * age_in_years))/100
#' }
#' age_limits <- c(seq(0, 69, by = 5), 70, 80, 100)
#' age_limits <- c(seq(0, 69, by = 5), 70, 80, 101)
#' age_pyramid <- data.frame(
#' from = 0:100, weight = ifelse(0:100 < 65, 1, .99^(0:100-64))
#' ) # flat age distribution, then 1% annual deaths
#' ifr_alembic <- alembic(ifr_levin, age_pyramid, age_limits, 0:100)
#' from = 0:101, weight = ifelse(0:101 < 65, 1, .99^(0:101-64))
#' )
#' age_pyramid$weight[102] <- 0
#' # flat age distribution, then 1% annual deaths, no one lives past 101
#' ifr_alembic <- alembic(ifr_levin, age_pyramid, age_limits, 0:101)
#'
#' @importFrom utils head tail
#' @importFrom stats integrate
Expand Down Expand Up @@ -115,11 +117,15 @@ alembic <- function(
#' ifr_levin <- function(age_in_years) {
#' (10^(-3.27 + 0.0524 * age_in_years))/100
#' }
#' age_limits <- c(seq(0, 69, by = 5), 70, 80, 100)
#'
#' age_limits <- c(seq(0, 69, by = 5), 70, 80, 101)
#' age_pyramid <- data.frame(
#' from = 0:99, weight = ifelse(0:99 < 65, 1, .99^(0:99-64))
#' ) # flat age distribution, then 1% annual deaths
#' alembic_dt <- alembic(ifr_levin, age_pyramid, age_limits, 0:100)
#' from = 0:101, weight = ifelse(0:101 < 65, 1, .99^(0:101-64))
#' )
#' age_pyramid$weight[102] <- 0
#' # flat age distribution, then 1% annual deaths, no one lives past 101
#'
#' alembic_dt <- alembic(ifr_levin, age_pyramid, age_limits, 0:101)
#'
#' ifr_blend <- blend(alembic_dt)
#' # the actual function
Expand All @@ -140,7 +146,8 @@ alembic <- function(
#' )
#' # properly aggregated, but not accounting for age distribution
#' bad_alembic_dt <- alembic(
#' ifr_levin, within(age_pyramid, weight <- 1), age_limits, 0:100
#' ifr_levin,
#' within(age_pyramid, weight <- c(rep(1, 101), 0)), age_limits, 0:101
#' )
#' ifr_unif <- blend(bad_alembic_dt)
#' lines(
Expand Down Expand Up @@ -188,13 +195,18 @@ blend <- function(
#' ifr_levin <- function(age_in_years) {
#' (10^(-3.27 + 0.0524 * age_in_years))/100
#' }
#' age_limits <- c(seq(0, 69, by = 5), 70, 80, 100)
#' age_pyramid <- data.table(
#' from = 0:99, weight = ifelse(0:99 < 65, 1, .99^(0:99-64))
#' ) # flat age distribution, then 1% annual deaths
#' alembic_dt <- alembic(ifr_levin, age_pyramid, age_limits, 0:100)
#'
#' results <- data.table(model_partition = head(age_limits, -1))[, value := 10]
#' age_limits <- c(seq(0, 69, by = 5), 70, 80, 101)
#' age_pyramid <- data.frame(
#' from = 0:101, weight = ifelse(0:101 < 65, 1, .99^(0:101-64))
#' )
#' age_pyramid$weight[102] <- 0
#' # flat age distribution, then 1% annual deaths, no one lives past 101
#'
#' alembic_dt <- alembic(ifr_levin, age_pyramid, age_limits, 0:101)
#'
#' results <- data.frame(model_partition = head(age_limits, -1))
#' results$value <- 10
#' distill(alembic_dt, results)
distill <- function(
alembic_dt, outcomes_dt, groupcol = names(outcomes_dt)[1]
Expand Down
10 changes: 6 additions & 4 deletions man/alembic.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 10 additions & 5 deletions man/blend.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 11 additions & 6 deletions man/distill.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e833d64

Please sign in to comment.