Skip to contents

Calculates day weights for each person in each household, adjusting for unrelated persons and incomplete days. Use to generate day-level weights for downstream weighting steps.

Usage

calc_day_weights(
  person_weights,
  households,
  persons,
  days,
  trips,
  value_labels,
  settings
)

Arguments

person_weights

data.table with required columns:

  • hh_id

  • person_id

  • day_group

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

households

data.table. Household-level variables.

persons

data.table. Person-level variables.

days

data.table with required columns:

  • hh_id

  • person_id

  • day_id

  • day_group

  • travel_dow

  • num_trips

  • is_complete

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

trips

data.table. Trip-level variables.

value_labels

data.table. Value labels for categorical variables.

settings

list. Must include:

  • unrelated_adjustment — adjustment method

  • weight_dow_groups — valid day-of-week groups

Value

data.table with columns:

  • hh_id

  • person_id

  • day_id

  • day_group

  • num_trips

  • day_weight Rows: one per person-day. Keys: (hh_id, person_id, day_id).

Details

  • Adjusts person weights for unrelated persons if specified in settings.

  • Merges day, person, and household data to assign weights.

  • Sets weights to zero for non-study or incomplete days.

  • Checks consistency between person and day weights.

  • Returns a copy; does not modify by reference.

Settings

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

  • weight_dow_groups (direct): Valid day-of-week groups. Default from settings.

Examples

## Not run:
person_weights <- data.table(
  hh_id = 1,
  person_id = 1,
  day_group = "weekday",
  person_weight = 1.2
)
households <- data.table()
persons <- data.table()
days <- data.table(
  hh_id = 1,
  person_id = 1,
  day_id = 1,
  day_group = "weekday",
  travel_dow = "Mon",
  num_trips = 2,
  is_complete = 1,
  hh_day_complete = 1
)
trips <- data.table()
value_labels <- data.table()
settings <- list(
  unrelated_adjustment = "day",
  weight_dow_groups = c("Mon", "Tue")
)
calc_day_weights(
  person_weights,
  households,
  persons,
  days,
  trips,
  value_labels,
  settings
)
#> Setting non-surveyed person-day weights to 0 and adjusting up remaining person-day weights.
#> Error in .checkTypos(e, names_x): Object 'variable' not found amongst []
## End(Not run)