如何在复杂调查中获得正确的频率 table 加权和未加权?

How to get the right frequency table weighted and unweighted in complex survey?

我正在使用 survey package 来分析一项复杂的调查

我在使用这段代码时遇到的问题

tab_w<- svytable( ~edu+ smok , design= dsub)

结果显示整个人群的频率 table 而不仅仅是我调查的样本人群。

         smok
edu         1         2
       1   26466299  87948351
       2   20898455 102012829

这是我想要做的 table

----------------------------------------------
    |     Smok             |  Smok
    | Unweighted           | Weighted
    | Sample size          | population Size
    |   1     |  2         |  1     |  2         
----------------------------------------------
edu |-----------------------------------------                    
  1 |26466299| 87948351    |  200 | 204 
  2 |20898455|102012829    |  400 | 300
-----------------------------------------------

这包括整个人口,而不仅仅是我的样本人口。有没有办法在频率 table?

中仅包含样本总体

未加权样本table根本不需要调查包,只需使用tablextabs函数即可。

或者,如果您只有调查对象中方便使用的数据

with(model.frame(dsub), table(edu,smok))

作为可重现的例子

library(survey)
data(api)


with(apistrat, table(comp.imp, sch.wide))
#stratified sample
dstrat<-svydesign(id=~1,strata=~stype, weights=~pw, data=apistrat, fpc=~fpc)
svytable(~comp.imp+sch.wide, design=dstrat)
with(model.frame(dstrat), table(comp.imp, sch.wide))