svyby 比例的置信区间 [英] confidence intervals of svyby proportion

查看:49
本文介绍了svyby 比例的置信区间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is there an existing function that creates confidence intervals from a svyby object for proportions (in my case a crosstab for a binary item in the survey package). I often compare proportions across groups, and it would be very handy to have a function that can extract confidence intervals (with the survey function svyciprop rather than confint). The example below shows what I'd like to achieve.

加载数据

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)

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

Create a svyby object which compares proportion of variable "both" across stype

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

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

Would it be possible to create a function (e.g. byCI(b,method="likelihood") which achieves the same as confint(b) but using svyciprop? It would basically have to go through each level of the svyby object and create a confidence interval. My attempts have been unsuccessful up to now.

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

There may be another way around this, but I like using svyby() as it's quick and intuitive.

推荐答案

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

svyby() has a vartype= argument to specify how you want the sampling uncertainty specified. Use vartype="ci" to get confidence intervals, eg

svyby(~I(ell>0),~stype,design=dclus1, svyciprop,vartype="ci",method="beta")

很容易检查这是否与手动完成每个级别相同,例如,

It's easy to check that this gives the same as doing each level by hand, eg,

confint(svyciprop(~I(ell>0), design=subset(dclus1,stype=="E"),method="beta"))

这篇关于svyby 比例的置信区间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆