0

I am trying to estimate the negative binomial fit to this distribution. I run into the error Error in stats::optim(x = c(12.0267113881516, 0, 3.80379771067847, 7.05725491534987, : non-finite finite-difference value [1] using method SANN.

I tried to follow this solution and set method as "Nelder-Mead" but I still run into an error. Any ideas on how to proceed?

Error in stats::optim(x = c(12.0267113881516, 0, 3.80379771067847, 7.05725491534987, : function cannot be evaluated at initial parameters

   library(MASS)
    test <- c(12.0267113881516,0,3.80379771067847,7.05725491534987,1.62599447730595,8.30878868218926,6.09407800158777,6.0944087874194,1.24210950760511,4.48520498182001,7.25510549345545,1.99853195575834,5.86661457976411,8.32325356444931,6.48394298573265,6.90725677738384,9.2849750875507,4.84723567802178,1.70706120564479,2.41528453337787,5.66663622929956,1.14049051919231,1.20415579381222,4.73028620968109,4.62094824590891,9.99322335474613,7.28555660260907,5.20498129498037,3.29357561350145,5.21546196710692,0,5.27443389563682,0,0,0,1.52534250716659,0,1.14049051919231,1.26613919229593,0,0,0,1.71706472345776,0,3.58594158649788,1.24611128038666,1.1921940752291,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5.3067883458523,3.27131542792302,0,0,2.87101691095707,0,0,0,4.623403877228,0,7.64288059466011,3.92270670542074,2.89377318451868,1.61362654846051,3.30051043721702,0,0,0,0,2.97870996101758,3.87522664704839,1.89909233457104,1.53967232648203,0,12.810006098797,6.87392867858633,1.03574601452557,0,2.18282609051313,11.5312610850693,3.05931137579068,4.1891969565737,6.38862518509007,7.16100053058515,1.52125125858248,6.92516228711371,0,7.75079521410472,4.18476202445648,4.95389780040816,1.04362101432561,5.63455480524832,5.70627520767702,1.01215044368955,9.54222086996302,4.11372615789153,7.85690670281307,0,3.37748286391673,4.34555570781537,4.4577587209379,4.17700827446864,0,2.65463943682732,3.76691803817074,7.76854139503314,1.25612126507028,4.03718613649813,6.53721325487247,3.3860657709757,6.98199462654774,2.61132216481394,3.92396827845501,6.21167776768704,7.14618552521957,4.26831915431375,2.92035777838643,4.29696667800272,7.95684979254918,6.93960648973022,4.88371247587174,5.45540809456259,9.00170760208552,7.10268391665812,4.06498047279548,3.90863722907481,1.84231964976201,6.31650377737209,4.88794131684486,3.57808284954737,4.43455227364459,4.93466754445512,1.0239427169815,3.20804086179141,9.42760542019615,10.0405498853745,2.97745439201775,7.79249606103591,7.23887801626788,7.15339190469555,1.91459640489343,5.08221740008803,15.8154349754837,1.5829472474698,3.83447372539102,0,1.21927980113296,4.95633469976262,1.13850614307505,5.82506904570296,3.41306335807436,0,1.41534148492906,0,3.91594385295598,3.09632981688278,0,0,0,0,0,0)
    
    est <- fitdistr(test, "negative binomial", method = "SANN")$estimate
    est <- fitdistr(test, "negative binomial", method = "Nelder-Mead")$estimate
  • Did my answer addressed your problem? What happened then? If there was no more issue, perhaps you may accept my answer? – Zheyuan Li Jul 07 '22 at 19:55

1 Answers1

2

Samples of Negative Binomial Distribution are integers.

x <- round(test)

fitdistr(x, "negative binomial", method = "Nelder-Mead")$estimate
#    size       mu 
#1.096929 3.422323 
Zheyuan Li
  • 71,365
  • 17
  • 180
  • 248