r语言 - FitDist 错误:'data must be a numeric vector of length greater than 1'



我正在尝试使用以下代码安装分发:

fit.gamma <- fitdist(x, distr = "gamma", method = "mle")

我有以下错误:

FITDIST中的错误(X,dister =" gamma",method =" mle"):数据必须是长度大于1

的数字向量

X是数字变量。绘制时看起来像这样。1

为什么我会收到此错误。任何技巧都非常感谢。

> class(x)
[1] "numeric"
> str(x)
 atomic [1:18839] 7 175 386 375 397 333 378 394 330 346 ...
 - attr(*, "na.action")=Class 'omit'  int [1:17] 1 209 267 286 288 297 299 300 304 305 ...
> dput(head(x, 20))
c(7, 175, 386, 375, 397, 333, 378, 394, 330, 346, 306, 344, 308, 
278, 291, 284, 252, 294, 277, 241)

谢谢

问题似乎是您使用了na.omit,它不返回像fitdist这样的向量。

而不是这个

x <- na.omit(x.init)
fit.gamma <- fitdist(x, distr = "gamma", method = "mle")

尝试将na.omit的输出转换为向量

x <- c(na.omit(x.init))
fit.gamma <- fitdist(x, distr = "gamma", method = "mle")

相关内容

最新更新