尝试将 f 分布拟合到向量
Trying to fit f distribution to a vector
有谁知道为什么下面的代码执行失败fitdist
,错误"the function mle failed to estimate the parameters, with the error code 100"。
我过去在使用正态分布时遇到过这个错误;这种情况下的解决方案是增加向量的方差(通过将其乘以 100),但这对这种情况没有帮助。请注意向量中的所有元素都是正数。谢谢。
library(fitdistrplus)
VH <- c(0.36, 0.3, 0.36, 0.47, 0, 0.05, 0.4, 0, 0, 0.15, 0.89, 0.03, 0.45, 0.21, 0, 0.18, 0.04, 0.53, 0, 0.68, 0.06, 0.09, 0.58, 0.03, 0.23, 0.27, 0, 0.12, 0.12, 0, 0.32, 0.07, 0.04, 0.07, 0.39, 0, 0.25, 0.28, 0.42, 0.55, 0.04, 0.07, 0.18, 0.17, 0.06, 0.39, 0.65, 0.15, 0.1, 0.32, 0.52, 0.55, 0.71, 0.93, 0, 0.36)
f <- fitdist(na.exclude(VH),"f", start =list(df1=1, df2=2))
您在此处得到的错误实际上提供了一些信息:
simpleError in optim(par = vstart, fn = fnobj, fix.arg = fix.arg, obs = data, ddistnam = ddistname, hessian = TRUE, method = meth, lower = lower, upper = upper, ...): function cannot be evaluated at initial parameters
Error in fitdist(na.exclude(VH), "f", start = list(df1 = 1, df2 = 2)) :
the function mle failed to estimate the parameters,
with the error code 100
这意味着立即出现问题,而不是在优化过程中。
我猜测了一下,发现你的数据中有一个零值(所以你说所有元素都是正数的说法在技术上是不正确的——它们都是 非负数 ...)。 F 分布在 0 处具有无限值:df(0,1,2)
是 Inf
.
如果我排除零值,我会得到一个答案...
f <- fitdist(na.exclude(VH[VH>0]),"f", start =list(df1=1, df2=2))
...第二个形状参数的估计值非常大(大约6e6,不确定性很大),但似乎适合...
par(las=1); hist(VH,freq=FALSE,col="gray")
curve(df(x,1.37,6.45e6),add=TRUE)
有谁知道为什么下面的代码执行失败fitdist
,错误"the function mle failed to estimate the parameters, with the error code 100"。
我过去在使用正态分布时遇到过这个错误;这种情况下的解决方案是增加向量的方差(通过将其乘以 100),但这对这种情况没有帮助。请注意向量中的所有元素都是正数。谢谢。
library(fitdistrplus)
VH <- c(0.36, 0.3, 0.36, 0.47, 0, 0.05, 0.4, 0, 0, 0.15, 0.89, 0.03, 0.45, 0.21, 0, 0.18, 0.04, 0.53, 0, 0.68, 0.06, 0.09, 0.58, 0.03, 0.23, 0.27, 0, 0.12, 0.12, 0, 0.32, 0.07, 0.04, 0.07, 0.39, 0, 0.25, 0.28, 0.42, 0.55, 0.04, 0.07, 0.18, 0.17, 0.06, 0.39, 0.65, 0.15, 0.1, 0.32, 0.52, 0.55, 0.71, 0.93, 0, 0.36)
f <- fitdist(na.exclude(VH),"f", start =list(df1=1, df2=2))
您在此处得到的错误实际上提供了一些信息:
simpleError in optim(par = vstart, fn = fnobj, fix.arg = fix.arg, obs = data, ddistnam = ddistname, hessian = TRUE, method = meth, lower = lower, upper = upper, ...): function cannot be evaluated at initial parameters
Error in fitdist(na.exclude(VH), "f", start = list(df1 = 1, df2 = 2)) : the function mle failed to estimate the parameters, with the error code 100
这意味着立即出现问题,而不是在优化过程中。
我猜测了一下,发现你的数据中有一个零值(所以你说所有元素都是正数的说法在技术上是不正确的——它们都是 非负数 ...)。 F 分布在 0 处具有无限值:df(0,1,2)
是 Inf
.
如果我排除零值,我会得到一个答案...
f <- fitdist(na.exclude(VH[VH>0]),"f", start =list(df1=1, df2=2))
...第二个形状参数的估计值非常大(大约6e6,不确定性很大),但似乎适合...
par(las=1); hist(VH,freq=FALSE,col="gray")
curve(df(x,1.37,6.45e6),add=TRUE)