[R] prcomp - arbitrary direction of the returned principal components

Ashim Kapoor @@h|mk@poor @end|ng |rom gm@||@com
Wed Oct 12 13:48:26 CEST 2022


Dear R experts,

>From ?prcomp,

---- snip -----
Note:

     The signs of the columns of the rotation matrix are arbitrary, and
     so may differ between different programs for PCA, and even between
     different builds of R.
---- snip ------

My problem is that I am building an index based on Principal
Components Analysis.
When the index is high it should indicate stress in the market. Due to
the arbitrary sign sometimes I get an index which is HIGH when there
is stress and sometimes I get  the OPPOSITE - an index which is LOW
when there is stress.
This program is shared with other people who may have a different build of R.

I can forcefully use a NEGATIVE sign to FLIP the index when it is LOW.
That works.

Now my query is : Just like we do set.seed(1234) and force the pattern
of generation of random number and make it REPRODUCIBLE, can I do
something like :

set.direction.for.vector.in.pca(1234)

Now each time I do prcomp it should choose the SAME ( high or low )
direction of the principle component on ANY computer having ANY
version of R installed.

That's what I want. I don't want the the returned principal component
to be HIGH(LOW) on my computer and LOW(HIGH) on someone else's
computer.
That would confuse the people the code is shared with.

Is this possible ? How do people deal with this ?

Many thanks,
Ashim



More information about the R-help mailing list