'FitDist ERROR: 'data must be a numeric vector of length greater than 1'
I am trying to fit a distribution using the following code:
fit.gamma <- fitdist(x, distr = "gamma", method = "mle")
I get the following error:
Error in fitdist(x, distr = "gamma", method = "mle") : data must be a numeric vector of length greater than 1
X is a numeric variable. It looks like this when plotted.1
Why do I get this error. Any tips are greatly appreciated.
Solution 1:[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)
Thanks
Solution 2:[2]
The issue appears to be that you used na.omit, which doesn't return a vector like fitdist is expecting.
Instead of this
x <- na.omit(x.init)
fit.gamma <- fitdist(x, distr = "gamma", method = "mle")
try converting the output of na.omit to a vector
x <- c(na.omit(x.init))
fit.gamma <- fitdist(x, distr = "gamma", method = "mle")
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Stata_user |
| Solution 2 | Jake Greene |
