score matrix in PCA study does not match with the scores shown on bi-plot.

3 views (last 30 days)
I have data matrix X of 9x7 size. (S1-S9 are the observations for seven variables). Ran this code [coeff,score,latent,tsquared,explained,mu] = pca(X) and got the score matrix as below.
score = 9×7
-2.3014 -0.8045 0.2860 -0.3568 -0.0104 0.0193 -0.0193
-0.2822 0.0153 -0.2089 0.0211 -0.2991 -0.1827 0.0328
-0.9933 0.0789 0.2627 0.8664 -0.0145 0.0677 0.0268
-0.1554 0.5001 0.3686 -0.0004 0.4874 -0.0531 -0.0068
-0.7596 0.4617 -0.7863 -0.4201 0.1215 0.0024 0.0142
0.2076 0.4386 -0.1516 -0.0994 -0.2469 0.2026 -0.0149
1.7778 -0.0610 0.7477 -0.4636 -0.0712 0.0212 0.0277
0.7455 0.2118 0.0642 0.2227 -0.1621 -0.1085 -0.0607
1.7610 -0.8409 -0.5823 0.2301 0.1953 0.0311 0.0002
As you can see in the bi-plot, (shown few observation tips), the scores (component1 and component 2) are different that those in the score matrix. Why is this happening?
Also, is there a way I could show S1,S2,...,S9 as I could show M, At, OAA etc. ObsLabels didn't work same as VarLabels.

Answers (1)

Aditya
Aditya on 4 Feb 2025
Hi Manpreet,
When you perform PCA using MATLAB's pca function, the score matrix contains the principal component scores for each observation. These scores are the coordinates of the observations in the new principal component space.
Here's an example of how you can do this :
% Example data matrix X (9x7)
% X = [ ... ]; % Your data matrix
% Perform PCA
[coeff, score, latent, tsquared, explained, mu] = pca(X);
% Create a bi-plot
figure;
biplot(coeff(:,1:2), 'Scores', score(:,1:2), 'VarLabels', {'Var1','Var2','Var3','Var4','Var5','Var6','Var7'});
title('PCA Bi-plot');
% Manually add observation labels
obsLabels = {'S1', 'S2', 'S3', 'S4', 'S5', 'S6', 'S7', 'S8', 'S9'};
for i = 1:length(obsLabels)
text(score(i,1), score(i,2), obsLabels{i}, 'VerticalAlignment', 'bottom', 'HorizontalAlignment', 'right');
end

Categories

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

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!