[英]Weibull cumulative distribution function starting from “fitdistr” command
我已經使用R MASS軟件包中的fitdistr
函數來調整Weibull 2參數的概率密度函數(pdf)。
這是我的代碼:
require(MASS)
h = c(31.194, 31.424, 31.253, 25.349, 24.535, 25.562, 29.486, 25.680, 26.079, 30.556, 30.552, 30.412, 29.344, 26.072, 28.777, 30.204, 29.677, 29.853, 29.718, 27.860, 28.919, 30.226, 25.937, 30.594, 30.614, 29.106, 15.208, 30.993, 32.075, 31.097, 32.073, 29.600, 29.031, 31.033, 30.412, 30.839, 31.121, 24.802, 29.181, 30.136, 25.464, 28.302, 26.018, 26.263, 25.603, 30.857, 25.693, 31.504, 30.378, 31.403, 28.684, 30.655, 5.933, 31.099, 29.417, 29.444, 19.785, 29.416, 5.682, 28.707, 28.450, 28.961, 26.694, 26.625, 30.568, 28.910, 25.170, 25.816, 25.820)
weib = fitdistr(na.omit(h),densfun=dweibull,start=list(scale=1,shape=5))
hist(h, prob=TRUE, main = "", xlab = "x", ylab = "y", xlim = c(0,40), breaks = seq(0,40,5))
curve(dweibull(x, scale=weib$estimate[1], shape=weib$estimate[2]),from=0, to=40, add=TRUE)
現在,我想創建Weibull累積分布函數(cdf)並將其繪制為圖形:
,其中x> 0,b =比例尺,a =形狀
我嘗試使用上面的公式為h
應用比例和形狀參數,但事實並非如此。
這是累積密度函數的刺傷。 您只需要記住要對采樣點的間距進行調整(注意:它適用於均勻間距小於或等於1的采樣點):
cdweibull <- function(x, shape, scale, log = FALSE){
dd <- dweibull(x, shape= shape, scale = scale, log = log)
dd <- cumsum(dd) * c(0, diff(x))
return(dd)
}
盡管上面討論了比例差異,但您可以像dweibull
一樣將其繪制在圖形上:
require(MASS)
h = c(31.194, 31.424, 31.253, 25.349, 24.535, 25.562, 29.486, 25.680,
26.079, 30.556, 30.552, 30.412, 29.344, 26.072, 28.777, 30.204,
29.677, 29.853, 29.718, 27.860, 28.919, 30.226, 25.937, 30.594,
30.614, 29.106, 15.208, 30.993, 32.075, 31.097, 32.073, 29.600,
29.031, 31.033, 30.412, 30.839, 31.121, 24.802, 29.181, 30.136,
25.464, 28.302, 26.018, 26.263, 25.603, 30.857, 25.693, 31.504,
30.378, 31.403, 28.684, 30.655, 5.933, 31.099, 29.417, 29.444,
19.785, 29.416, 5.682, 28.707, 28.450, 28.961, 26.694, 26.625,
30.568, 28.910, 25.170, 25.816, 25.820)
weib = fitdistr(na.omit(h),densfun=dweibull,start=list(scale=1,shape=5))
hist(h, prob=TRUE, main = "", xlab = "x",
ylab = "y", xlim = c(0,40), breaks = seq(0,40,5), ylim = c(0,1))
curve(cdweibull(x, scale=weib$estimate[1], shape=weib$estimate[2]),
from=0, to=40, add=TRUE)
這適用於我的數據,但您的可能有所不同。 它使用FAdist
軟件包中的rweibull3
函數。
>h=rweibull3(1000,2,2,2)
>#this gives some warnings...that I ignore.
>weib = fitdistr(h,densfun=dweibull3,start=list(scale=1,shape=5,thres=0.5))
There were 19 warnings (use warnings() to see them)
要注意的是,起始值影響擬合進行的方式。 因此,如果起始值接近真實值,則將收到較少的警告。
>curve(dweibull3( x,
scale=weib$estimate[1],
shape=weib$estimate[2],
thres=weib$estimate[3]),
add=TRUE)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.