Skip to contents

Calculates and returns the maximum absolute percent error among weighted variables comparing survey incidence to targets. Use to identify the variable with the largest fit discrepancy after weighting.

Usage

calc_max_error(
  seed_incidence_table,
  target_table,
  weights,
  weight_col = "final_weight"
)

Arguments

seed_incidence_table

data.table with required columns:

  • hh_id_dow — household-day identifier

  • p_* — person-level variables (prefix p_)

  • h_* — household-level variables (prefix h_) Rows: one per household-day. Keys: (hh_id_dow). Modified by reference: no (returns copy).

target_table

data.table with required columns:

  • hh_id_dow — household-day identifier

  • p_* — person-level target variables (prefix p_)

  • h_* — household-level target variables (prefix h_) Rows: one per household-day. Keys: (hh_id_dow). Modified by reference: no (returns copy).

weights

data.table with required columns:

  • hh_id_dow — household-day identifier

  • final_weight — weight value (or as specified by weight_col) Rows: one per household-day. Keys: (hh_id_dow). Modified by reference: no (returns copy).

weight_col

character(1). Name of the column in weights containing the weight values. Default: 'final_weight'.

Value

named numeric(1). Maximum absolute percent error, with variable name as name.

Details

  • Checks that household IDs are consistent and ordered between tables.

  • Computes weighted sums for all target columns (prefix p_ or h_).

  • Calculates absolute percent error for each variable.

  • Returns the maximum error and its variable name.

  • Returns a named numeric vector (variable name as name).

Settings

None.

See also

calc_weight_mape calc_weight_fit scripts/weighting/fit_analysis.R

Other survey analysis: calc_survey_ci(), calc_weight_fit()

Examples

## Not run:
seed_incidence_table <- data.table(hh_id_dow = 1:3, p_var1 = c(1,2,3), h_var2 = c(4,5,6))
target_table <- data.table(hh_id_dow = 1:3, p_var1 = c(1,2,3), h_var2 = c(4,5,6))
weights <- data.table(hh_id_dow = 1:3, final_weight = c(1,1,1))
calc_max_error(seed_incidence_table, target_table, weights)
#> Error in weighted_sums - target_vec: non-conformable arrays
## End(Not run)