首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >3参数威布尔分布的拟合

3参数威布尔分布的拟合
EN

Stack Overflow用户
提问于 2012-08-06 00:01:57
回答 2查看 15.3K关注 0票数 9

我已经在R中做了一些数据分析,我正在试图弄清楚如何将我的数据拟合到3参数威布尔分布。我发现了如何使用2个参数的威布尔来做到这一点,但在找到如何使用3参数来做到这一点上却做得不够。

下面是我如何使用MASS包中的fitdistr函数拟合数据:

代码语言:javascript
复制
y <- fitdistr(x[[6]], 'weibull')

x[[6]]是我的数据子集,y是我存储拟合结果的位置。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-08-06 00:20:32

首先,您可能想看看FAdist package。然而,从rweibull3rweibull并不是很难

代码语言:javascript
复制
> rweibull3
function (n, shape, scale = 1, thres = 0) 
thres + rweibull(n, shape, scale)
<environment: namespace:FAdist>

类似地,从dweibull3dweibull

代码语言:javascript
复制
> dweibull3
function (x, shape, scale = 1, thres = 0, log = FALSE) 
dweibull(x - thres, shape, scale, log)
<environment: namespace:FAdist>

所以我们有这个

代码语言:javascript
复制
> x <- rweibull3(200, shape = 3, scale = 1, thres = 100)
> fitdistr(x, function(x, shape, scale, thres) 
       dweibull(x-thres, shape, scale), list(shape = 0.1, scale = 1, thres = 0))
      shape          scale          thres    
    2.42498383     0.85074556   100.12372297 
 (  0.26380861) (  0.07235804) (  0.06020083)

编辑:正如评论中提到的,当尝试以这种方式适应分布时,会出现各种警告

代码语言:javascript
复制
Error in optim(x = c(60.7075705026659, 60.6300379017397, 60.7669410153573,  : 
  non-finite finite-difference value [3]
There were 20 warnings (use warnings() to see them)
Error in optim(x = c(60.7075705026659, 60.6300379017397, 60.7669410153573,  : 
  L-BFGS-B needs finite values of 'fn'
In dweibull(x, shape, scale, log) : NaNs produced

对我来说,一开始它只是NaNs produced,这并不是我第一次看到它,所以我认为它没有太大的意义,因为估计是好的。经过一番搜索,这似乎是一个相当普遍的问题,我既找不到原因,也找不到解决方案。一种替代方案是使用stats4包和mle()函数,但它似乎也存在一些问题。但我可以让你使用danielmedic的code的一个修改版本,我已经检查过几次了:

代码语言:javascript
复制
thres <- 60
x <- rweibull(200, 3, 1) + thres

EPS = sqrt(.Machine$double.eps) # "epsilon" for very small numbers

llik.weibull <- function(shape, scale, thres, x)
{ 
  sum(dweibull(x - thres, shape, scale, log=T))
}

thetahat.weibull <- function(x)
{ 
  if(any(x <= 0)) stop("x values must be positive")

  toptim <- function(theta) -llik.weibull(theta[1], theta[2], theta[3], x)

  mu = mean(log(x))
  sigma2 = var(log(x))
  shape.guess = 1.2 / sqrt(sigma2)
  scale.guess = exp(mu + (0.572 / shape.guess))
  thres.guess = 1

  res = nlminb(c(shape.guess, scale.guess, thres.guess), toptim, lower=EPS)

  c(shape=res$par[1], scale=res$par[2], thres=res$par[3])
}

thetahat.weibull(x)
    shape     scale     thres 
 3.325556  1.021171 59.975470 
票数 8
EN

Stack Overflow用户

发布于 2018-09-26 01:57:51

另一种选择:包"lmom“。用L-矩技术进行估计

代码语言:javascript
复制
library(lmom)
thres <- 60
x <- rweibull(200, 3, 1) + thres
moments = samlmu(x, sort.data = TRUE)
log.moments <- samlmu( log(x), sort.data = TRUE )
weibull_3parml <- pelwei(moments)
weibull_3parml
zeta      beta     delta 
59.993075  1.015128  3.246453  

但我不知道如何在这个软件包或上面的解决方案中进行一些拟合优度统计。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11817883

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档