0
$\begingroup$

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<-c(1.618,1.711,1.665,1.707,2.178,2.047,1.925,1.936,1.997,1.862)
A2<-c(2.342,2.408,2.345,2.397,2.818,2.731,2.637,2.648,2.723,2.59)
A3<-c(3.197,3.258,3.191,3.223,3.634,3.587,3.488,3.51,3.611,3.473)
A4<-c(3.646,3.707,3.653,3.695,4.104,4.032,3.926,3.956,4.044,3.914)
A5<-c(4.428,4.495,4.446,4.49,4.897,4.811,4.734,4.79,4.88,4.738)
A6<-c(4.6,4.688,4.649,4.699,4.965,4.898,4.815,4.82,4.898,4.806)
A7<-c(5.086,5.154,5.13,5.197,5.413,5.397,5.333,5.345,5.415,5.351)

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.

$\endgroup$
  • 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 '15 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$ – user2696565 Mar 21 '15 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 '15 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 '15 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 '15 at 22:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.