1

I am trying to fit a truncated normal distribution to some data. However, I have been running into the following error:

<simpleError in optim(par = vstart, fn = fnobj, fix.arg = fix.arg, obs = data,     gr = gradient, ddistnam = ddistname, hessian = TRUE, method = meth,     lower = lower, upper = upper, ...): non-finite finite-difference value [1]>
Error in fitdist(testData, "truncnorm", start = list(a = 0, mean = 0.8,  : 
  the function mle failed to estimate the parameters, 
                with the error code 100

I'm not sure what's going wrong - I've read that in some cases there can be problems fitting if the initial guesses are wrong or higher than the actual values, but I've tried a number of different start values and none seem to work.

Here is a small sample of my data, and the code I used to get the error:

library(fitdistrplus)
library(truncnorm)
testData <- c(3.2725167726, 0.1501345235, 1.5784128343, 1.218953218, 1.1895520932, 
              2.659871271, 2.8200152609, 0.0497193249, 0.0430677458, 1.6035277181, 
              0.2003910167, 0.4982836845, 0.9867184303, 3.4082793339, 1.6083770189, 
              2.9140912221, 0.6486576911, 0.335227878, 0.5088426851, 2.0395797721, 
              1.5216239237, 2.6116576364, 0.1081283479, 0.4791143698, 0.6388625172, 
              0.261194346, 0.2300098384, 0.6421213993, 0.2671907741, 0.1388568942, 
              0.479645736, 0.0726750815, 0.2058983462, 1.0936704833, 0.2874115077, 
              0.1151566887, 0.0129750118, 0.152288794, 0.1508512023, 0.176000366, 
              0.2499423442, 0.8463027325, 0.0456045486, 0.7689214668, 0.9332181529, 
              0.0290242892, 0.0441181842, 0.0759601229, 0.0767983979, 0.1348839304
)

fitdist(testData, "truncnorm", start = list(a = 0, mean = 0.8, sd = 0.9))
mlinegar
  • 1,389
  • 1
  • 11
  • 19

1 Answers1

1

The problem is that the mle estimator provides increasingly negative estimates for the parameter mean as the lower bound a tends to zero (note that the latter must not be specified within the start parameter, but within fix.arg):

fitdist(testData, "truncnorm", fix.arg=list(a=-.5),
        start = list(mean = mean(testData), sd = sd(testData)))
fitdist(testData, "truncnorm", fix.arg=list(a=-.2),
        start = list(mean = mean(testData), sd = sd(testData)))
fitdist(testData, "truncnorm", fix.arg=list(a=-.15),
        start = list(mean = mean(testData), sd = sd(testData)))

One possibility to prevent large negative values for mean is to use a lower bound for the optimisation:

fitdist(testData, "truncnorm", fix.arg=list(a=0),
        start = list(mean = mean(testData), sd = sd(testData)),
        optim.method="L-BFGS-B", lower=c(0, 0))

However, this alters the estimation procedure; in fact you are imposing additional constraints on the parameters and might obtain different answers with different lower bounds.

renato vitolo
  • 1,744
  • 11
  • 16
  • This leaves me with a few questions - the data that I'm working with can't be lower than zero, but I don't necessarily care about whether or not the mean is negative as I'm just trying to fit a distribution to the data as best I can. Given that mle estimators tend negative as `a` goes to zero, would it be better to use non-mle estimation? Does it make sense to have negative values of `a` if the data itself can't be negative? – mlinegar Aug 11 '16 at 19:05
  • These are very interesting questions, as I stumbled upon them myself a while ago and it took me some thinking to figure them out. However, I think that they would be more suited to http://stats.stackexchange.com/, as they are of statistical nature. If you post them there with your example, I'll be happy to provide you an extended answer (which, now that I think of it, might be already available there). – renato vitolo Aug 12 '16 at 14:33
  • Thank you, I just posted the new question here: http://stats.stackexchange.com/questions/229624/fitting-truncated-distributions-using-fitdistrplus-with-a-lower-bound-of-zero – mlinegar Aug 13 '16 at 00:04
  • OK, I posted an answer there. – renato vitolo Aug 16 '16 at 00:31