svyby比例的置信区间

may*_*bra 10 r survey

是否存在从svyby对象为比例创建置信区间的现有函数(在我的示例中为survey包中的二进制项的交叉表).我经常比较各组的比例,并且拥有一个可以提取置信区间的函数(使用调查函数svyciprop而不是confint)是非常方便的.下面的例子显示了我想要实现的目标.

加载数据

library(survey)
library(weights)
data(api)
apiclus1$both<-dummify(apiclus1$both)[,1]#Create dummy variable
dclus1<-svydesign(id=~dnum, weights=~pw, data=apiclus1, fpc=~fpc)
Run Code Online (Sandbox Code Playgroud)

创建一个svyby对象,比较stype中变量"both"的比例

b<-svyby(~both, ~stype, dclus1, svymean)
confint(b)#This works, but svyciprop is best in  other cases, especially when proportion is close to 0 or 1
svyciprop(b)#This requires that you specify each level and a design object
Run Code Online (Sandbox Code Playgroud)

是否有可能创建一个函数(例如byCI(b,method="likelihood"),它实现与confint(b)使用相同svyciprop?它基本上必须遍历svyby对象的每个级别并创建置信区间.到目前为止,我的尝试都没有成功.

可能有另一种方法,但我喜欢使用,svyby()因为它快速和直观.

小智 9

svyby()有一个vartype=参数来指定您希望如何指定采样不确定度.使用vartype="ci"得到的置信区间,如

svyby(~I(ell>0),~stype,design=dclus1, svyciprop,vartype="ci",method="beta")
Run Code Online (Sandbox Code Playgroud)

很容易检查这与手动执行每个级别相同,例如,

confint(svyciprop(~I(ell>0), design=subset(dclus1,stype=="E"),method="beta"))
Run Code Online (Sandbox Code Playgroud)