# [Scipy-tickets] [SciPy] #1157: Correlation matrix from scipy.optimize.leastsq(): undocumented approximation?

SciPy Trac scipy-tickets@scipy....
Tue Apr 20 08:55:35 CDT 2010

```#1157: Correlation matrix from scipy.optimize.leastsq(): undocumented
approximation?
-----------------------------------------+----------------------------------
Reporter:  lebigot                      |       Owner:  somebody
Type:  enhancement                  |      Status:  new
Priority:  normal                       |   Milestone:  0.8.0
Component:  scipy.optimize               |     Version:  0.7.0
Keywords:  leastsq, correlation matrix  |
-----------------------------------------+----------------------------------
The correlation matrix calculation from scipy.optimize.leastsq() implies
(as far as I understand from the source code) that the minimized sum of
squares is actually a sum of functions of a specific form, namely

{{{
((y_i - f(x_i; a))/s_i)**2
}}}

(where 'a' are the parameters to be optimized).

If this is the case, I would suggest that the documentation for the
returned covariance matrix makes this explicit.

In fact, I spent a lot of time struggling with leastsq's covariance matrix
result because I thought that the returned correlation matrix was the
inverse of the curvature matrix of the minimized function.  This would is
a good definition of the "formal" covariance matrix when the function
minimized by leastsq is a log-likelihood (i.e., a generalization of the
above terms).  I guess that the "no second-order derivative" approximation
to the curvature matrix used in the code does not hold anymore, when terms
do not average to zero, so that the covariance matrix becomes very wrong
if a constant is added to each (squared) term (even though the curvature
of the minimized function does not change, in this case).

So, to summarize, if the above special form for the terms is confirmed, I
think that it would be great if the definition of the returned covariance
matrix was made more precise (such as "covariance matrix" for normally
distributed terms of the form "…").  This could save a lot of time to some
people! :)

--
Ticket URL: <http://projects.scipy.org/scipy/ticket/1157>
SciPy <http://www.scipy.org>
SciPy is open-source software for mathematics, science, and engineering.
```