Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R-自举置信区间-获取上下界参数_R_Ggplot2_Confidence Interval_Statistics Bootstrap_Probability Density - Fatal编程技术网

R-自举置信区间-获取上下界参数

R-自举置信区间-获取上下界参数,r,ggplot2,confidence-interval,statistics-bootstrap,probability-density,R,Ggplot2,Confidence Interval,Statistics Bootstrap,Probability Density,我使用自举法获得威布尔分布的置信区间。然后我在一个图中绘制了置信带 代码如下: 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=TRU

我使用自举法获得威布尔分布的置信区间。然后我在一个图中绘制了置信带

代码如下:

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)
  • 我想用R的ggplot包绘制相同的图表。关于如何使用ggplot语法实现这一点,有什么想法吗

  • 我对第一个问题没有把握

    下面是问题2的一些代码

    library (fitdistrplus) #you forgot to mention this
    library (ggplot2)
    library (tidyr)
    
    dat <- gather(as.data.frame(boot.pdf), i, y, -1)
    dat2 <- gather(as.data.frame(t(quants)), quantile, y)
    dat$x <- dat2$x <- xs
    
    ggplot(dat, aes(x, y, group = i)) +
      geom_line(col = 'grey') +
      geom_line(data = dat2, aes(group = quantile, col = quantile), size = 1) +
      scale_color_manual(values  = c('2.5%' = 'red', '50%' = 'darkred', '97.5%' = 'red')) +
      theme_bw() + xlab("Note Life (months)") + ylab("Probability density") + 
      ggtitle("Probability Distribution")
    
    library(FitDistripPlus)#你忘了提到这一点
    图书馆(GG2)
    图书馆(tidyr)
    
    谢谢阿克斯曼。对于问题1,我真的试图找到2.5%和97.5%曲线的Weibull形状和比例参数值。例如,原始模型的形状=1.781096,比例=33.669511。是的,我理解,但我不确定如何做到这一点。您可以查看
    MASS
    包中的
    fitdistr
    函数。或者查看此处:
    fits
    
    library (fitdistrplus) #you forgot to mention this
    library (ggplot2)
    library (tidyr)
    
    dat <- gather(as.data.frame(boot.pdf), i, y, -1)
    dat2 <- gather(as.data.frame(t(quants)), quantile, y)
    dat$x <- dat2$x <- xs
    
    ggplot(dat, aes(x, y, group = i)) +
      geom_line(col = 'grey') +
      geom_line(data = dat2, aes(group = quantile, col = quantile), size = 1) +
      scale_color_manual(values  = c('2.5%' = 'red', '50%' = 'darkred', '97.5%' = 'red')) +
      theme_bw() + xlab("Note Life (months)") + ylab("Probability density") + 
      ggtitle("Probability Distribution")