Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • matrix not symmetric

    Dear All:

    I am doing the following matrix calculation:

    . matrix alpha_head_t = (1/650) * (I - B*(invsym(B'*B))*B')* Sigma_a * (I-B*(invsym(B'*B))*B')


    . matrix teststatisticbasic = alpha' * invsym(alpha_head_t) * alpha
    matrix not symmetric

    matrix not symmetric
    r(505);


    alpha_head_t is a matrix with 25 rows and 25 columns
    alpha is a matrix with 25 rows and one column .

    Does anyone know how to solve this issue?

    Many Thanks!

  • #2
    What do the following commands result in?
    Code:
    display issymmetric(alpha_head_t)
    display issymmetric(Sigma_a)

    Comment


    • #3
      Dear Professor Lisowski:

      Thank you for your help!

      I got the following:


      . display issymmetric(alpha_head_t)
      0

      . display issymmetric(Sigma_a)
      1

      Thank you!

      Comment


      • #4
        Well, the problem is that alpha_head_t is not symmetric.

        Perhaps one of your two instances of
        Code:
        (I-B*(invsym(B'*B))*B')
        was intended to be
        Code:
        (I-B*(invsym(B'*B))*B')'

        Comment


        • #5
          Dear Professor Lisowski:

          Thank you for your reply!

          I tried it but it did not work. Any other suggestions?

          Thank you

          Comment


          • #6
            In what way did it "not work"? Same error message? Different error message? No error message, wrong results?

            Please review the Statalist FAQ linked to from the top of the page, as well as from the Advice on Posting link on the page you used to create your post. Note especially sections 9-12 on how to best pose your question.

            The more you help others understand your problem, the more likely others are to be able to help you solve your problem.

            Section 12.1 is particularly pertinent

            12.1 What to say about your commands and your problem

            Say exactly what you typed and exactly what Stata typed (or did) in response. N.B. exactly!
            ...
            Never say just that something "doesn't work" or "didn't work", but explain precisely in what sense you didn't get what you wanted.

            Comment


            • #7
              Dear Professor William Lisowski:

              Thank you for your reply!

              The stata output:

              . *first instance
              . matrix alpha_head_t = (1/650) * (I - B* invsym(B'*B)*B')'* Sigma_a * (I-B*invsym(B'*B)*B')
              . matrix teststatisticbasic = alpha' * invsym(alpha_head_t) * alpha
              matrix not symmetric
              r(505);

              *second instance
              . matrix alpha_head_t = (1/650) * (I - B* invsym(B'*B)*B')* Sigma_a * (I-B*invsym(B'*B)*B')'
              . matrix teststatisticbasic = alpha' * invsym(alpha_head_t) * alpha
              matrix not symmetric
              r(505);

              . *both instances
              . matrix alpha_head_t = (1/650) * (I - B* invsym(B'*B)*B')'* Sigma_a * (I-B*invsym(B'*B)*B')'

              . matrix teststatisticbasic = alpha' * invsym(alpha_head_t) * alpha
              matrix not symmetric
              r(505);

              .

              Comment


              • #8

                [P] error . . . . . . . . . . . . . . . . . . . . . . . . Return code 505
                matrix not symmetric
                You have issued a matrix command that can be performed only on
                a symmetric matrix, and your matrix is not symmetric. While
                fixing their code, programmers are requested to admire our
                choice of the "symmetric" number 505 -- it is symmetric about
                the zero -- for this error.

                Comment


                • #9
                  Well this demonstrates that Stata has as sense of humor.

                  I guess my next suggestion would be to show the results of the following.
                  Code:
                  display issymmetric(alpha_head_t)
                  matrix list alpha_head_t
                  and perhaps also
                  Code:
                  display issymmetric(I)
                  matrix list I
                  matrix BB = B * invsym(B'*B) * B'
                  display issymmetric(BB)
                  matrix list BB

                  Comment


                  • #10
                    Sorry for coming late to the party. I have some thoughts here.

                    By ordinary matrix algebra:
                    Code:
                    B * invsym(B'*B) * B' = B * ((inv(B)*inv(B')) * B'
                             = (B*inv(B)) *( inv(B')*B')
                             = I * I = I
                    Now, if you do it with a real matrix, there will be some rounding errors, so you won't get exactly I, but you'll get numbers extremely close to 1 on the diagonal and extremely close to 0 elsewhere.

                    When you then calculate I - B * invsym(B'*B) * B', that is 0 (or, with real matrices, within rounding error of 0).

                    It follows that alpha_head_t should also, in theory, always be a 0 matrix, and in reality will be nearly so. It may be that when Stata then tries to calculate invsym(alpha_head_t) it is blowing up because alpha_head_t is singular, but is giving an incorrect message about it not being symmetric.

                    In other words, I think the expression that Binder is trying to calculate is in fact undefined, the inverse of a zero matrix, but the Stata error message is misleading as to why.

                    Comment

                    Working...
                    X