[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
"Ines Butler" <ibutler@ieral.org> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
st: RE: Matrix inversion "bug" |

Date |
Tue, 10 Jun 2003 11:45:13 -0300 |

Mark I think I am encountering with a similar problem to the one you mention about symentric matrices. I am usingmat function 'mat accum' with the options noconstant and deviations to construct a matrix from data which should return a positive definite matrix (because divided by N-1 is the covariance matrix). However, when I try to use cholesky factorization, an error message appears saying that the matrix is not positive definite. Do you have any idea on how to cope with this problem? Thank you very much! Inés Butler IERAL Fundación Mediterránea -----Mensaje original----- De: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu]En nombre de Mark Schaffer Enviado el: Monday, June 09, 2003 8:19 PM Para: Statalist CC: Mark Schaffer Asunto: st: Matrix inversion "bug" Dear Statalisters: Every now and then I encounter a matrix inversion "bug" in Stata. It cropped up yet again last week when an ivreg2 user wrote to me, and I finally decided to see what my fellow Statalisters think of it. Say we have a matrix M which is calculated as X*S*X'. S is symmetric and so is M. We want to invert M and so the best thing to do is to use -syminv-. The Stata programming manual tells us to use -syminv- instead of -inv- wherever possible. The problem is this. Although M is guaranteed to be symmetric in principle, it is not guaranteed to be symmetric in practice. Tiny rounding errors can arise when Stata multiplies matrices. Once in a while, M will be very slightly non-symmetric, but when it is, -syminv- will exit with an error. When I first encountered this, I wrote to Stata Technical Support, and I received a very helpful and simple fix: prior to the call to syminv, simply do the following: mat M = (M+M')/2 This makes the matrix symmetric. Works, no problem. But... Arguably, this is just a fix for what is really a Stata bug. Ought it be possible for Stata's code to recognise when the result of a matrix multiplication is supposed to be a symmetric matrix? Whether or not this should be called a "bug", it may still be the case that it's not possible for our friends at Stata Corp to fix it. If so, then there are several possibilities: (1) Prior to using -syminv-, we should always (?) symmetrize the matrix we want to invert using the code fragment above. (2) Any (?) time we call -syminv-, we should use -capture-. If the inversion using -syminv- fails, we should call -inv-. (3) Neither of the above is very pretty. An alternative is to ask our Stata Corp friends to, say, add a variant of the -syminv- function, say -syminv2-. This function would automatically symmetrize a square matrix before inverting it. What do you think? --Mark ________________________________________________________________ DISCLAIMER: This e-mail and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom it is addressed. If you are not the intended recipient you are prohibited from using any of the information contained in this e-mail. In such a case, please destroy all copies in your possession and notify the sender by reply e-mail. Heriot Watt University does not accept liability or responsibility for changes made to this e-mail after it was sent, or for viruses transmitted through this e-mail. Opinions, comments, conclusions and other information in this e-mail that do not relate to the official business of Heriot Watt University are not endorsed by it. ________________________________________________________________ * * For searches and help try: * http://www.stata.com/support/faqs/res/findit.html * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/ * * For searches and help try: * http://www.stata.com/support/faqs/res/findit.html * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**References**:**st: Matrix inversion "bug"***From:*Mark Schaffer <M.E.Schaffer@hw.ac.uk>

- Prev by Date:
**st: RE: Matrix inversion "bug"** - Next by Date:
**st: RE: RE: Matrix inversion "bug"** - Previous by thread:
**st: Matrix inversion "bug"** - Next by thread:
**st: RE: Matrix inversion "bug"** - Index(es):

© Copyright 1996–2014 StataCorp LP | Terms of use | Privacy | Contact us | What's new | Site index |