StandardizationReference.RdEncapsulates a reference population for direct method standardization. Stores population weights by age and gender with metadata.
The StandardizationReference class provides a structured way to manage reference populations used for age-sex standardization. It validates data structure, auto-calculates weights as proportions, and provides methods for accessing and manipulating reference data.
nameName of the reference population (active)
countryCountry or region (active)
yearYear of reference (numeric) (active)
sourceSource/citation (active)
referenceURL or reference to access source data (active)
new()Create a new StandardizationReference
StandardizationReference$new(
name,
country,
year,
source,
data,
reference = NULL
)getAdjustedReference()Apply both bounds filtering and age truncation
StandardizationReference$getAdjustedReference(
ageMin = NULL,
ageMax = NULL,
rightTruncation = NULL
)validateRightTruncation()Validate right truncation point against reference age groups
For single-year references, any integer age is valid. For grouped references, the truncation point must fall exactly at the start of an age group (e.g., "85" for "85+" group, "80" for "80-84" group). Fails fast if truncation falls mid-group.
getValidTruncationPoints()Get valid truncation points for this reference
Returns a numeric vector of all valid age thresholds where right truncation is allowed (start of each age group for grouped references, all ages for single-year references).
mapAgesToReference()Map single-year ages to reference age group labels
Converts a character/numeric vector of ages (some possibly \"N+\" labels from right truncation) to the reference's age label format so prevalence data can be joined to reference weights by (age, gender).
Works generically for any reference type:
Already-truncated \"N+\" values pass through unchanged
Single-year references (Decennial Census): zero-pad numeric values
Grouped references (ACS, WHO): lookup which group each numeric age falls into
if (FALSE) {
# Create a custom reference
ref_data <- data.frame(
age = c("0", "1", "2", "100+", "0", "1", "2", "100+"),
gender = c(rep("Male", 4), rep("Female", 4)),
population = c(100000, 95000, 92000, 50000, 98000, 93000, 90000, 48000)
)
my_ref <- StandardizationReference$new(
name = "Custom Reference",
country = "Custom",
year = 2020L,
source = "My Data",
data = ref_data
)
# View reference
my_ref$viewReference()
# Get total population
my_ref$getTotalPopulation()
# Filter to age range
filtered <- my_ref$getFilteredReference(ageMin = 18, ageMax = 65)
}