在R中的图表上找到一个点

时间:2016-11-14 01:31:33

标签: r weibull

我有一个概率图,其中逐点置信区间符合数据。使用图表我想从置信带计算或定位0.001分位数。我使用函数locator ()来查找点的位置。是否有任何其他方法可用于在图表上给出y值的情况下找到x值?

我使用的代码如下。

times <- c (17.88, 28.92, 33.00, 41.52, 42.12, 45.60, 48.40,
            51.84, 51.96, 54.12, 55.56, 67.80, 68.64, 68.64, 
            68.88, 84.12, 93.12, 98.64, 105.12, 105.84, 127.92,
            128.04,173.40)
N <- length (times)
t <- c (5, 10, 15)

rank.times <- rank (times) # Use average ranks for the tied observations
ecdf.times <- (rank.times - 0.5) / N
quant.ecdf <- log (-log (1 - ecdf.times))
weibull.ml <- suppressWarnings (fitdist (times, "weibull"))
weibull.cdf <- pweibull (times, shape = weibull.ml$estimate[1], 
                     scale = weibull.ml$estimate[2])
wei <- log (-log (1 - weibull.cdf))
wei.extra <- approxExtrap (log (times), wei, log (t), method = "linear")
quant.wei <- c (wei.extra$y, wei)
set.seed (123)
B <- 2000
wei.boot <- suppressWarnings (bootdist (weibull.ml, bootmethod = "param", niter = B))
boot.cdf.we <- matrix (NA, nrow = B, ncol = N)
for (i in 1:B){
boot.cdf.we[i, ] <- pweibull (times, shape = wei.boot$estim$shape[i],
                            scale = wei.boot$estim$scale[i])
}

p <- 0.025
upper.wei <- NULL
lower.wei <- NULL
for (i in 1:N) {
upper.wei[i] <- log (-log (1 - quantile (boot.cdf.we[,i], probs = p)))
lower.wei[i] <- log (-log (1 - quantile (boot.cdf.we[,i], probs = 1-p)))
}


extra.wei.l <- approxExtrap (log (times), lower.wei, log (t), method = "linear")
lower.weibull <- c (extra.wei.l$y, lower.wei)
extra.wei.u <- approxExtrap (log (times), upper.wei, log (t), method = "linear")
upper.weibull <- c (extra.wei.u$y, upper.wei)

times.ext <- c (t, times)
loc1 <- c (.001, .005, .02, .05, .1, .2, .4, .6, .8, .9, .95, .98, .995)
loc2 <- log (-log (1 - loc1))
loc3 <- c (5, 9.77, 20, 50, 100, 200)
plot (times, quant.ecdf, log = "x", axes = FALSE, xlab = "Millions of cycles", 
  ylab = "Proportion failing", pch = 16, type = "p", main = "Weibull - Complete", 
  xlim = c (5, 200), ylim = c (-6.95, 1.7))
  lines (times.ext, quant.wei)
  lines (times.ext, upper.weibull)
  lines (times.ext, lower.weibull)
  abline (h = loc2[1])
  segments (9.77789, -7.5, 9.77789, loc2[1])
  axis (1, at = loc3, labels = loc3)
  axis (2, at = loc2, labels = loc1, las = 2)

提前致谢!!

0 个答案:

没有答案