Solved – Warnings in R after “fitdistr” used

fittingr

I have just tried to fit a t-dist in R for some data, and did this by reading in a 21×1 csv file and converting to numeric (can show code used if you think it's important).
It has produced parameters but with 27 warnings all saying 1: In log(s) : NaNs produced etc up to 26: and one saying In sqrt(diag(vc)) : NaNs produced.
Does this affect the validity of the parameters it has come back with?

I also just noticed it has 2 values for mean, sd and df. One on top and one below in brackets? what do these mean?

        m               s               df      
  -0.0001337445    0.0034887033   10.0256862670 
 ( 0.0008246931) ( 0.0000891192) (          NaN)
There were 27 warnings (use warnings() to see them)

Best Answer

This often happens when internally some of the results were invalid, like logarithms of non-positive numbers. In my experience, I have found fitdistr to be very "fragile". Sometimes you will still get results, other times (often with gammas) fitdistr just fails. You are almost always better off writing a small function to return the negative loglikelihood, and passing it directly into optim using Nelder-Mead (to dispense with calculating derivatives, although deriv3 often works).