I am trying to replicate PCA results from an external report, being a paid report I cant see exactly how the numbers are being calculated but I do have a good high level understanding. After a lot of hit and trial the below approach has brought me closest to matching the results:

#small subset from the data (interest rates)
A1 <- 
A2 <- 
A3 <- 
A4 <- 
A5 <-  
A6 <-  
A7 <- 

data <- cbind(A1,A2,A3,A4,A5,A6,A7)

# do PCA on corr because this gives the best match of PC scores plot!
corr <- cor(data)
eg <- eigen(corr)
evectors <- eg$vectors
scores <- -1*(data %*% evectors) #flip sign to match report

# below check does return approx zeros
summary(data - (scores %*% t(evectors)))

The shape of plot of PC1, PC2 and PC3 scores from above matches uncannily with the ones in the report but the scale is completely different. By the way, the report calls them "PC Values", I am assuming it is same as PC Scores. The PC1 scores from above are around 10 (even though none of the inputs > 5.5), while the report has scores that are much closer to the input numbers. Given that first PC on interest rates represents the level of rates, the PC Scores will be much easier to interpret if I could scale down my PC scores to a level more in line with the input numbers? For example in the above subset, having PC score around 3.8 would be easier to understand and more intuitive.

Could someone please give me some pointers about what this transformation might be? I greatly appreciate any help/suggestions/comments.

  • 1
    $\begingroup$ You should not project original data onto the eigenvectors, this does not make a lot of sense to me. Usually in PCA you project the same data that you computed the covariance matrix of, i.e. you project centered and standardized data. Regarding the difference in values: perhaps the report did not use standardized data, i.e. did not divide by the standard deviations? Consider posting the original figures and your replication attempt. $\endgroup$
    – amoeba
    Mar 19, 2015 at 21:02
  • $\begingroup$ @amoeba Thank you for your comment, I have made some progress and accordingly updated the question. If you could please spare some time and share your thoughts, that'd be very helpful. $\endgroup$ Mar 21, 2015 at 16:48
  • 1
    $\begingroup$ I don't know -- it is weird. PCA is almost always done on the centered data, meaning that principal components are centered as well, i.e. have mean zero. If "the report has all values greater than zero", it is strange. I have no idea why this could be the case. Does this report perhaps have a Methods section or provide any formulas? $\endgroup$
    – amoeba
    Mar 21, 2015 at 16:54
  • $\begingroup$ In addition to what @amoeba said: Have you tried to use an SVD on your original data? (So omit the construction of the correlation/covariance matrix altogether) Maybe you accidentally include some bias in your sample. You mention that "It looks like the output is: constant+lambda*(MyScores). *" are you sure about the *constant part? PCA scores should be zero-meaned. $\endgroup$
    – usεr11852
    Mar 21, 2015 at 19:29
  • $\begingroup$ As I said above, the algorithm that you now follow in your code: projecting raw uncentered and unscaled data onto the eigenvectors of the correlation matrix -- does not make much sense. If this gives a close match to whatever is displayed in the report, then so much worse for this report. $\endgroup$
    – amoeba
    Mar 25, 2015 at 22:46


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.