6

I just discovered the fitdistrplus package, and I have it up and running with a Poisson distribution, etc.. but I get stuck when trying to use a binomial:

set.seed(20)
#Binomial distributed, mean score of 2
scorebinom <- rbinom(n=40,size=8,prob=.25)


fitBinom=fitdist(data=scorebinom, dist="binom", start=list(size=8, prob=mean(scorebinom)/8))

I get the error:

Error in fitdist(data = scorebinom, dist = "binom", start = list(size = 8,  : 
  the function mle failed to estimate the parameters, 
                with the error code 100
In addition: There were 50 or more warnings (use warnings() to see the first 50)

I see a lot of documentation from this package about the negative binomial distribution, but not much about the binomial. This function does appear to support this distribution (though fitdistr in MASS does not).

Any thoughts?

emudrak
  • 789
  • 8
  • 25
  • The issue seems to be arising from the MLE routine called inside of `fitdist` - there is a (somewhat unhelpful) list of output codes in the **Value** section of the helpfile `?mledist`. I have run into errors like this from time to time when fitting parameters, and it's usually a pain to track down the exact cause. You might try playing around with the `custom.optim` function `fitdist` passes to `optim`. Sometimes I have better luck with *Simulated Annealing* than the default algorithm used by `optim`. ... – nrussell Dec 23 '14 at 23:30
  • 2
    For example, this returns parameter estimates, but not standard errors, and still produces warnings: `fitdist(data=x,dist="binom",start=list(size=8, prob=mean(x)/8),custom.optim=function(...){optim(..., method="SANN")})` (where I renamed your vector `scorebinom` as `x` for convenience). – nrussell Dec 23 '14 at 23:32

1 Answers1

7

Won't you always know the number of trials (i.e., the size parameter)? If so, then try

fitBinom=fitdist(data=scorebinom, dist="binom", fix.arg=list(size=8), start=list(prob=0.3))

to estimate p and its error.

user1930565
  • 238
  • 1
  • 6
  • 2
    Thanks! That worked. It seems odd to me that it can't estimate the size parameter when I supply it for the starting value, but I suppose it would make sense that it should be required in a fixed argument list. I think the `fitdist` documentation can be more explicit here. – emudrak Jan 08 '15 at 14:02