Skip to contents

Calculates person weights from household weights, adjusting for unrelated persons if specified. Use to generate person-level weights for weighting pipeline.

Usage

calc_person_weights(hh_weights, households, persons, value_labels, settings)

Arguments

hh_weights

data.table with required columns:

  • hh_id

  • day_group

  • n_complete_hh_days

  • hh_weight Rows: one per household-day group. Keys: (hh_id, day_group). Modified by reference: no (returns copy).

households

data.table. Household-level variables.

persons

data.table with required columns:

  • hh_id

  • person_id Rows: one per person. Keys: (hh_id, person_id). Modified by reference: no (returns copy).

value_labels

data.table. Value labels for categorical variables.

settings

list. Must include:

  • unrelated_adjustment — adjustment method

  • study_unit — study unit type

Value

data.table with columns:

  • hh_id

  • person_id

  • day_group

  • person_weight Rows: one per person-day group. Keys: (hh_id, person_id, day_group).

Details

  • Merges household weights with persons table.

  • Drops nonstudy_day records if weighted record exists.

  • Adjusts for unrelated persons if specified in settings.

  • Checks consistency between household and person weights.

  • Returns a copy; does not modify by reference.

Settings

  • unrelated_adjustment (direct): Adjustment method for unrelated persons. Default from settings.

  • study_unit (direct): Study unit type. Default from settings.

Examples

## Not run:
hh_weights <- data.table(hh_id = 1, day_group = "weekday", n_complete_hh_days = 5, hh_weight = 1.2)
households <- data.table()
persons <- data.table(hh_id = 1, person_id = 1)
value_labels <- data.table()
settings <- list(unrelated_adjustment = "person", study_unit = "household")
calc_person_weights(hh_weights, households, persons, value_labels, settings)
#> Error in colnamesInt(i, unname(on), check_dups = FALSE): argument specifying columns received non-existing column(s): cols[1]='hh_id'
## End(Not run)