我试图了解如何使用survey
R 中的包组合多个设计。例如,要构建测量权重,我需要进行分层、校准、修剪权重和重新校准。
我尝试按以下顺序堆叠设计术语:
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)
(我将后分层作为一个单独的步骤的主要原因是因为有 13 个后层。有些后层很小,所以我担心将后分层变量折叠成 raking 会导致收敛问题。)
我真的很想知道这是否是正确的方法以及是否有更简洁的方法。谢谢!