synthesize {ipfr} | R Documentation |
Creates a synthetic population based on ipu results
Description
A simple function that takes the weight_tbl
output from
ipu
and randomly samples based on the weight.
Usage
synthesize(weight_tbl, group_by = NULL, primary_id = "id")
Arguments
weight_tbl |
the |
group_by |
if provided, the |
primary_id |
The field used to join the primary and secondary seed
tables. Only necessary if |
Value
A data.frame
with one record for each synthesized member of
the population (e.g. household). A new_id
column is created, but
the previous primary_id
column is maintained to facilitate joining
back to other data sources (e.g. a person attribute table).
Examples
hh_seed <- dplyr::tibble(
id = c(1, 2, 3, 4),
siz = c(1, 2, 2, 1),
weight = c(1, 1, 1, 1),
geo_cluster = c(1, 1, 2, 2)
)
hh_targets <- list()
hh_targets$siz <- dplyr::tibble(
geo_cluster = c(1, 2),
`1` = c(75, 100),
`2` = c(25, 150)
)
result <- ipu(hh_seed, hh_targets, max_iterations = 5)
synthesize(result$weight_tbl, "geo_cluster")
[Package ipfr version 1.0.2 Index]