威布尔分布的矩估计

时间:2013-11-11 14:21:40

标签: r

我想在R中使用“矩量估计法”(MME)拟合weibull参数。我知道我们可以在fitdisr()包中用MASS函数估计这些值,但我想知道如果有功能或包用MME计算参数。 例如,我想用蒙特卡罗方法近似MME。当我从均匀分布生成1000值时,我为此问题编写的函数(用于估计积分),给出0值。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:3)

这是使用MME查找Weibull分布参数的一种方法。

# load packages
require(rootSolve)
# generate data
N <- 1000
shape <- 2
scale <- 6
X <- rweibull(n=N, shape=shape, scale=scale)
# range of plausible shapes (for solver)
min_shape <- 0.1
max_shape <- 100 
# bootstraping
Nboot <- 1000
sim <- replicate(Nboot, {
  Xboot <- sample(X, replace=TRUE)
  # find shape
  rt <- 1+(sd(Xboot)/mean(Xboot))^2
  rootFct <- function(k) {
    gamma(1+2/k)/gamma(1+1/k)^2 - rt
  }
  shape_est <- uniroot.all(rootFct, c(min_shape, max_shape))
  if (length(shape_est)!=1) stop("The shape may be outside min_shape and max_shape")
  scale_est <- mean(Xboot)/gamma(1+1/shape_est)
  c(shape=shape_est, scale=scale_est)
})
apply(sim, 1, function(x)
  c(est=mean(x), se=sd(x), quantile(x, c(.025, .5, .975))))