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: Problem computing eigenvalues, STATA vs. MATA


From   Steven Samuels <sjsamuels@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Problem computing eigenvalues, STATA vs. MATA
Date   Sun, 9 Jan 2011 20:44:44 -0500

Reread Austin's response and then look up the definition of eigenvalues and eigenvectors. The two "different" solutions are, in fact, equivalent.


Steve
sjsamuels@gmail.com


On Jan 9, 2011, at 5:30 PM, Zachary Neal wrote:

This doesn't seem to help.  Running the code suggested below by Austin
Nichols, the values in the first eigenvector using matrix symeigen
are:

.5773502692
.5
.5
.2886751346
.2886751346

However, the values in the first eigenvector using
symeigensystem(st_matrix("A"),vectors2,values2) are:

.5773502692
-.5
-.5
.2886751346
.2886751346

I'm not clear why the 2nd and 3rd values here are not positive, as
they are in the results produced by matrix symeigen.

Best
Zachary

On Sun, Jan 9, 2011 at 10:42 AM, Austin Nichols <austinnichols@gmail.com> wrote:
Zachary Neal <zpneal@gmail.com>:
You are confusing vectors and values there, and not sorting by values
after computing the eigensystem, but note that the only real
difference is that a couple of vectors are negated (any scalar
multiple of an eigenvector is also an eigenvector and the negation has
the same length so they are essentially equivalent) and Mata is using
quad precision to do the computations.

matrix define A = 0,1,1,0,0 \ 1,0,0,1,0 \ 1,0,0,0,1 \ 0,1,0,0,0 \ 0,0,1,0,0
matrix symeigen vectors1 values1 = A
matrix list values1
matrix list vectors1
mata
values2 = 0
vectors2 = 0
symeigensystem(st_matrix("A"),vectors2,values2)
v2=sort((values2\vectors2)',1)'
v2[1,.]
v2[2..6,.]
end

On Sun, Jan 9, 2011 at 8:08 AM, Zachary Neal <zpneal@gmail.com> wrote:
I am trying to obtain the eigenvalues of a symmetric matrix. However, I get different results depending on whether I use STATA or MATA. For
example:

matrix define A = 0,1,1,0,0 \ 1,0,0,1,0 \ 1,0,0,0,1 \ 0,1,0,0,0 \ 0,0,1,0,0
matrix symeigen eigenvalues1 eigenvectors1 = A
matrix list eigenvalues1

mata: A = 0,1,1,0,0 \ 1,0,0,1,0 \ 1,0,0,0,1 \ 0,1,0,0,0 \ 0,0,1,0,0
mata: eigenvalues2 = 0
mata: eigenvectors2 = 0
mata: symeigensystem(A,eigenvalues2,eigenvectors2)
mata: eigenvalues2

In this case, eigenvalues1 does not equal eigenvalues2. I believe the results yielded by STATA (i.e. eigenvalues1) are what I'm looking for.

Why do these two sets of commands yield different results?  What
commands are necessary in MATA to yield the same eigenvalues that are
given by STATA?

Thank you
Zachary Neal

*
*   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/




--
Zachary Neal, PhD
Department of Sociology
Michigan State University
zpneal@msu.edu
http://www.msu.edu/~zpneal

*
*   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/

*
*   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