Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Mata problem with nonreals [was: Re: Mata finds nonreal although I can't find a no nonreal]


From   Matthew Baker <[email protected]>
To   [email protected]
Subject   Re: st: Mata problem with nonreals [was: Re: Mata finds nonreal although I can't find a no nonreal]
Date   Tue, 27 Dec 2011 08:09:51 -0500

Dirk --

I have encountered this problem before, and I think it has to do with
the fact that the command "eigensystem" typically returns the
eigenvectors in complex number form, even though results seem to be
reals. Presumably, this is so that the command can be sure it always
finds all eigenvalues. So, I think that the culprit is the sequence (I
modified it a bit):

RF1=1,0\0,1
eigensystem(RF1,V1=.,eigv1=.)

If you now do:

iscomplex(eigv1)

It turns out that these eigenvalues are complex, even though they seem
not to be. One possibility is to simply replace the line:

eigensystem(RF1,V1=.,eigv1=.)

with

symeigensystem(RF1,V1=.,eigv1=.)

As symeigensystem always returns reals. I was able to get your example
to go through just be replacing your eigensystem command with the
symeigensystem command.

Hope that helps!

Matt Baker

On Tue, Dec 27, 2011 at 7:51 AM, Dirk Enzmann
<[email protected]> wrote:
> The title of my first mail had an error and was misleading: It should have
> been
>
> "Mata rinds nonreal although I can't find a nonreal", even better:
> "Why does Mata report nonreals?"
>
> I still have no answer to my question but found a way to get rid of the
> complaint about nonreals: When inserting next to the command line that
> computes A1 via
>
> A1 = S1*(V1:/sqrt(eigv1))*V1'
>
> the command line
>
> A1 = sign(P1):*abs(A1)
>
> Mata does no longer complain about the mysterious nonreals. Of course, this
> is no solution because this is may change the signs of the matrix elements
> in A1 if RF1 is not an identity matrix.
>
> Thus, a suggestion on how to solve the problem is highly appreciated.
>
> Dirk
>
>
> Am 27.12.2011 04:14, schrieb Dirk Enzmann:
>>
>>
>> I just encountered the problem that Mata gives me the error message
>>
>> invsym(): 3253 nonreal found where real required
>> <istmt>: - function returned error
>>
>> although I believe that there is no nonreal value in the matrix.
>>
>> Below is the code that produces the error in the line
>>
>> W1 = A1*invsym(A1'*A1)
>>
>> Note that P1, S1, and A1 should contain the same values due to the fact
>> that RF1 is an identity matrix - if I replace A1 by P1 Mata behaves as
>> it should. If you ask why I use RF1 like that: I am testing whether the
>> special case of a zero correlation is handled correctly - if I insert
>> values such as .05 in the off-diagonal cells, Mata keeps complaining
>> about nonreal values.
>>
>> Any suggestions for a solution of this problem?
>>
>> * -------- (start) ----------
>> mata
>> P1 = ( .43506, .44920 \
>> .68702, .06891 \
>> .77649, -.09335 \
>> -.60949, .27331 \
>> .02898, .65232 \
>> -.16600, .43717 \
>> .82794, -.04080 \
>> .79320, -.11331 \
>> -.04388, .62171 \
>> .03556, .71095 \
>> .08361, .75362 \
>> -.23253, .58472 \
>> .71299, -.20058 \
>> -.19725, .55294 \
>> .51660, .03276 )
>> RF1 = ( 1.00, .00 \
>> .00, 1.00 )
>> S1 = P1*RF1
>> S1
>> V1 = NULL
>> eigv1 = NULL
>> eigensystem(RF1,V1,eigv1)
>> A1 = S1*(V1:/sqrt(eigv1))*V1'
>> A1
>> rssqA1 = diagonal(A1*A1')
>> rssqA1
>> cssqA1 = diagonal(A1'*A1)
>> cssqA1
>> W1 = A1*invsym(A1'*A1)
>> W1
>> end
>> * -------- (end) ------------
>>
>> Dirk
>>
>> ========================================
>> Dr. Dirk Enzmann
>> Institute of Criminal Sciences
>> Dept. of Criminology
>> Rothenbaumchaussee 33
>> D-20148 Hamburg
>> Germany
>>
>> phone: +49-(0)40-42838.7498 (office)
>> +49-(0)40-42838.4591 (Mrs Billon)
>> fax: +49-(0)40-42838.2344
>> email: [email protected]
>>
>> http://www2.jura.uni-hamburg.de/instkrim/kriminologie/Mitarbeiter/Enzmann/Enzmann.html
>>
>> ========================================
>
>
> --
> ========================================
> Dr. Dirk Enzmann
> Institute of Criminal Sciences
> Dept. of Criminology
> Rothenbaumchaussee 33
> D-20148 Hamburg
> Germany
>
> phone: +49-(0)40-42838.7498 (office)
>       +49-(0)40-42838.4591 (Mrs Billon)
> fax:   +49-(0)40-42838.2344
> email: [email protected]
> http://www2.jura.uni-hamburg.de/instkrim/kriminologie/Mitarbeiter/Enzmann/Enzmann.html
> ========================================
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/



-- 
Dr. Matthew J. Baker
Department of Economics
Hunter College and the Graduate Center, CUNY

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index