synthesize: Creates a synthetic population based on ipu results

Description Usage Arguments Value Examples

View source: R/synthesize.R

Description

A simple function that takes the weight_tbl output from ipu and randomly samples based on the weight.

Usage

1
synthesize(weight_tbl, group_by = NULL, primary_id = "id")

Arguments

weight_tbl

the data.frame of the same name output by ipu.

group_by

if provided, the data.frame will be grouped by this variable before sampling. If not provided, tidyverse/dplyr groupings will be respected. If no grouping info is present, samples are drawn from the entire table.

primary_id

The field used to join the primary and secondary seed tables. Only necessary if secondary_seed is provided.

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
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")

ipfr documentation built on April 2, 2020, 1:12 a.m.