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: how to manually calculate eigenvalue of principal components in STATA


From   Mash Hamid <[email protected]>
To   "[email protected]" <[email protected]>
Subject   RE: st: how to manually calculate eigenvalue of principal components in STATA
Date   Sun, 26 May 2013 09:07:08 +0000

Thanks Nick,

I will give this a go. 

Cheers

________________________________________
From: [email protected] [[email protected]] on behalf of Nick Cox [[email protected]]
Sent: 26 May 2013 10:04
To: [email protected]
Subject: Re: st: how to manually calculate eigenvalue of principal components in STATA

For the correct spelling "Stata", please see

http://www.stata.com/support/faqs/resources/statalist-faq/#spell

Here is an example for you:

. sysuse auto
(1978 Automobile Data)

. corr  headroom trunk weight weight length displacement
(obs=74)

             | headroom    trunk   weight   weight   length displa~t
-------------+------------------------------------------------------
    headroom |   1.0000
       trunk |   0.6620   1.0000
      weight |   0.4835   0.6722   1.0000
      weight |   0.4835   0.6722   1.0000   1.0000
      length |   0.5163   0.7266   0.9460   0.9460   1.0000
displacement |   0.4745   0.6086   0.8949   0.8949   0.8351   1.0000

. ret li

scalars:
                  r(N) =  74
                r(rho) =  .6620111289412028

matrices:
                  r(C) :  6 x 6

. mat li r(C)

symmetric r(C)[6,6]
                  headroom         trunk        weight        weight
     length
    headroom             1
       trunk     .66201113             1
      weight     .48345581     .67220573             1
      weight     .48345581     .67220573             1             1
      length     .51629547     .72659561     .94600864     .94600864
          1
displacement     .47449149     .60863505     .89489577     .89489577
  .83514003

              displacement
displacement             1

. mat corr = r(C)

. mat symeigen X lambda = corr

. mat li lambda

lambda[1,6]
            e1          e2          e3          e4          e5          e6
r1    4.670069   .80145975   .30939082   .16168343   .05739702  -2.776e-17

. pca  headroom trunk weight weight length displacement

Principal components/correlation                  Number of obs    =        74
                                                  Number of comp.  =         5
                                                  Trace            =         6
    Rotation: (unrotated = principal)             Rho              =    1.0000

    --------------------------------------------------------------------------
       Component |   Eigenvalue   Difference         Proportion   Cumulative
    -------------+------------------------------------------------------------
           Comp1 |      4.67007      3.86861             0.7783       0.7783
           Comp2 |       .80146      .492069             0.1336       0.9119
           Comp3 |      .309391      .147707             0.0516       0.9635
           Comp4 |      .161683      .104286             0.0269       0.9904
           Comp5 |      .057397      .057397             0.0096       1.0000
           Comp6 |            0            .             0.0000       1.0000
    --------------------------------------------------------------------------

Principal components (eigenvectors)

    ------------------------------------------------------------------------------
        Variable |    Comp1     Comp2     Comp3     Comp4     Comp5 |
Unexplained
    -------------+--------------------------------------------------+-------------
        headroom |   0.3014    0.7768    0.5371   -0.1309   -0.0111 |
         0
           trunk |   0.3747    0.4306   -0.7705    0.2655   -0.1005 |
         0
          weight |   0.4460   -0.2548    0.0571   -0.2144   -0.4324 |
         0
          weight |   0.4460   -0.2548    0.0571   -0.2144   -0.4324 |
         0
          length |   0.4419   -0.1516   -0.1227   -0.4492    0.7516 |
         0
    displacement |   0.4192   -0.2415    0.3105    0.7866    0.2256 |
         0
    ------------------------------------------------------------------------------

Here is the code in one:

sysuse auto

corr  headroom trunk weight weight length displacement

ret li

mat li r(C)

mat corr = r(C)

mat symeigen X lambda = corr

mat li lambda

pca  headroom trunk weight weight length displacement


Nick
[email protected]


On 26 May 2013 09:55, Mash Hamid <[email protected]> wrote:
> Hi,
>
> I'm having difficulty computing eigenvalue of principal components (not principal component factors) by hand. I know how to calculate the eigenvalues of each principal component factors. Suppose I have 6 variables in component 1 and the out put looks like:
>
>
> Component |   Eigenvalue   Difference         Proportion   Cumulative
>     -------------+------------------------------------------------------------
>     Comp1 |      1.70622      .303339             0.2844       0.2844
>     Comp2 |      1.40288      .494225             0.2338       0.5182
>     Comp3 |      .908652      .185673             0.1514       0.6696
>     Comp4 |      .722979     .0560588             0.1205       0.7901
>     Comp5 |       .66692      .074563             0.1112       0.9013
>     Comp6 |      .592357            .             0.0987       1.0000
>     --------------------------------------------------------------------------
>
> Principal components (eigenvectors)
>
>  ---------------------------------------------------------------------------
>  Variable |    Comp1     Comp2     Comp3     Comp4     Comp5     Comp6 |
>  ---------+------------------------------------------------------------+
>  bt1      |   0.2741    0.5302   -0.2712   -0.7468   -0.0104   -0.1111 |
>  bt2      |  -0.3713    0.4428   -0.4974    0.2800    0.2996    0.5005 |
>  bt3      |  -0.4077    0.4834    0.0656    0.2466   -0.5649   -0.4646 |
>  bt4      |  -0.3766    0.2748    0.7266   -0.2213    0.4504    0.0538 |
>  bt5      |   0.4776    0.3345    0.3829    0.1950   -0.3942    0.5657 |
>  bt6      |   0.5009    0.3192    0.0144    0.4647    0.4824   -0.4453 |
>
>     ---------------------------------------------------------------------------
>
>
>
> how do I calculate the eigenvalue using the info above in STATA by using display?
>
>
> Many thanks
>
>
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/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/faqs/resources/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/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


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