Skip to contents

Creates a contingency table that aligns external population data with an existing synthetic agent population.

Usage

make_matched_contingency(
  agents_dt,
  data_tb,
  conditioned_on_chr,
  age_coding_1L_chr = "four",
  age_new_1L_chr = "AgeGroup4",
  age_old_1L_chr = "agep",
  categories_1L_chr = c("one", "multiple"),
  drop_missing_1L_lgl = FALSE,
  filters_ls = list(),
  new_missing_chr = c("Not stated", "_N"),
  new_options_chr = c("Yes", "No"),
  new_target_1L_chr = "MentalHealthCondition",
  new_total_chr = c("Total", "_T"),
  new_var_chr = c("Mental Health Condition", "91"),
  sex_old_1L_chr = "sexp",
  sex_new_1L_chr = "SEXP",
  target_1L_chr = "lthp",
  region_type_1L_chr = "SA3"
)

Arguments

agents_dt

A synthetic agent population stored as a data.table.

data_tb

Source dataset used to construct the contingency table.

conditioned_on_chr

Character vector specifying conditioning variables.

age_coding_1L_chr

Age coding scheme passed to add_recoded_age().

age_new_1L_chr

Name of the derived age-group variable.

age_old_1L_chr

Name of the source age variable.

categories_1L_chr

Either "one" for binary attributes or "multiple" for multi-category attributes.

drop_missing_1L_lgl

Logical indicating whether records with missing values should be removed.

filters_ls

Named list of filtering criteria.

new_missing_chr

Labels representing missing values.

new_options_chr

Labels representing binary response options.

new_target_1L_chr

Name of the generated target variable.

new_total_chr

Labels representing total categories.

new_var_chr

Labels representing positive cases.

sex_old_1L_chr

Name of the source sex variable.

sex_new_1L_chr

Name of the output sex variable.

target_1L_chr

Name of the source target variable.

region_type_1L_chr

Geographic aggregation level.

Value

A data.table contingency table suitable for use with ReplicaAdder().

Details

The function transforms source data into a format suitable for use with ReplicaAdder, ensuring that all combinations present in the agent population are represented in the resulting contingency table.

The function supports both binary and multi-category attributes and can optionally generate records for missing combinations.

Examples

if (FALSE) { # \dontrun{
make_matched_contingency(
  agents_dt,
  data_tb = health_tb,
  conditioned_on_chr = c(
    "SA3",
    "AgeGroup4",
    "SEXP"
  ),
  target_1L_chr = "lthp"
)
} # }