I am trying to fit a distribution to my data (ssdist
; ssi
is the values), however I keep getting thrown the error code below, and I have no idea why. Notably, the error is only thrown for pois
and nbinom
which are the distributions that I think might fit the data best.
Error in fitdistrplus::fitdist(ss$ssi[ss$name == s], distr = "nbinom") : the function mle failed to estimate the parameters, with the error code 100
Here is my code:
ssdist <- read_excel(here("Data/Raw/ssdist.xlsx")) %>%
verify(has_all_names("name", "ssi")) %>%
assert(name) %>%
assert(is.numeric, ssi)
library(fitdistrplus)
par0 <- par(mfrow = c(3,2))
for(s in unique(ssdist$name)) {
fitdistrplus::descdist(ss$ssi[ss$name == s], discrete = TRUE)
title(sub = s)
}
par(par0)
This is the code block giving me issues
par0 <- par(mfrow = c(2,2))
for(s in unique(ssdist$name)) {
f <- fitdistrplus::fitdist(ss$ssi[ss$name == s], distr = "nbinom")
fitdistrplus::cdfcomp(f, main = "Cumulative distribution: Data vs. theoretical")
title(sub = s)
mtext(side = 3, line = 0,
text = paste0("p-value: ", round(fitdistrplus::gofstat(f)$chisqpvalue, 4)))
}
par(par0)
Here is a link to my data (I was unsure how to post it here): https://docs.google.com/spreadsheets/d/1B-9sygnfDd8rUjyN3ZO6DwpvMO95FLMi02RlKpDC7Ig/edit?usp=sharing