使用ciplot画上n个置信区间,其中confint是一个2*n的矩阵,第一行是置信区间的下界,第二行是置信区间的上界。
以下是代码,当时总是出现:
错误于int_abline(a = a, b = b, h = h, v = v, untf = untf, ...) :
找不到对象'true'
并且图像出来是一片空白……求问这个程序哪个地方错了~~~~
谢谢大家了!
ciplot <- function(confint, true)
{
n <- length(confint[1,]) # find number of confidence intervals
x <- matrix(c(1:n,1:n),nrow=n,ncol=2)
y <- c(t(x)) # produces vector with y[2i-1] = y[2i] = i
z <- c(confint) # vector with z[2i-1] lower bound, z[2i] upper bound of ith ci
plot(z, y, type="n", ylab="Sample number") # plot end points of ci
abline(v=true) # draw vertical line at true value of parameter
for (i in 1:n)
{
a <- 2*i-1
b <- 2*i
if (z[a] <= true & z[b] >= true) # interval contains true value of parameter
{
lines(z[a:b],y[a:b],col=2) # join endpoints of ci with red line
}
else
{
lines(z[a:b],y[a:b],col=4) # join endpoints of ci with blue line
}}}