# [SciPy-user] optimize.leastsq confusing when it comes to errors

Pim Schellart P.Schellart@student.science.ru...
Thu Mar 26 16:40:16 CDT 2009

```Dear Scipy users,

This is my first post to the list so please let me know if I am
posting the question in the wrong place.
I need to fit several functions to a dataset and would love to use
scipy for this, this would allow me to use Python for all my
scientific work as this is the only task for which I still use gnuplot.
But I find the documentation on optimize.leastsq very confusing.
I can get the fit paramaters (using the example as a guide) but I also
need the errors on the resulting parameters and basically all the
information given by the default gnuplot fit command output, which is
the following.

###################################################################
final sum of squares of residuals : 1588.68
rel. change during last iteration : -2.92059e-06

degrees of freedom    (FIT_NDF)                        : 27
rms of residuals      (FIT_STDFIT) = sqrt(WSSR/ndf)    : 7.67072
variance of residuals (reduced chisquare) = WSSR/ndf   : 58.84

Final set of parameters            Asymptotic Standard Error
=======================            ==========================

a               = 1.77246          +/- 1.984        (111.9%)
b               = 0.713972         +/- 0.06909      (9.677%)
c               = -0.207495        +/- 1.413        (681.2%)

correlation matrix of the fit parameters:

a      b      c
a               1.000
b               0.004  1.000
c              -0.103 -0.088  1.000
###################################################################

Furthermore my datapoints have associated errors and these need to be
taken into account in the fit.
How can I make sure this is done?
Is optimize.leastsq build to do this or should I use a different
function.
It would be even better if the example in the tutorial is extended to
include this information as I can imagine most real world applications
need errors on both the input and the output.
Thank you very much in advance.

Kind regards,

Pim Schellart

P.S. I am aware of the gnuplot python module but I prefer scipy :)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 1590 bytes
Desc: not available
Url : http://mail.scipy.org/pipermail/scipy-user/attachments/20090326/a9f2eb13/attachment-0001.bin
```