
Calculate an Age Range from an Age-Gap Specification
Source:R/fn_utils-extractors.R
calculate_age_range_from_gap.RdConverts an age-gap specification into a valid age range for candidate selection.
Details
Given a reference age and lower/upper age-gap bounds, the function calculates the corresponding acceptable age range.
This function is used by the household-generation subsystem when searching for compatible partners.
Age bounds are calculated by adding the supplied age-gap values to the reference age.
For example:
age = 40
gap_start = -5
gap_end = 5produces:
age_start = 35
age_end = 45If the calculated lower bound is greater than the upper bound, the two values are automatically swapped so that the returned interval is always valid.
This behaviour mirrors the original GenSynthPop implementation.
Examples
calculate_age_range_from_gap(
age = 40,
gap_start = -5,
gap_end = 5
)
#> $age_start
#> [1] 35
#>
#> $age_end
#> [1] 45
#>
calculate_age_range_from_gap(
age = 40,
gap_start = 5,
gap_end = 15
)
#> $age_start
#> [1] 45
#>
#> $age_end
#> [1] 55
#>
calculate_age_range_from_gap(
age = 40,
gap_start = -10,
gap_end = -5
)
#> $age_start
#> [1] 30
#>
#> $age_end
#> [1] 35
#>