Adjusts survey weights so that the weighted marginal totals match known population values. Supports linear (GREG) and logit calibration methods for categorical auxiliary variables.
Arguments
- data
A
data.frame,weighted_df,survey_taylor, orsurvey_nonprob.survey_replicate→ error. Any other class → error.- variables
<
tidy-select> Columns to calibrate on. Must be categorical (character or factor). Specify as a bare name orc(var1, var2, ...).- population
Named list of population targets. Names must match the column names selected by
variables. Each element: a named numeric vectorc(level = target, ...).For
type = "prop": values must sum to 1.0 (within1e-6tolerance). Fortype = "count": values must be strictly positive.- weights
<
tidy-select> Weight column name (bare name).NULL→ auto-detected fromweighted_dfattribute or survey object@variables$weights. For plaindata.framewithweights = NULL, uniform starting weights are used and the output column is named bywt_name(default"wts").- wt_name
Character scalar. Name of the output weight column in the returned
weighted_df. Default"wts". Ignored whendatais a survey object (survey_taylororsurvey_nonprob).- method
Character scalar.
"linear"(default): one-step exact GREG calibration (may produce negative weights)."logit": bounded iterative calibration (always positive).- type
Character scalar.
"prop"(default):populationvalues are proportions."count":populationvalues are counts.- control
Named list of convergence parameters. Merged with defaults
list(maxit = 50, epsilon = 1e-7)— omitted keys retain their defaults.
Value
data.frameorweighted_dfinput →weighted_dfsurvey_taylororsurvey_nonprobinput → same class as input (survey_taylororsurvey_nonprob; class is preserved)
The weight column in the output contains calibrated weights. A history
entry with operation = "calibration" is appended to
weighting_history.
See also
Other calibration:
poststratify(),
rake()
Examples
df <- data.frame(
age_group = c("18-34", "35-54", "55+", "18-34", "35-54"),
sex = c("M", "F", "M", "F", "M"),
stringsAsFactors = FALSE
)
pop <- list(
age_group = c("18-34" = 0.30, "35-54" = 0.40, "55+" = 0.30),
sex = c("M" = 0.48, "F" = 0.52)
)
result <- calibrate(df, variables = c(age_group, sex), population = pop)
