My question envolves a discrepancy between principal components estimated by hand in Eviews and the ones estimated by makepcomp.
Before making the proper question, I think need to contextualize it.
I'm trying to build a Financial Condition Index (FCI) with Principal Components Analysis. The idea is quite simple: extract the first principal component from seven different groups of variables (e.g., interest rates, commodities, exchange rates, etc) and make a linear combination of this 7 different principal components to build the FCI.
Well, in order to so, I decided to try to create the principal components directly with programming. The steps were:
[1] take the z-score of all the variables
[2] estimate the covariance matrix for each of the 7 groups of variables, which in this case will be the correlation matrix, given that data is standardized
[3] calculate the eigenvalues and eigenvectors for each covariance (correlation) matrix
[4] calculate de principal components by multiplying the matrices with standardized data by the corresponding eigenvector matrix
[5] extract the first column of the principal component matrix, which corresponds to the first principal component
I will put below the codes I have used for steps [2] to [4], so it becomes more clear:
Code: Select all
Step [2]
'list that saves all group names
string list_group_names = @lower(@wlookup("*", "group"))
'creating the matrices for each group
for %j {list_group_names}
stom({%j}, matrix_{%j})
next
'calculating the covariance (correlation) matrices for each group
for %j {list_group_names}
sym cov_matrix_{%j} = (1/@rows(matrix_{%j})) * (@transpose(matrix_{%j})*matrix_{%j})
next
Step [3]
'Calculating the vectors with the eigenvalues and sorting them in descending order
for %j {list_group_names}
vector eigvalue_{%j} = @sort(@eigenvalues(cov_matrix_{%j}), "d")
next
'Calculating the matrices with the corresponding eigenvectors and sorting them in the same order of the eigenvalues
for %j {list_group_names}
matrix eigvector_{%j} = @rapplyranks(@eigenvectors(cov_matrix_{%j}), @ranks(eigvalue_{%j}, "a", "i"))
next
Step [4]
'Calculating the principal components
for %j {list_group_names}
matrix pc_{%j} = matrix_{%j} * eigvector_{%j}
next
In this sense, I decided to use makepcomp to check my results with the ones from the function. Surprisingly, altough the eigenvalues estimated by hand and with makepcomp are basically the same (some difference in the third or forth decimal place), the eigenvectors, although identical in module, have a different sign. This happens for some group of variables, and others not.
So, in the case of interest rates, the values of the first column of eigenvector matrix estimated by hand (used to estimate the first pc) are negative, and with makepcomp, they are positive. Of course, this changes the sign of my principal components for interest rates and, consequently, the impact of the interest rate principal component on my FCI will be different (higher rates with have a negative impact in the case of PC estimated by hand, which should not be true).
That said, as far as I know, the eigenvectors are not unique, and can be subect to rotations (like the change in sign). Nevertheless, in this case the sign is creating a "distortion" in the impact of the principal component in my FCI.
Could anyone help me with this? I would like to understand if I have made something wrong when estimating the PCs by hand. Or I'm misinterpreting something. Maybe makepcomp uses a different process for calculating PCs.
Thanks very much in advance!
Best regards,
mister_jackaba.
