[SciPy-user] scipy.optimize.leastsq and covariance matrix meaning
Thu Nov 6 15:05:21 CST 2008
massimo sandal wrote:
> I have a trouble with the covariance matrix in the output of
> scipy.optimize.leastsq . I am trying to find the estimated sigma of
> the parameters obtained by the fit. Please bear with me since my
> statistics knowledge is poor. I understand that the diagonal of the
> covariance matrix should return me the variance values of each parameter.
> Problems are:
> 1) The variance of such parameters look unreasonably large to me,
> despite the fact I obtain an *excellent* fit over a lot of data points
> (and values extremly well coherent with expected).
> 2) The non-diagonal values of the covariance are also unreasonably
> large, which lets me doubt that picking simply the diagonal values is
> the correct thing to do.
> The residuals function is:
> def residuals(params,y,x,T):
> Calculates the residuals of the fit
> lambd, pii=params
> err = y-( (therm*pii/4) * (((1-(x*lambd))**-2) - 1 +
> (4*x*lambd)) )
> return err
> For example, a common entity of values is:
> and the relative covariance matrix is
> [[ 1.97019986e+29 -2.67163157e+33]
> [ -2.67163157e+33 3.78415451e+37]]
> ...which concerns me.
> SciPy-user mailing list
It is possible to be correct if the values of y are large and
sufficiently variable. But, based on the comment on the fit and the
correlation in the matrix above is -0.98, my expectation is that there
is almost no error/residual variation left. The residual variance should
be very small (sum of squared residuals divided by defree of freedom).
You don't provide enough details but your two x variables would appear
to virtually correlated because of the very highly correlation. There
are other reasons, but with data etc. I can not guess.
More information about the SciPy-user