Encapsulates a reference population for direct method standardization. Stores population weights by age and gender with metadata.

Details

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.

Active bindings

name

Name of the reference population (active)

country

Country or region (active)

year

Year of reference (numeric) (active)

source

Source/citation (active)

reference

URL or reference to access source data (active)

Methods


Method new()

Create a new StandardizationReference

Usage

StandardizationReference$new(
  name,
  country,
  year,
  source,
  data,
  reference = NULL
)

Arguments

name

Character. Name of reference (e.g., "USA Census 2020")

country

Character. Country/region name

year

Integer. Reference year

source

Character. Data source description

data

Data frame with columns: age, gender, population

reference

Character. URL or reference to access the source data

Returns

A new StandardizationReference object


Method viewReference()

View the reference population data

Usage

StandardizationReference$viewReference()


Method getData()

Get the full reference data frame

Usage

StandardizationReference$getData()

Returns

Data frame with columns: age, gender, population, weight


Method getTotalPopulation()

Get total population

Usage

StandardizationReference$getTotalPopulation()

Returns

Numeric value


Method getAgeValues()

Get unique ages

Usage

StandardizationReference$getAgeValues()

Returns

Character vector of age values


Method getGenderValues()

Get unique genders

Usage

StandardizationReference$getGenderValues()

Returns

Character vector of gender values


Method getMetadata()

Get metadata as list

Usage

StandardizationReference$getMetadata()

Returns

List with name, country, year, source, reference


Method getFilteredReference()

Filter reference to demographic bounds and re-normalize weights

Usage

StandardizationReference$getFilteredReference(ageMin = NULL, ageMax = NULL)

Arguments

ageMin

Minimum age (inclusive)

ageMax

Maximum age (inclusive)

Returns

Data frame filtered and re-normalized to bounds


Method getAdjustedReference()

Apply both bounds filtering and age truncation

Usage

StandardizationReference$getAdjustedReference(
  ageMin = NULL,
  ageMax = NULL,
  rightTruncation = NULL
)

Arguments

ageMin

Minimum age (inclusive)

ageMax

Maximum age (inclusive)

rightTruncation

Age threshold for truncation (optional)

Returns

Data frame with both transformations applied


Method 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.

Usage

StandardizationReference$validateRightTruncation(rightTruncation)

Arguments

rightTruncation

Numeric. Age threshold to validate.

Returns

Numeric. The validated truncation point (or stop with error)


Method 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).

Usage

StandardizationReference$getValidTruncationPoints()

Returns

Numeric vector of valid truncation points


Method 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

Usage

StandardizationReference$mapAgesToReference(age_values)

Arguments

age_values

Character/numeric vector. May contain \"N+\" suffix values or numeric strings.

Returns

Character vector of reference-formatted age labels


Method clone()

The objects of this class are cloneable with this method.

Usage

StandardizationReference$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

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)
}