rake_weight: Estimate rake weights for input survey data & population...

Description Usage Arguments Examples

View source: R/weight.R

Description

This is a thin wrapper for anesrake. If return_stats = TRUE, it returns a list with (1) a survey dataset and (2) the anesrake() object. Otherwise, it prints a summary and returns just the survey dataset with a weight variable appended.

Usage

1
2
3
4
5
6
7
8
9
rake_weight(
  svy,
  pop,
  idvar,
  weightvar = "weight",
  return_stats = TRUE,
  print_name = "",
  ...
)

Arguments

svy

a survey data frame

pop

a list that holds population distributions for the weighting variables.

idvar

name of varible that holds unique id

weightvar

name of output weight variable

return_stats

If TRUE, the function will instead return a list with 2 elements: (1) the survey data frame with a new weight variable, and (2) the object returned directly by anesrake(). This is helpful if you want to later pull elements such as design effect for confidence interval calculations.

print_name

header to print in summary (useful for log output)

...

other arguments passed to anesrake()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
data(svy, pop)
svy <- svy$person

# determine target weight values
# the population is determined by a survey dataset which is itself weighted
wtvars <- c("age_weight", "income_weight", "race_weight")
pop_target <- sapply(wtvars, function(x) weights::wpct(pop[[x]], pop$stwt))

# compare distributions for survey and population
pop_target
sapply(wtvars, function(x) weights::wpct(svy[[x]]))

# run weighting
svy_wts <- rake_weight(svy, pop_target, "Vrid")
svy <- svy_wts$svy
sapply(wtvars, function(x) weights::wpct(svy[[x]], svy$weight))
summary(svy_wts$wts)

southwick-associates/sastats documentation built on March 27, 2020, 9:39 p.m.