Statistics Saga 2: Dimensionality Reduction
Published: 2022-08-29 13:00:37

---
title: Statistics Saga 2: Dimensionality Reduction
published: true
date: 2022-08-29 07:26:00 UTC
tags: 
canonical_url: https://dataroots.io/research/contributions/statistics-saga-1-matrix-factorization-and-dimensionality-reduction
---

Welcome back! If you remember from [last time](https://dataroots.io/research/contributions/statistics-saga-1-matrix-factorization) I told you we would continue with matrix factorisations, more specifically dive into some dimensionality reduction techniques! Hope you're ready!

This blogpost will give you a comparison of two specific factorisation techniques that are foundational to the idea of dimensionality reduction: principal component analysis and factor analysis.

Some of the techniques are also given some context with examples from a recent psychology study. Which is a bit more fun than the billionth iris flower dataset example. At least we think so!

## Dimensionality reduction

Dimensionality reduction, the term leaves very little to the imagination: techniques that can reduce the dimensionality of data. Why is this useful? We live in a 3 dimensional world, higher dimensional relationships are very difficult for us to reason about. The relationship between the height and weight of a person is not too difficult to think about, it only uses 2 dimensions. Include age into this relationship and we start to struggle a whole lot more. Similarly, computers can also struggle with high dimensional data: calculations and models become a lot less efficient.

💡

**psychology example**  
Within the field of psychology dimensionality reduction is often used when dealing with multivariate data. Usually this is done to infer or measure latent/unobservable traits. As an example: psychologists have long attempted to characterise what an emotion is. One of the first ideas, and it has stuck around, is that at the very least an emotion should have two properties: valence and arousal. The valence of an emotion is how pleasant or unpleasant it is. You can think of it on a spectrum of the happiest a person could ever be to the saddest a person could ever be. The second property, arousal, is perhaps a bit less straightforward. You can think of it as how much an emotion activates you. If you’re extremely angry or happy you’re in a high arousal state, while boredom or feeling at ease would be a low arousal state. An intuitive next step might then be to conceive of any emotion as a combination of some arousal and valence on a 2D-plane.  
  
stop for a moment and think about how you are feeling right now.  
Happy 1 - 2 - 3 - 4 - 5  
Sad 1 - 2 - 3 - 4 - 5  
Bored 1 - 2 - 3 - 4 - 5  
Miserable 1 - 2 - 3 - 4 - 5  
  
The amount of emotions a person would have to rate could vary, but is usually at least 10 items. A matrix factorization model is then applied to the gathered data. Reducing the dimensionality of the data to only 2 dimensions would reflect the underlying levels of valence and arousal.

For this reason dimensionality reduction is used in machine learning to combine a set of variables into a smaller set and use this smaller set as features for a model. This can be beneficial when dealing with a huge amount of features because it reduces the space in which the model has to find solutions.  However, there are downsides to doing this. Firstly, you are throwing away information. While ideally only statistical noise is discarded, these techniques all make some assumptions about the structure of the data. If these assumptions do not hold useful information might get excluded from the model. Secondly, when combining multiple features into one, model explainability is negatively impacted. It is much harder to interpret a regression coefficient for a feature that is combination of 10 other features than it is to individually compare those coefficients. That is to say, one should carefully consider the up- and downsides when applying dimensionality reduction. Thoroughly research the algorithm or model you wish to use, taking into account the specific question or problem you wish to address.

Having introduced and explored the basic ideas behind dimensionality reduction we’ll next compare and contrast two different techniques, Principal Component Analysis (PCA) and Factor Analysis (FA). PCA is a very popular technique used in both machine learning and statistics. FA is a less popular technique that has its origins in psychology/psychometrics. Why FA then? The techniques are very similar, as we shall see, and serves to illustrate how small changes in a model can make it more or less appropriate given a specific task. Also, the author of this blog is a psychometrician who has no qualms with picking their favourite child.

## PCA and FA

Let’s first look at how an FA is defined so that we may compare it to PCA and understand the differences. Factor analysis as a model of our data can be specified as:

$$ X = \Xi \Lambda' + \Delta, $$

where \( X \) is our observed data, with \( n \) observations and \( p \) variables. \( \Xi \) is a matrix of factors with dimensions \( n \) and \( m \) where \( m \) **≤** \( p \). \( \Lambda' \) is a \( m \) **x** \( p \) matrix of factor loadings or weights. Lastly \( \Delta \) is an \( n \) **×** \( p \) matrix of error terms.

Now, let’s refresh our memory on PCA, which is usually defined as follows:

$$ X = Z\_s D^{1/2}U'. $$

\( X \) is again our observed data, \( Z\_s \) the standardized principal components, \( D^{1/2} \) a diagonal matrix of the standard deviations of the principal components, and \( U' \)the matrix of eigenvectors. What we are doing here is a singular value decomposition of the observed data matrix.

If we apply these techniques to a covariance matrix, the difference becomes clearer. Let’s call this covariance matrix,

$$ R = \frac{1}{(n-1)}X'X $$

which we’ve calculated using some of the emotion data mentioned in the previous example [1].

![](https://dataroots.ghost.io/content/images/2022/01/000005.png)
_Covariance matrix from a study on human emotion_

If we now plug in the formulas for PCA and EFA in the place of X, we get the following results.

<!--kg-card-begin: markdown-->

| PCA | FA |
| --- | --- |
| $$ R = \frac{1}{(n-1)}(Z\_sD^{1/2}U')'(Z\_sD^{1/2}U') \\ = (UD^{1/2})(UD^{1/2})' \\ =FF' \\ \approx F\_cF'\_c $$ | $$ R = \frac{1}{(n-1)}(\Xi\Lambda'\_m + \Delta)' (\Xi\Lambda'\_m + \Delta) \\ =\Lambda\Lambda' + \Psi \\ \approx \Lambda\_c\Lambda'\_c + \Psi $$ |

<!--kg-card-end: markdown-->

Ignoring differences in notation \( F \) and \( \Lambda \) are functionally the same - there is quite some similarity. The subscript \( c \) serves to indicate that we reconstruct the covariance matrix using a lower rank approximation, using only the first \( c \) components or factors to reconstruct the covariance matrix. For the FA model, the added parameter \( \Psi \) serves to improve estimates of item-specific variances over what is possible in PCA. This explains why FA is said to reconstruct the shared variance (covariance), while PCA is said to explain the total variance.

### Why is this a big deal?

Using the Eckart-Young theorem we can prove that PCA optimally reconstructs the totality of the covariance matrix. As an example, Iet's again look at the covariance matrix of the emotion items used before. I ran both PCA and FA, specifying a 2 component/factor solution. We can then reconstruct a lower rank matrix \( R\_{rec} \) and subtract this new matrix from \( R \) to get a matrix of residuals, \( R\_{res} \) :

$$ R\_{res} = R - R\_{rec}. $$

Taking the Frobenius norm \( \| R\_{res} \|\_F \), we get a good idea of how well the observed covariance matrix was reconstructed:

<!--kg-card-begin: markdown-->

| PCA | FA |
| --- | --- |
| $$ | R\_{res} |\_F^{PCA} = 2.3205 $$ | $$ | R\_{res} |\_F^{FA} = 3.5561 $$ |

<!--kg-card-end: markdown-->

Indeed, we see that PCA offers a better rank \( 2 \) approximation of the covariance matrix. So why would we even bother with techniques that offer poorer performance?

Recall that for FA we are really only interested in the covariances. Rather than reproducing the whole covariance matrix, we care more about reproducing the off-diagonal elements of the covariance matrix. For this reconstruction, PCA is not necessarily the most optimal procedure. If we set all diagonal entries of \( R\_{res} \)  to zero and take the Frobenius norm of the resulting matrix, we get an estimate of the reproduction error for the off-diagonal elements. While PCA might optimally reconstruct the total covariance matrix, FA is better at estimating the off-diagonal elements of the covariance matrix.

<!--kg-card-begin: markdown-->

| PCA | FA |
| --- | --- |
| $$ | R\_{off} |\_F^{PCA} = 6.5712 $$ | $$ | R\_{off} |\_F^{FA} = 5.9352 $$ |

<!--kg-card-end: markdown-->

Of course, all statistical procedures or models make some assumptions. Let's discuss what should be kept in mind when using PCA or factor analysis.

## Assumptions

All observations should be complete, and significant outliers might bias the results. This is because both techniques, on some level, assume multivariate normality of the data. Let's go over some of the more substantial assumptions.

Both techniques also assume that the variables are correlated to at least some degree. If all variables were independent from one another we would not reach identifiable solutions for either PCA or FA. Since correlation is a linear measure of association, if the variables are only associated in nonlinear ways, the output of both models will be biased. Of course, both models are sufficiently robust against small deviations, especially when the variables are still monotonically associated. Solutions to deal with nonlinearity exist for both PCA and FA, but this is outside the scope of this blog.

Finally, a crucial difference between PCA and FA is that because PCA attempts to model the variance in the data, it is highly susceptible to differences in that variance. More concretely, if one variable has a variance of 1000, and the other variables only have a variance of 10, most of the variance lies in the first variable. As a result, the principal components will be dominated by the first variable. For this reason, it is always best to work with standardised variables. While this is not strictly necessary when doing factor analysis because it is scale invariant.

## When and how do I use PCA or FA?

Say you want to apply either technique to help solve some problem you are having, which technique is appropriate?

### PCA

PCA can be used as a dimensionality reduction technique assuming the assumptions discussed earlier are not violated. One important consideration is how many principal components to maintain. As a general rule, only components with an eigenvalue greater than one should be retained. This is because components with smaller eigenvalues don't explain additional variance over what could be explained using just one of the original features. This rule should generally give a very good indication of how many components to use. Should it be necessary, more numeric techniques like Horn's procedure exist that account for sampling variance in the eigenvalues.

Once the PCA has been fit, the components can be used as input to another model. This can be any kind of model: regression, classification, or even another unsupervised learning algorithm like cluster analysis.

### FA

Factor analysis was developed to analyse data from questionnaires and to estimate the latent variables _causing_ them. This was usually done to gain some more theoretical understanding of concepts being studied. As an example, psychologists has identified 5 dimensions of personality that can be consistently found across people of all ages and backgrounds. These dimensions were first identified using factor analysis. For these reasons, perhaps the most straightforward use of factor analysis within a business would be to analyse questionnaire data that has some latent structure, for example customer or employee satisfaction. With FA, questions that don't contribute much information can be identified and changed, or left out entirely.

To determine how many factors are to be extracted, the same methods used in PCA can be applied. However, in contrast to PCA the factor solution changes depending on how many factors were calculated by the model. More concretely, when calculating a 3 factor solution, the first 2 factors of that solution are not identical to the 2 factors of a 2 factor solution. As such, once it has been decided how many factors to use, it is best to recalculate the model and specifying exactly how many factors to retain.

To summarise, FA can be used to check whether a valid latent structure can be found, and whether or not the questions were interpreted similarly across different groups of people. Additionally, factor scores can be calculated and used as input to a machine learning model just like PCA. But, because FA is a more complex model (recall the extra parameter \( \Psi \) ), it should be preferred over PCA when the variables or features were measured with any degree of measurement error. A great illustration of this is given on the [scikit-learn documentation for factor analysis](https://scikit-learn.org/stable/auto_examples/decomposition/plot_pca_vs_fa_model_selection.html#sphx-glr-auto-examples-decomposition-plot-pca-vs-fa-model-selection-py).

However, a downside to FA is that because of this added complexity a solution isn't guaranteed to be found. This is both a blessing and a curse though, because when a solution cannot be found this usually means the model is very badly specified. At that point, you should turn back to the drawing board and rethink your model.

## Conclusion

This blog introduced you to PCA and factor analysis by showing how similar the models are, but also highlighting crucial differences. Factor analysis and PCA have a lot in common, and are both a great first attempt at dimensionality reduction. As with all techniques, it is important to keep in mind which assumptions are made, and to choose the right tool for the job.

Keep posted for our next blog in the statistics saga, the _interval_ between this blog and the next shouldn't be too large!

## Acknowledgements

Thanks to Michelle Yik for allowing us to use the data from the valence/arousal study to serve as an example!

## References

1. Yik, M., Mues, C., Sze, I. N. L., Kuppens, P., Tuerlinckx, F., De Roover, K., Kwok, F. H. C., Schwartz, S. H., … Russell, J. A. (in press). On the relationship between valence and arousal in samples across the globe_. Emotion._

## You might also like

[

Trends in statistical visualisation - Lode Nachtergaele

Machine learning engineers are at the intersection of programming (computerscience), math/statistics/machine learning and domain knowledge/communication.Although a lot of progress has been made in the first two, their advances areconstrained by the ability to convey their results to the business…

 ![](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsSAAALEgHS3X78AAAAB3RJTUUH5QMTDQUuJijI6QAAAAFvck5UAc+id5oAAANWSURBVFjD7dZZiJVlGAfw33GGaWJomMzItEXbbHGGZoyiRW0RLxLypgutbiuIFiJbQCKKiGihneqiBW+CoGIIuqgkEJexxZRogbLQjJrKaLFi1Jm6eN7Pec93vnOcAaOb+cOB873b83+2//syhf8ZtUNyyuCDreeX3/UfEqg3PhPz8AWGJ0KmOYGyV1Ve1K+Zg2dwCbZjPdbiA+zCaBWZagITCWn9mjPwLBaXVu7HTryPd7ERX2OkOYHxg9txBcaSF9+n/2UM4Hmc05q1f0RaPsLd+LgwUuV1B25NCzsS66HkxRB2YB8WJs/PKnm9Bz0lAjVRI8uwqSBQqzB+OFbj9mQ8xxi+SxH5FCtxSjY/gocxiPNxGRZgFqZl617DCuyvlYx3437cgDaTw5+4F4+n6BSRPBFLcB9mpPHPcCmGc1Yz8ARuLBnfKfLfCr9gFR7NjMNefIkXsC0bPw5zGa+BWcn4laWD38MtIq8XpZCei+Pl9cOTeO7AV96yEeG92Jr2F5Huw1B7YvI0Li8ZfxM3iYKDz/EiZqfxVdnawyqN12OLqKEi6gPSx9kZM2nRK7guM15gNKXkDVHpBRag8yBp+iSlqkAvetqTZ8M4IU3sEu33Q4uQfiO6YV4aPQ3HNBCuL/A2hQAFTsKcdnyLrzIC3ThKyGmzkP4s9L4gMBMnY0cTFe0VaZ6djfVg7jTRPttKE32VQRw/fB8+zGY6cS0WYXpp13lYgwuzsTFRT+uKgtgipLLAQIPRRqU8umRoBd7CO0ILlgkpf1nUWU7+EdyB3YUQ9QuZLdhvxNIUnTK6cI9ozw7NMSLatysb+xsPCLUcgTYrlxB9uhzHZmmYnkK1JyPSg4dEG+Y6MKpeaqX5nOAfQuIfk4lVccivQtv70/cRycPrRYFuwLoU1qtKhtaLd8B88RY4U+NFtDuF/CVFqlNxFwTGxDV5TWljZzp4viiyspdvi3tje/ruFm+DRULrB1J0b8OrB3ZlnZWHcVC0yWKcnqKQo2z8ddws9KDA79icfk/hVNH/W6uMU30dH5k8vjj9+ozfYgXWCCn+qeHgVq+pCk2pHWRTV/JioZDrfnFHrMZvrQ6eKBqfZHdezQW9VWs7xK35I/46FMarCZQxyZBOYQqTxb9fddW1INHowAAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAyMS0wMy0xOVQxMzowNTo0NiswMDowMMNJPDoAAAAldEVYdGRhdGU6bW9kaWZ5ADIwMjEtMDMtMTlUMTM6MDU6NDYrMDA6MDCyFISGAAAAAElFTkSuQmCC)dataroots

 ![](https://dataroots.io/static/9b23bc59d714e405d8ccb046f824bff2/f3583/visualization--8--1.png)
](https://dataroots.io/research/contributions/trends-in-statistical-visualisation)

[

Statistics Saga 1: Matrix Factorization - Chiel Mues

This blogpost will give you a gentle (re)introduction to the idea of matrixfactorization, an enormously useful technique in statistics and machinelearning. Matrix FactorizationMatrix factorization is a technique to decompose or factorize a matrix into aproduct of more fundamental matrices. If t…

 ![](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsSAAALEgHS3X78AAAAB3RJTUUH5QMTDQUuJijI6QAAAAFvck5UAc+id5oAAANWSURBVFjD7dZZiJVlGAfw33GGaWJomMzItEXbbHGGZoyiRW0RLxLypgutbiuIFiJbQCKKiGihneqiBW+CoGIIuqgkEJexxZRogbLQjJrKaLFi1Jm6eN7Pec93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y0xOVQxMzowNTo0NiswMDowMMNJPDoAAAAldEVYdGRhdGU6bW9kaWZ5ADIwMjEtMDMtMTlUMTM6MDU6NDYrMDA6MDCyFISGAAAAAElFTkSuQmCC)dataroots

 ![](https://dataroots.io/static/1df996a24b79d8a0e9a6d66808fec204/f3583/Screenshot-2022-04-19-at-14.51.15.png)
](https://dataroots.io/research/contributions/statistics-saga-1-matrix-factorization)