Confidence Intervals from Model fits

292 views
Skip to first unread message

Eric

unread,
Oct 28, 2015, 7:40:15 PM10/28/15
to lmfit-py
Hi All,

I recently jump from 0.8x to 0.9x lmfit.  This did not break much, but it did break the confidence interval calculations.  My program builds a Model class to do the fitting, but then was calling lmfit.conf_interval() to calculate the true confidence intervals.  That function now requires a minimizer class as an input instead of just a result object (where I previously passed in the ModelFit object from fitting my data), but I'm not sure what to pass in as the minimizer object.  If I try passing in the Model object, I get an error when I have a composite object.  Is there any additional information you can give me about calculating a confidence interval when using the Model architecture?  It feels a little like lmfit has a split personality right now between the models and the direct use of the minimizer.

Matt Newville

unread,
Oct 28, 2015, 9:44:12 PM10/28/15
to Eric, lmfit-py
Hi Eric,


On Wed, Oct 28, 2015 at 6:40 PM, Eric <erev...@gmail.com> wrote:
Hi All,

I recently jump from 0.8x to 0.9x lmfit.  This did not break much, but it did break the confidence interval calculations.  My program builds a Model class to do the fitting, but then was calling lmfit.conf_interval() to calculate the true confidence intervals.  That function now requires a minimizer class as an input instead of just a result object (where I previously passed in the ModelFit object from fitting my data), but I'm not sure what to pass in as the minimizer object.  If I try passing in the Model object, I get an error when I have a composite object.  Is there any additional information you can give me about calculating a confidence interval when using the Model architecture?  It feels a little like lmfit has a split personality right now between the models and the direct use of the minimizer.


Yes, calculating confidence intervals for models got more complicated in 0.9.0 and 0.9.1 due to neglect, whereas it should have actually been made simpler. 

In 0.9.2 (released just a few days ago), the ModelResult class got its own `conf_interval()` and `ci_report()` methods to hide this sort of weird complexity. So now you can do (incomplete example, but probably clear enough):


    model = GaussianModel()
    params  = model.make_params()
    result = model.fit(ydata, params, x=xdata)

    print(result.fit_report())
    print(result.ci_report())


If you *do* want to explicitly run the conf_interval() function, a ModelResult can be used *both* arguments:
   lmfit.conf_interval(result, result)

Yeah, it's sort of weird, but it works.

Hope that helps,

--Matt
Reply all
Reply to author
Forward
0 new messages