[R] Signs of loadings from princomp on Windows

Jari Oksanen jarioksa at sun3.oulu.fi
Thu Sep 16 09:31:51 CEST 2004


On Thu, 2004-09-16 at 02:38, Tony Plate wrote:
> You could investigate this yourself by looking at the code of princomp (try 
> getAnywhere("princomp.default")).  I'd suggest making a file that in-lines 
> the body of princomp.default into the commands you had below.  See if you 
> still get the difference.  (I'd be surprised if you didn't).  Then try 
> commenting out lines the second pass through the commands produces the same 
> results as the first.  The very last thing you commented out might help to 
> answer your question "What would be causing the
> difference?"  (The fact that various people chimed in to say they could 
> reproduce the behavior that bothered you, but didn't bother dig deeper 
> suggests it didn't bother them that much, which further suggests that you 
> are the person most motivated by this and thus the best candidate for 
> investigating it further...)
> 
People were not too bothered, since the sign of the eigenvector is not
well defined in PCA: vectors x and -x are equal. Have you compared
absolute values? Do they differ much (more than, say 1e-6)? If they
differ too much for you, this could be a symptom of some other problems,
so it may be worth investigating in machines where you get this thing
(others can do nothing). Since the princomp.default is difficult to find
(either getAnywhere("princomp.default") or stats:::princomp -- I hate
this information hiding), and its code is winding, I'd suggest you
concentrate studying line:

sol <- eigen(cv, symmetric=TRUE)

where you get the cv with

cv <- cov.wt(x)$cov * (1 - 1/nrow(x))

and x is your data matrix. If cv remains unchanged from time to time,
but there is a change in signs of sol$vectors, then you have localised
your problem. If it's not there, then the rest of the princomp.default
code is worth investigating. If it's in the eigen, then it dives deep
into Fortran, and that may be all you can say. (If your covariance
matrices change with repeated calculations, then the problem is deeper).

However, sign doesn't matter if there are 
-- 
Jari Oksanen <jarioksa at sun3.oulu.fi>




More information about the R-help mailing list