我正在尝试使用矩方法将威布尔分布拟合到我在RStudio中的数据。我不知道需要什么样的命令和包才能适应像威布尔或帕累托这样的发行版。具体地说,我试图估计形状参数k和比例λ。
我使用以下代码生成我的数据:
a <- rweibull(100, 10, 1)发布于 2021-03-04 15:23:48
这是一个用矩量法估计威布尔分布参数的函数。
weibull_mom <- function(x, interval){
mom <- function(shape, x, xbar){
s2 <- var(x, na.rm = TRUE)
lgamma(1 + 2/shape) - 2*lgamma(1 + 1/shape) - log(xbar^2 + s2) + 2*log(xbar)
}
xbar <- mean(x, na.rm = TRUE)
shape <- uniroot(mom, interval = interval, x = x, xbar = xbar)$root
scale <- xbar/gamma(1 + 1/shape)
list(shape = shape, scale = scale)
}
set.seed(2021) # Make the results reproducible
a <- rweibull(100, 10, 1)
weibull_mom(a, interval = c(1, 1e6))
#$shape
#[1] 9.006623
#
#$scale
#[1] 0.9818155最大似然估计为
MASS::fitdistr(a, "weibull")
# shape scale
# 8.89326148 0.98265852
# (0.69944224) (0.01165359)
#Warning messages:
#1: In densfun(x, parm[1], parm[2], ...) : NaNs produced
#2: In densfun(x, parm[1], parm[2], ...) : NaNs producedhttps://stackoverflow.com/questions/66469202
复制相似问题