split_interval_counts()
splits counts of a given age interval in to
counts for individual years based on a given weighting. Age intervals are
specified by their lower (closed) and upper (open) bounds, i.e. intervals
of the form [lower, upper).
Arguments
- lower_bounds, upper_bounds
[integerish]
.A pair of vectors representing the bounds of the intervals.
lower_bounds
must be strictly less thanupper_bounds
and greater than or equal to zero.Missing (NA) bounds are not permitted.
Double vectors will be coerced to integer.
- counts
[numeric]
.Vector of counts to be aggregated.
- max_upper
[integerish]
Represents the maximum upper bounds permitted upon splitting the data.
Any upper bound greater than this will be replaced with this value prior to splitting.
Double vectors will be coerced to integer.
- weights
[numeric]
Population weightings to apply for individual years.
If
NULL
(default) counts will be split evenly based on interval size.If specified, must be of length
max_upper
and represent weights in the range 0:(max_upper - 1).
Examples
split_interval_counts(
lower_bounds = c(0, 5, 10),
upper_bounds = c(5, 10, 20),
counts = c(5, 10, 30)
)
#> age count
#> 1 0 1
#> 2 1 1
#> 3 2 1
#> 4 3 1
#> 5 4 1
#> 6 5 2
#> 7 6 2
#> 8 7 2
#> 9 8 2
#> 10 9 2
#> 11 10 3
#> 12 11 3
#> 13 12 3
#> 14 13 3
#> 15 14 3
#> 16 15 3
#> 17 16 3
#> 18 17 3
#> 19 18 3
#> 20 19 3
split_interval_counts(
lower_bounds = c(0, 5, 10),
upper_bounds = c(5, 10, Inf),
counts = c(5, 10, 30),
max_upper = 15
)
#> Warning: `upper_bounds` greater than `max_upper` (15) have been replaced prior to splitting.
#> age count
#> 1 0 1
#> 2 1 1
#> 3 2 1
#> 4 3 1
#> 5 4 1
#> 6 5 2
#> 7 6 2
#> 8 7 2
#> 9 8 2
#> 10 9 2
#> 11 10 6
#> 12 11 6
#> 13 12 6
#> 14 13 6
#> 15 14 6
split_interval_counts(
lower_bounds = c(0, 5),
upper_bounds = c(5, 10),
counts = c(5, 10),
max_upper =10,
weights = 1:10
)
#> age count
#> 1 0 0.3333333
#> 2 1 0.6666667
#> 3 2 1.0000000
#> 4 3 1.3333333
#> 5 4 1.6666667
#> 6 5 1.5000000
#> 7 6 1.7500000
#> 8 7 2.0000000
#> 9 8 2.2500000
#> 10 9 2.5000000