Reputation: 160
I have created weighted data with my survey using the anesrake
and weights
package. However, I am not sure how to use the weights afterwards, beside wpct
function in the package. How can I compute say descriptive stats and integrate the weighted data with other functions/packages?
Reproducible data from the anesrake
package:
data("anes04")
anes04$caseid <- 1:length(anes04$age)
anes04$agecats <- cut(anes04$age, c(0, 25,35,45,55,65,99))
levels(anes04$agecats) <- c("age1824", "age2534", "age3544",
"age4554", "age5564", "age6599")
marriedtarget <- c(.4, .6)
agetarg <- c(.10, .15, .17, .23, .22, .13)
names(agetarg) <- c("age1824", "age2534", "age3544",
"age4554", "age5564", "age6599")
targets <- list(marriedtarget, agetarg)
names(targets) <- c("married", "agecats")
outsave <- anesrake(targets, anes04, caseid=anes04$caseid,
verbose=TRUE)
caseweights <- data.frame(cases=outsave$caseid, weights=outsave$weightvec)
This will give me a new vector with weights for the dataframe. So, my question is, how can I analyze the data know? How can I incorporate these weights with summary statistics?
Upvotes: 0
Views: 573
Reputation: 2765
You could supply the weights as the weights=
argument to survey::svydesign
. Ideally, you'd do the raking in the survey package so that you could take account of the variance reductions from raking, but it's pretty standard (at least in public-use data) to analyse raked weights as if they were just sampling weights.
Or, if the raking specification you ended up with was simple enough to reproduce in survey::rake
or survey::calibrate
, you could redo the raking in the survey package.
The reason for using the survey package is the very wide range of other analyses it allows (and even more with svyVGAM
).
Upvotes: 1