Prepare initial expansion summary table for weighting memo
prep_initial_expansion_data.RdPrepares 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.
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, andref.
Details
Loads sample plan and seed-weighted household data from settings.
Aggregates reference counts by segment and invitation type.
If
study_unitis "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 householdsref: reference countref_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
Cusingcalc_alpha():Cfor ABS:1 - C_valCfor NPS:C_valRounds
Cto 4 decimals.
Sets
ief,C, andrefto NA for total row.Sets column order with
setcolorder().Adds
sort_orderfor 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.