I used bootstrapping to obtain confidence intervals of a Weibull distribution. Then I plotted the Confidence Bands in a plot.
Code is below:
set.seed(123)
rw.small<-rweibull(100,shape=1.781096,scale=33.669511)
xs <- seq(0,100, len=500)
boot.pdf <- sapply(1:100, function(i) {
xi <- sample(rw.small, size=length(rw.small), replace=TRUE)
MLE.est <- suppressWarnings(fitdist(xi, distr="weibull",lower=0))
dweibull(xs, shape=MLE.est$estimate["shape"], scale = MLE.est$estimate["scale"])
})
par(bg="white",las=1,cex=1.2)
plot(xs, boot.pdf[, 1], type="l", col=rgb(.6, .6, .6, .1), ylim=range(boot.pdf),
xlab="Note Life (months)", ylab="Probability density",main= "Probability Distribution")
for(i in 2:ncol(boot.pdf)) lines(xs, boot.pdf[, i], col=rgb(.6, .6, .6, .1))
quants <- apply(boot.pdf, 1, quantile, c(0.025, 0.5, 0.975))
min.point <- apply(boot.pdf, 1, min, na.rm=TRUE)
max.point <- apply(boot.pdf, 1, max, na.rm=TRUE)
lines(xs, quants[1, ], col="red", lwd=1.5, lty=2)
lines(xs, quants[3, ], col="red", lwd=1.5, lty=2)
lines(xs, quants[2, ], col="darkred", lwd=2)
Two questions: 1. How do i obtain the Shape and Scale Parameter values from the lower and upper bounds of the confidence interval plotted (i.e. the two red lines)?
lines(xs, quants[1, ], col="red", lwd=1.5, lty=2)
lines(xs, quants[3, ], col="red", lwd=1.5, lty=2)
- I would like to plot the same chart with R's ggplot package. Any ideas as to how i might do this with ggplot syntax?