[SciPy-User] Question about errors (uncertainties) in non-linear least squares fitting
Tue Aug 7 09:25:51 CDT 2012
First off you may want to use a more up to date version of
leastsqbound which can be found at
Second, when you perform a constrained optimization using internal
parameters like leastsqbound does,
if one of more of the parameters is close to a bound, the values in the
covariance matrix can take on meaningless values. Section 1.3 of the
The Minuit User's Guide  gives a good overview of this, especially
look at the discussion on page 5. For best results an unconstrained
optimization should be performed, often times you can rewrite your model
in such a way that the constraints are automatically imposed (this is
what is done internally in leastsqbound, but transforming back to the
original model can introduce large errors if a parameter is close to the
Third, since you have measurement uncertainties make sure you
include them in the chi^2 calculation. I find the discussion by P.H.
Richter  to be quite good.
- Jonathan Helmus
 Estimating Errors in Least-Squares Fitting, P.H. Richter TDA
Progress Report 42-122
On 08/07/2012 09:16 AM, Pawe? Kwas'niewski wrote:
> I'm fitting some data using a wrapper around the
> scipy.optimize.leastsq method which can be found under
> Basically it allows for putting bounds on the fitted parameters, which
> is very important for me.
> I'm using the covariance matrix, returned by leastsq() function to
> estimate the errors of the fitted parameters. The fitting is done
> using real measurement uncertainties (which are ridiculously small, by
> the way), so I would expect the resulting parameter error to be
> reasonable. What don't understand, is that I'm getting extremely small
> errors on the fitted parameters (I calculate the errors as perr =
> sqrt(diag(fitres)), where fitres is the covariance matrix
> returned by leastsq() function). For example, a parameter which has a
> fitted value of ~100 gets an error of ~1e-6. At the same time, when I
> calculate the reduced chi squared of the fit I'm getting an extremely
> large number (of the order of 1e8). I can understand the large chi^2
> value - the data variance is extremely small and the model curve is
> not perfect, so even slight deviations of the fitted model from the
> data will blow up chi^2 into space. But how can the fitted parameter
> variance be so small, while at the same time the fit is garbage
> according to chi^2?
> I guess this requires a better understanding of how the covariance
> matrix is calculated. Some suggestions anyone?
> SciPy-User mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the SciPy-User