# [SciPy-User] [SciPy-user] scipy.odr - Correct form of covx, covy matrix

josef.pktd@gmai... josef.pktd@gmai...
Tue Feb 14 08:55:47 CST 2012

```On Tue, Feb 14, 2012 at 9:29 AM, Robert Kern <robert.kern@gmail.com> wrote:
> On Tue, Feb 14, 2012 at 02:38, Elfnor <elfnor@gmail.com> wrote:
>
>> I am trying to solve a generalised least squares problem of the form A*x = b
>> where A is the problem design matrix and b is a vector of correlated
>> observations with covariance V. V is not diagonal.

to be precise V is the correlation of the error b-A*x, I assume that's
what you mean.

>>
>> That is find x that minimizes (b - A*x)'*inv(V)*(b - A*x) similar to the
>> matlab function lscov.
>
> I think you can distribute the inv(V) by doing a Cholesky
> factorization, then doing a Cholesky-solve on both A and b, then doing
> a linear solve on the transformed A and b.
>
>  from scipy import linalg
>
>  cho = linalg.cho_factor(V)
>  Ac = linalg.cho_solve(cho, A)
>  bc = linalg.cho_solve(cho, b)
>  x = linalg.solve(Ac, bc)

That's pretty much what statsmodels GLS does. The transformed
variables have a w prefix, wendog, wexog, wresid

I don't think we have many examples with the full sized (nobs, nobs) V matrix.

Josef

>
> --
> Robert Kern
>
> "I have come to believe that the whole world is an enigma, a harmless
> enigma that is made terrible by our own mad attempt to interpret it as
> though it had an underlying truth."
>   -- Umberto Eco
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
```