TimTaylor / ageutils

Utility functions for working with individual ages and intervals
https://timtaylor.github.io/ageutils
GNU General Public License v2.0
3 stars 0 forks source link

Reaggregate_interval_rates gives the wrong rate for the lowest bound #8

Open BlackEdder opened 2 weeks ago

BlackEdder commented 2 weeks ago
lu <- 95
 lst <- qs::qread(file = "~/Downloads/list.qs.gz")

  u_f <- function(v) {
    dplyr::lead(v) |>
      dplyr::coalesce(lu)
  }

  lst$data |>
    dplyr::reframe(ageutils::reaggregate_interval_rates(
      lower_bounds = lower_bound,
      upper_bounds = u_f(lower_bound),
      rates = value,
      breaks = lst$breaks,
    ), .by = c(sex))

I would expect the rate to be 7.1 for the first row, but instead it is 0.108

Data (using fake extension name to fool github) list.qs.gz

BlackEdder commented 2 weeks ago

This seems to be fixed if I pass weights, with the first 65 values set to zero (because I only start at lower_bound 65)

TimTaylor commented 2 weeks ago

yeah this looks odd :grimacing: . Taking a look now

TimTaylor commented 2 weeks ago

Can you try installing from https://github.com/TimTaylor/ageutils/commits/fix8/ and see if that works?

remotes::install_github("TimTaylor/ageutils", ref = "fix8")