1

如何在没有 y 值的情况下绘制 CI。我只想绘制间隔。这是因为我的 y 值超出了置信区间。

我试过:plotCI(x, y=NULL, ui=U, li=L)哪里都是数字向量;它没有用

现在,如果对于一个条目,y=2U=4L=3,间隔将一直下降到2(而不是下降到3=L

我需要的是yy可能低于或高于垂直置信区间)

谢谢你的帮助。

4

2 回答 2

2

与其深入了解它的plotCI作用以及为什么它在缺少 y 值的情况下不起作用的细节,不如使用老式版本arrows()

x <- 1:10
L <- -(1:10)
U <- 1:10
ylim <- range(c(L,U))
plot(x,y=rep(NA,length(x)),type="n",ylim=ylim)
arrows(x,L,x,U,code=3,angle=90,length=0.1)

另见http://rwiki.sciviews.org/doku.php?id=tips:graphics-base:errbars

于 2013-05-03T18:38:51.277 回答
0

这是使用点图添加置信区间的示例:

http://www.r-bloggers.com/r-tutorial-add-confidence-intervals-to-dotchart-2/

示例代码:

### Create data frame with mean and std dev
x <- data.frame(mean=tapply(mtcars$mpg, list(mtcars$cyl), mean), sd=tapply(mtcars$mpg, list(mtcars$cyl), sd) )

###  Add lower and upper levels of confidence intervals
x$LL <- x$mean-2*x$sd
x$UL <- x$mean+2*x$sd

### plot dotchart with confidence intervals

title <- "MPG by Num. of Cylinders with 95% Confidence Intervals"

dotchart(x$mean, col="blue", xlim=c(floor(min(x$LL)/10)*10, ceiling(max(x$UL)/10)*10), main=title )

for (i in 1:nrow(x)){
    lines(x=c(x$LL[i],x$UL[i]), y=c(i,i))
}
grid()
于 2013-11-27T22:59:20.783 回答