Stacking multiple design terms using survey package in R

184 views Asked by At

I am trying to understand how to combine several designs using the survey package in R. For example, to construct survey weights, I need to post-stratify, calibrate, trim weights, and re-calibrate.

I have tried to stack the design terms in the following sequences:

n<- nrow(my_data)
d<- rep(N/n, n)
f<- rep(n/N, n)

#specifying SRS survey design
srs.design<- svydesign(ids= ~0, strata= NULL,
                       data= my_data, 
                       weight= ~d, fpc= ~f)

#specifying post-stratification survey design
ps.design<- postStratify(design= srs.design,
                         strata= ~postsurvey_strata, 
                         population= N.ps) #where N.ps is the poststrata population distribution


#specifying raking survey design
rake.design<- calibrate(design= ps.design, 
                        formula= ~as.factor(gender_age)+ 
                          as.factor(education)+
                          as.factor(race)+
                          as.factor(income),
                        calfun= "raking", 
                        population= pop.P_sam) #where pop.P_sam is the demographic distributions in the population

#specifying trimming survey design 
trim.design<- trimWeights(design= rake.design, lower= 0.2, upper= 6)

#specifying re-calibration
rerake.design<- calibrate(design= trim.design, 
                          formula= ~as.factor(gender_age)+ 
                            as.factor(education)+
                            as.factor(race)+
                            as.factor(income),
                          calfun= "raking", 
                          population= pop.P_sam)


(The main reason why I have post-stratification as a separate step is because there are 13 post-strata. Some of the post-strata are quite small, so I am concerned that folding the post-stratification variable into raking would lead to convergence problem.)

I would really like to know whether this is the right approach and whether there are more succinct ways. Thanks!

0

There are 0 answers