Skip to contents

reaggregate_interval_rates() enables the reweighting of interval rates in to different intervals ranges. It first replicates the rates of a given age interval into the individual years of said interval. These are then aggregated allowing for a user specified weight vector.

Usage

reaggregate_interval_rates(
  lower_bounds,
  upper_bounds = NULL,
  rates,
  breaks,
  weights = NULL
)

Arguments

lower_bounds, upper_bounds

[integerish].

A pair of vectors representing the bounds of the current intervals.

If upper_bounds is NULL, it will be automatically set to c(lower_bounds[-1L], max_upper).

lower_bounds must be strictly less than upper_bounds and greater than or equal to zero.

Missing (NA) bounds are not permitted.

Double vectors will be coerced to integer.

rates

[numeric].

Vector of counts to be averaged.

breaks

[numeric].

1 or more non-negative cut points in increasing (strictly) order.

These correspond to the left hand side of the desired intervals (e.g. the closed side of [x, y).

Double values are coerced to integer prior to categorisation.

weights

[numeric]

Population weightings to apply for individual years.

If NULL (default) weights will be allocated proportional to the interval size.

If specified, must be of length most 2000 and represent weights in the range 0:1999.

weights of length less than 2000 will be padded with 0.

Value

A data frame with 4 entries; interval, lower_bound, upper_bound and an associated count.

Examples

reaggregate_interval_rates(
  lower_bounds = c(0, 5, 13),
  upper_bounds= c(5, 15, 100),
  rates = c(1, 0.1, 0.01),
  breaks = c(0, 1, 9, 15),
  weights = round(runif(70, 10, 30))
)
#>    interval lower_bound upper_bound       rate
#> 1    [0, 1)           0           1 1.00000000
#> 2    [1, 9)           1           9 0.52631579
#> 3   [9, 15)           9          15 0.07218182
#> 4 [15, Inf)          15         Inf 0.01000000

reaggregate_interval_rates(
  lower_bounds = c(0, 5, 13),
  rates = c(1, 0.1, 0.01),
  breaks = c(0, 1, 9, 15),
  weights = round(runif(70, 10, 30))
)
#>    interval lower_bound upper_bound       rate
#> 1    [0, 1)           0           1 1.00000000
#> 2    [1, 9)           1           9 0.51489362
#> 3   [9, 15)           9          15 0.07107143
#> 4 [15, Inf)          15         Inf 0.01000000