plotrix:如何在没有y值的情况下绘制CI。 y值超出置信区间

时间:2013-05-03 17:50:21

标签: r

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

我试过:plotCI(x, y=NULL, ui=U, li=L)所有都是数字向量;并且它不起作用

现在,如果对于一个条目y=2U=4L=3,则间隔将一直降至2(而不是3=L。 1}})

我需要的是y(其中y可能低于或高于垂直置信区间)

感谢您的帮助。

2 个答案:

答案 0 :(得分: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

答案 1 :(得分: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()