The mathematical definition of the PCA problem is to find a linear combination of the original variables with maximum variance.
This means that we are going to create a (new) component. Let’s call it \(z\). This z is going to be computed based on our original variables \((X_1, X_2, …)\) multiplied by a weight for each of our variables \((u_1, u_2, …)\).
This can be written as \(z = Xu\).
[We apply it to cross-section data. For time-series cross-section data, we can use the superPCA package. Not exam material!]
The mathematical goal is to find the values for \(u\) that will maximize the variance of \(z\), with a constraint of unit length on \(u\).
This problem is mathematically called a constrained optimization using Lagrange Multiplier, but in practice, we use computers to do the whole PCA operation at once.
This can also be described as applying matrix decomposition to the correlation matrix of the original variables.
PCA is efficient in finding the components that maximize variance.
This is great if we are interested in reducing the number of variables while keeping a maximum of variance.
Sometimes, however, we are not purely interested in maximizing variance: we might want to give the most useful interpretations to our newly defined dimensions.
And this is not always easiest with the solution found by a PCA.
We can then apply Factor Analysis: an alternative to PCA that has a little bit more flexibility.
PCA only works with numeric data
Categorical data must be encoded as numeric data (e.g. "one-hot encoding" = creating dummies from categories, pd.get_dummies)
Numeric data must be scaled (otherwise your PCA will be misleading)