Data
View settings
Variance per variable
Scree plot
Score plot
Loadings
Reconstruction error
Method
Given a data matrix X with n observations (rows) and p variables (columns), each column is centered by subtracting its mean. With standardizing on, each column is also divided by its standard deviation, which turns the covariance analysis into a correlation analysis (useful when variables have different units or scales).
Principal component analysis seeks orthogonal directions of maximum variance. They are the eigenvectors of the sample covariance matrix C = XcTXc / (n - 1), a p × p symmetric matrix. Here it is eigendecomposed by a cyclic Jacobi rotation. The eigenvalues λj are the variances captured by each component (sorted descending), the eigenvectors V are the loadings, and the scores are the projections T = Xc V.
The fraction of variance explained by component j is λj / Σ λ. Keeping the first k components and reconstructing, X̂ = T:,1..k V:,1..kT, gives the best rank-k approximation in the least-squares sense. By the Eckart-Young theorem the relative Frobenius error is exactly √(Σj > k λj / Σ λ), which the app plots alongside the empirically reconstructed error.
Related publications
- Jolliffe, I.T.; Cadima, J. (2016). Principal Component Analysis: A Review and Recent Developments. Philosophical Transactions of the Royal Society A, 374, 20150202. doi:10.1098/rsta.2015.0202
- Talebi-Kalaleh, M.; Mei, Q. (2024). Damage Detection in Bridge Structures through Compressed Sensing of Crowdsourced Smartphone Data. Structural Control and Health Monitoring, 2024, 5436675. doi:10.1155/2024/5436675
- Talebi-Kalaleh, M. (2025). Sensing Techniques and Time Series Analysis in Python (v0.1). mtalebi.github.io/SHM-Live-Book