我想使用 R 中的“矩估计方法”(MME)来拟合 weibull 参数。我知道我们可以使用MASS
包中的fitdisr()
函数来估计这些值,但是我想知道是否有函数或包用 MME 来计算参数。例如,我想用蒙特卡洛方法来近似 MME。当我从均匀分布中生成 1000 值时,我可以修复 0,我为这个问题编写的函数
这是使用 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
# bootst
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))))
本站系公益性非盈利分享网址,本文来自用户投稿,不代表边看边学立场,如若转载,请注明出处
评论列表(80条)