Skip to contents

Computes the post-stratification factors natively in base R: each unit in stratum \(h\) gets \((N_h / N) / (n_h / n)\), the ratio of the population share to the sample share (the adjustment survey::postStratify() applies to equal starting weights). No package is called.

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 ...