从"fitdistr"开始的Weibull累积分布函数如图2所示.命令 [英] Weibull cumulative distribution function starting from "fitdistr" command

查看:213
本文介绍了从"fitdistr"开始的Weibull累积分布函数如图2所示.命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了R MASS软件包中的fitdistr函数来调整Weibull 2参数的概率密度函数(pdf).

I've used fitdistr function from R MASS package to adjust a Weibull 2 parameters probability density function (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)并将其绘制为图形:

Now, I would like to create the Weibull cumulative distribution function (cdf) and plot it as a graph:

,其中x> 0,b =比例尺,a =形状

, where x > 0, b = scale , a = shape

我尝试使用上述公式为 h 应用比例尺和形状参数,但事实并非如此.

I tried to apply scale and shape parameters for h using the formula above, but it was not this way.

推荐答案

在这里有一个累积密度函数的刺伤.您只需要记住要对采样点的间距进行调整(注意:它适用于均匀间距小于或等于1的采样点):

Here's a stab at a cumulative density function. You just have to remember to include an adjustment for the spacing of the sampling points (note: it works for sampling points with uniform spacing less than or equal to 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一样将其绘制在图形上:

The discussion above about scale differences notwithstanding, you can plot it over your graph the same as 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)

这篇关于从"fitdistr"开始的Weibull累积分布函数如图2所示.命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆