Skip to contents

Delegates to survey::postStratify() when given a design; otherwise computes raw post-stratification factors in base R.

Usage

morie_survey_poststratify(df, strata_col, population_counts)

Arguments

df

A data.frame holding the (unit-level) sample data plus any weight/strata/cluster/domain columns referenced by name.

strata_col

Character; column name of the stratum identifier in df.

population_counts

Named numeric vector of population counts by stratum (post-stratification target).

Value

A numeric vector of post-stratification weights.

Examples

set.seed(1)
df <- data.frame(g = rep(c("a", "b"), 15))
str(morie_survey_poststratify(df, "g", c(a = 60, b = 40)), max.level = 1)
#>  num [1:30] 1.2 0.8 1.2 0.8 1.2 0.8 1.2 0.8 1.2 0.8 ...