Skip to contents

Calculates a marginal distribution for one or more variables in a synthetic population.

Usage

get_margin_series_from_synthetic_population(df_synth_pop, margins)

Arguments

df_synth_pop

A synthetic population stored as a data.frame or data.table.

margins

Character vector identifying the variables that define the margin.

Value

A data frame containing the requested grouping variables and a count column.

Details

The resulting margin can be used for:

  • Validation.

  • Comparison with external data sources.

  • Iterative proportional fitting (IPF).

  • Diagnostic reporting.

The function aggregates the synthetic population over the supplied variables and counts the number of agents in each resulting category.

Unlike synthetic_population_to_contingency, this function is intended specifically for marginal distributions rather than higher-dimensional contingency tables.

Examples

population <- data.frame(
  gender = c(
    "Male",
    "Male",
    "Female"
  )
)

get_margin_series_from_synthetic_population(
  population,
  "gender"
)
#> $gender
#> [1] 2 1
#>