Statalist


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

Re: st: Principal components


From   Maarten buis <maartenbuis@yahoo.co.uk>
To   stata list <statalist@hsphsun2.harvard.edu>
Subject   Re: st: Principal components
Date   Thu, 17 Apr 2008 08:24:51 +0100 (BST)

The matrix e(L) does not contain the eigenvalues, it contains the
loadings. The eigenvalues are stored in e(Ev). In the example below you
can see that the predicted score is the weighted sum of the
standardized values of the variables you fed into -pca-, where the
weights are the elements in e(L).

Hope this helps,
Maarten

*------------- begin example --------------------
sysuse auto, clear
local vars "trunk weight length headroom"
pca `vars', comp(1)
matrix l = e(L)
predict pred, score
local i = 1
foreach var of varlist `vars' {
	sum `var' if e(sample)
	gen double Z`var' = (`var'-r(mean))/r(sd)
	if `i' == 1 {
		gen double comp = l[`i',1]*Z`var'
                local i = `i' + 1
	}
	else {
		replace comp = comp + l[`i',1]*Z`var'
                local i = `i' + 1
	}
}

twoway scatter pred comp, aspect(1) || ///
       function y = x, range(-4 4) lpattern(dot) ///
       xtitle("generated") ///
       ytitle("predicted") legend(off)
*---------------- end example ------------------------------
(For more on how to use examples I sent to the Statalist, see
http://home.fsw.vu.nl/m.buis/stata/exampleFAQ.html )


--- daniel cassar <danicassar@yahoo.com> wrote:
> Thanks for your reply, Maarten. However, I have
> problems with this. The matrix e(L) is the eigenvalue
> matrix. Could you please be more explicit? What steps
> should I follow?
> 
> Sorry for contacting out of statalist. 
> 
> Thanks for your help!
> 
> 
> 
> >You can find them in the matrix e(L) after you have
> run -pca-.
> >
> >Hope this helps,
> >Maarten
> >
> >--- daniel cassar <danicassar@yahoo.com> wrote:
> >
> >> Hi, 
> >> 
> >> I am at odds with principal components in Stata. I
> am using -pca- to
> >> create an index of eight variables but I cannot
> seem to find a way to
> >> find a way to get the weights for the underlying
> variables. Is there
> >> anybody who can help me with this? 
> >> 
> >> I use the following procedure
> >> 
> >> -pca var1 var2 var3 var4 var5 var6 var7 var8-
> >> 
> >> then, I get the first component as my index:
> >> 
> >> -predict index, score-
> >> 
> >> How do I get the weights for var1 ... var8 in
> index?
> >> 
> >> 
> >> Help very much appreciated. 
> >> 
> >> Best regards, 
> >> DC
> >> 
> >> 
> >> 
> >> 
> 
> 
>      
>
____________________________________________________________________________________
> ˇCapacidad ilimitada de almacenamiento en tu correo!
> No te preocupes más por el espacio de tu cuenta con Correo Yahoo!:   
>                   
> http://correo.espanol.yahoo.com/
> 


-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands

visiting address:
Buitenveldertselaan 3 (Metropolitan), room Z434

+31 20 5986715

http://home.fsw.vu.nl/m.buis/
-----------------------------------------


      ___________________________________________________________ 
Yahoo! For Good helps you make a difference  

http://uk.promotions.yahoo.com/forgood/
*
*   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/



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