[英]Plotting distribution of bootstrapped values in R
我需要以95%的置信區間擬合S形分布( y = 0~1
hc5
),並獲得y=5%
的x
值(稱為hc5
)。 原始輸入數據文件名為ZnOLC50.txt
:
LC50 Proportion
0.089 0.071428571
0.16 0.214285714
1.155 0.357142857
1.51 0.5
3.97 0.642857143
573.8 0.785714286
789 0.928571429
# Load data
>require(MASS)
>require(ggplot2)
>SSDZnOLC50<-read.delim("ZnOLC50.txt", header = TRUE)
>fitSSDZnOLC50<-fitdistr(SSDZnOLC50$LC50, 'lognormal')
# Extract hc5
>(hc5 <- qlnorm(0.05, meanlog = fitSSDZnOLC50$estimate[1], sdlog = fitSSDZnOLC50$estimate[2]))
[1] 0.01789181
>myboot <- function(fitSSDZnOLC50, p){
# resample from fitted distribution
>xr <- rlnorm(fitSSDZnOLC50$n, meanlog = fitSSDZnOLC50$estimate[1], sdlog = fitSSDZnOLC50$estimate[2])
# fit distribition to new data
>fitr <- fitdistr(xr, 'lognormal')
# return HCp
>hc5r <- qlnorm(p, meanlog = fitr$estimate[1], sdlog = fitr$estimate[2])
return(hc5r)
}
# Get 95% confidence interval
>set.seed(1234)
>hc5_boot <- replicate(1000, myboot(fitSSDZnOLC50, p = 0.05))
>quantile(hc5_boot, probs = c(0.025, 0.5, 0.975))
2.5% 50% 97.5%
0.0007278486 0.0370062459 1.4272168899
然后我想根據生成的矩陣hc5_boot
繪制hc5
分布。 首先,我嘗試了這個:
curve(dnorm(x,mean(hc5_boot),sd(hc5_boot)),xlim=c(-1,10),col="Red",lwd=1)
並得到如圖所示的曲線
然后我也嘗試了
> df <- as.data.frame(hc5_boot)
> ggplot(df, aes(x=hc5_boot)) + geom_density() + scale_x_continuous(limits=c(0,4))
並得到如圖所示的曲線
但是,根據觀察結果,這些曲線似乎都不符合0.0007278486
的2.5%
分位數,因為當x = 0
時密度值甚至不接近於x = 0
。
所以我想知道哪里出了問題以及我該怎么做。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.