正确,因此您正试图在不知道如何处理该类的函数(barNest)中使用对象类(svyby),因为调查包和plotrix包不能很好地一起玩。幸运的是svyby对象dotchart方法是不是太多的代码,所以你可能只是想修改它..
# run your code above, then review the dotchart method for svyby objects:
getS3method('dotchart' , 'svyby')
..和从,你可以学习它真的不是远远超出调用原dotchart功能(也就是说,在将b
对象中包含的数据转换为矩阵后,不使用svyby对象,只是统计数据的常规集合)。现在你所要做的就是增加一个置信区间线。
置信区间宽度很容易通过运行
confint(b)
获得的(更容易比使用SE(b)
)可以提取这些统计数据,以建立自己的barNest
或plotCI
电话?
如果在点图上放置置信区间很重要,主要障碍是正确地打y坐标。在点图默认方法中挖掘..
getS3method('dotchart' , 'default')
..你可以看到y坐标是如何计算的。削减到只有基本的内容,我想你可以使用这个:
# calculate the distinct groups within the `svyby` object
groups <- as.numeric(as.factor(attr(b , 'row.names')))
# calculate the distinct statistics within the `svyby` object
nstats <- attr(b , 'svyby')$nstats
# calculate the total number of confidence intervals you need to add
n <- length(groups) * nstats
# calculate the offset sizes
offset <- cumsum(c(0, diff(groups) != 0))
# find the exact y coordinates for each dot in the dotchart
# and leave two spaces between each group
y <- 1L:n + sort(rep(2 * offset , nstats))
# find the confidence interval positions
ci.pos <-
rep(groups , each = nstats) +
c(0 , length(groups))
# extract the confidence intervals
x <- confint(b)[ ci.pos , ]
# add the y coordinates to a new line data object
ld <- data.frame(x)
# loop through each dot in the dotchart..
for (i in seq_len(nrow(ld))){
# add the CI lines to the current plot
lines(ld[ i , 1:2 ] , rep(y[i] , 2))
}
但是这显然笨重,因为置信区间被允许去的方式在屏幕上。忽略了svyby
类,甚至整个survey
包一秒钟,找到我们实现dotchart
很好地格式置信区间,我们可能会帮助你更多。我不认为survey
包是你问题的根源:)
报告错误时,预计会提供足够的详细信息。代码在我的机器上运行良好。使用R 2.15.2,plotrix_3.4-5,survey_3.29,据我所知可以是所有当前版本。你甚至没有描述过什么“不工作”对你意味着什么。 –