使用 plotrix 绘制二项式置信区间
Plot binomial confidence intervals with plotrix
我需要在我的图中添加二项式置信区间。
这是我的步骤:
library(binom)
library(plotrix)
x <- c(1:6)
y <- c(68, 69, 70, 75, 75, 87)
CI <- binom.confint(y, 265, conf.level = 0.95, methods = "exact")
plot(x, y)
plotCI(x, y, ui = CI$upper, li = CI$lower, add = TRUE)
我认为我做的一切都是正确的,但我的输出图似乎不正确:
你有什么建议吗?
您是否考虑过使用 ggplot2 的选项?
geom_smooth
为您提供线性模型 ("lm") 预测的 95% 置信区间。
data<-data.frame(y=c(20.7, 18, 21.4, 15.3, 27.3, 20),x=c(1:6))
library(ggplot2)
g<-ggplot(data,aes(x,y))
g+geom_point()+geom_smooth(method="lm")
输出将是:
binom.confint
returns 比例 的置信区间,而不是总数(如果您检查了 CI
对象打印它,你可能已经注意到了这一点)。尝试
plotCI(x,y,ui=CI$upper*CI$n,li=CI$lower*CI$n)
(这结合了您的两个绘图语句以同时绘制点和误差线。)
或者,您可以绘制比例及其置信区间:
plotCI(x,y/CI$n,ui=CI$upper,li=CI$lower)
我需要在我的图中添加二项式置信区间。
这是我的步骤:
library(binom)
library(plotrix)
x <- c(1:6)
y <- c(68, 69, 70, 75, 75, 87)
CI <- binom.confint(y, 265, conf.level = 0.95, methods = "exact")
plot(x, y)
plotCI(x, y, ui = CI$upper, li = CI$lower, add = TRUE)
我认为我做的一切都是正确的,但我的输出图似乎不正确:
你有什么建议吗?
您是否考虑过使用 ggplot2 的选项?
geom_smooth
为您提供线性模型 ("lm") 预测的 95% 置信区间。
data<-data.frame(y=c(20.7, 18, 21.4, 15.3, 27.3, 20),x=c(1:6))
library(ggplot2)
g<-ggplot(data,aes(x,y))
g+geom_point()+geom_smooth(method="lm")
输出将是:
binom.confint
returns 比例 的置信区间,而不是总数(如果您检查了 CI
对象打印它,你可能已经注意到了这一点)。尝试
plotCI(x,y,ui=CI$upper*CI$n,li=CI$lower*CI$n)
(这结合了您的两个绘图语句以同时绘制点和误差线。)
或者,您可以绘制比例及其置信区间:
plotCI(x,y/CI$n,ui=CI$upper,li=CI$lower)