Why is PCA returning only one component when I have 50 variables?

5 views (last 30 days)
I am trying to use PCA in Matlab 2013. I have 50 variables with 52 observations for each. In the example given in documentation there is a component (as I understand each column of coefficients is a component) for each variable. When I do (coeffs, scores)=pca(data) I only get one column of coefficients with 52 rows. Can anyone explain what I am doing wrong please? Thanks!

Answers (1)

Aditya
Aditya on 3 Feb 2025 at 4:48
Hi Kim,
When performing PCA in MATLAB, you should expect the coeff matrix to contain as many columns as there are variables in your dataset. Each column in the coeff matrix represents a principal component, and each row corresponds to a variable. If you're seeing only one column of coefficients, it suggests that something might be off with the input data or the function call.
1) Check Data Dimensions:
  • Ensure your data matrix data is structured correctly. It should be an ( n \times p ) matrix, where ( n ) is the number of observations (52 in your case) and ( p ) is the number of variables (50 in your case).
2) Standardize the Data:
  • Although not strictly necessary for PCA, it's common to standardize the data so that each variable has zero mean and unit variance. This ensures that PCA does not give undue weight to variables with larger scales.
Here is a sample code for the same:
% Example data matrix with 52 observations and 50 variables
% data = rand(52, 50); % Replace with your actual data
% Standardize the data
dataStandardized = (data - mean(data)) ./ std(data);
% Perform PCA
[coeff, score, latent] = pca(dataStandardized);
% Check dimensions of coeff
disp(size(coeff)); % Should output [50, 50]

Categories

Find more on Dimensionality Reduction and Feature Extraction in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!