svyciprop 的 'ci' 和 value 有不同的形式。
> str( svyciprop(~I(stype %in% "E"), dclus1, method="lo", df=degf(dclus1)) )
Class 'svyciprop' atomic [1:1] 0.787
..- attr(*, "var")= num [1, 1] 0.00215
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : chr "as.numeric(I(stype %in% \"E\"))"
.. .. ..$ : chr "as.numeric(I(stype %in% \"E\"))"
..- attr(*, "ci")= Named num [1:2] 0.671 0.87
.. ..- attr(*, "names")= chr [1:2] "2.5%" "97.5%"
要以紧凑的形式提供它们,需要从属性中提取“ci”向量并将其附加到级别值。还需要制定一个公式以允许在svyciprop 的第一个参数之外进行替换,这不会进行就地替换。
library(survey) # using the `dclus1` object that is standard in the examples.
sapply( levels(dclus1$variables$stype),
function(x){
form <- as.formula( substitute( ~I(stype %in% x), list(x=x)))
z <- svyciprop(form, dclus1, method="lo", df=degf(dclus1))
c( z, c(attr(z,"ci")) )} )
E H M
I(stype %in% "E") 0.7868852 0.07650273 0.1366120
2.5% 0.6712011 0.03540883 0.0844893
97.5% 0.8697648 0.15750112 0.2133950
编辑:感谢 Anthony 的认可,因为他对这个软件包的经验比我丰富得多。“me”方法赋予 CI 的值略有不同:
sapply( levels(dclus1$variables$stype), function(x){
form <- as.formula( substitute( ~I(stype %in% x), list(x=x)))
z <- svyciprop(form, dclus1, method="me", df=degf(dclus1))
c( z, c(attr(z,"ci")) )} )
E H M
I(stype %in% "E") 0.7868852 0.07650273 0.13661202
2.5% 0.6875032 0.01900053 0.07302114
97.5% 0.8862673 0.13400493 0.20020290