Statalist


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

RE: st: generating new var using principal components eigen


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: generating new var using principal components eigen
Date   Mon, 12 Jan 2009 17:07:47 -0000

It is ultra-pedantic of me but let me gild this lily by pointing out
that multiplication by -1 is simply negation. 

gen myvarflip = - myvar 

I think it's still true that negation is always easier than
multiplication machinewise, although you might be pushed to discern
that. 

Nick 
[email protected] 

jverkuilen

I can't think of a quicker way to make a variable off-hand but I am sure
if one exists, Nick Cox knows it.

As to the way you reverse the signs, all you need to do is reflect the
variable, i.e., multiply by -1. This is best done by making new
variables which you use in your analysis, keeping the old ones around
for reference.

     gen myvarflip = -1*myvar   

This is a good idea if you have variables worded in a negative and
positive direction. 

Depending on what the variable is, you may want to shift it too. Let's
say the original responses are between 1 and 5. Then 

     gen myvarnew = 6 - myvar 

preserves the original response scale but flips everything around.   

You are free to reflect and recenter because PCA only cares about
covariances and variances. (The fact that it cares about variances is
the essential difference between PCA and factor analysis, which
eliminates the variances and uses only off-diagonal information.) While
reflecting a variable alters the covariances, it does so in a
predictable fashion.   

If you are doing PCA on a correlation matrix, you might as well
standardize everything and reflect the variables to a convenient
direction before analysis.  

In statistical inference a correlation matrix and a covariance matrix
differ, because you made the correlation matrix by dividing by random
variables (the variances and geometric means of standard deviations),
but I doubt this is of much interest and I don't think -pca- corrects
for this difference when it spits out statistics. Perhaps I am
incorrect, though---check the manual.  

[email protected]

I am trying to create a single var_simple comprised of the sum of
var*pc1 (pc1 is the score of component one of a principle components
analysis). I have tried a simple formula where var_simple= pc1*var1+
pc1*var2 etc... but thought there must be a quicker way to compute this
that I am unaware of. Also, in the first example, I obtained a number of
negative values (some of the var's had a negative score for pc1) and I
was wanting to transform them into positive values in simple_var. Any
help would be greatly appreciated Thanks for your attention to what is
no doubt a simple problem!


*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index