# [SciPy-User] [SciPy-user] Covariance matrix

josef.pktd@gmai... josef.pktd@gmai...
Wed Feb 15 10:42:30 CST 2012

```On Wed, Feb 15, 2012 at 8:36 AM, suzana8447 <k-assem84@hotmail.com> wrote:
>
> Thanks all for your  help.
>
> What I have understood is that I get what so called the cov_x from least
> square root fit and then multipy this matrix by the error variance.
>
> I have two more questions.
>
> 1) What is meant by the  error variance? How one can extract it?
>
> 2) Do you mean by ||err||= func-data?

(func-data).sum() / (n-k)
squared sum of it an divided by number of observations minus number of
parameters, as Chuck mentioned

source of curve_fit is useful
https://github.com/scipy/scipy/blob/master/scipy/optimize/minpack.py#L441

IIRC, infodict 'fvec'  returns the squared error sum

Josef

>
> Thanks in advance.
>
> Charles R Harris wrote:
>>
>> On Mon, Feb 13, 2012 at 8:56 AM, <josef.pktd@gmail.com> wrote:
>>
>>> On Sat, Feb 11, 2012 at 7:39 PM, Kevin Gullikson
>>> <kevin.gullikson@gmail.com> wrote:
>>> > Use full_output=True when you call leastq, and you will get a matrix
>>> (among
>>> > other things). If you multiply that matrix by the standard deviation of
>>> the
>>> > residuals, it will be the covariance matrix.
>>>
>>> As Charles pointed out, multiply by the error variance not the
>>> standard deviation. Docstring is wrong in this.
>>>
>>>
>> Even more precisely, multiply by ||err||^2/(n - dof), since it is possible
>> that the error has an offset unless the model can perfectly fit a
>> constant.
>> If this actually makes a difference, the model is inadequate, but the
>> variance estimate might be useful if you are using something like the
>> Akaike information criterion to choose the number of parameters.
>>
>> <snip>
>>
>> Chuck
>>
>> _______________________________________________
>> SciPy-User mailing list
>> SciPy-User@scipy.org
>> http://mail.scipy.org/mailman/listinfo/scipy-user
>>
>>
>
> --
> View this message in context: http://old.nabble.com/Covariance-matrix-tp33301423p33328834.html
> Sent from the Scipy-User mailing list archive at Nabble.com.
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
```

More information about the SciPy-User mailing list