Skip to contents

Prepares the initial expansion summary table (Table 1) for the weighting memo, summarizing household segments, invitations, reference counts, adjusted counts, initial expansion factors, and convenience sample rates. Use to report initial weighting and expansion statistics.

Usage

prep_initial_expansion_data(settings)

Arguments

settings

list. Project settings; must include paths for sample plan, seed weights, and working directory, plus study_unit.

Value

data.table. Initial expansion summary table. Columns:

  • segment_name : household segment

  • invitation : invitation type (ABS, NPS)

  • day_group : day-of-week group

  • hh : number of households

  • ref : reference count

  • ref_adj : adjusted reference count (sum of initial weights)

  • ief : initial expansion factor

  • C : convenience sample rate

  • sort_order : custom sort order

  • Total row has NA for ief, C, and ref.

Details

  • Loads sample plan and seed-weighted household data from settings.

  • Aggregates reference counts by segment and invitation type.

  • If study_unit is "household", uses household reference counts; else uses person reference counts.

  • Renames "Non-probability" segment to "Supplemental" for reporting.

  • Joins reference counts to seed-weighted data.

  • Aggregates by segment, invitation, and day group:

    • hh: number of households

    • ref: reference count

    • ref_adj: sum of initial weights (rounded)

    • ief: initial expansion factor

  • Uses janitor::adorn_totals() to add total row.

  • Orders table by invitation and segment.

  • Calculates convenience sample rate C using calc_alpha():

    • C for ABS: 1 - C_val

    • C for NPS: C_val

    • Rounds C to 4 decimals.

  • Sets ief, C, and ref to NA for total row.

  • Sets column order with setcolorder().

  • Adds sort_order for custom sorting.

  • Returns table ordered by sort order and segment name.

  • Error handling: none explicit; assumes valid settings and input files.

  • TODO: Validate that totals match (see code comments).

  • TODO: Confirm that convenience sample rate matches weighting logic; may break if initial weighting for NPS is revised.

Settings

  • study_unit (direct): selects household or person reference counts.

  • working_dir (direct): path for input files.

  • seed_wtd_path (direct): path to seed-weighted household data.

See also

calc_alpha, fetch_hts_table

Examples

## Not run:
prep_initial_expansion_data(settings)
#> Error: object 'settings' not found
## End(Not run)