PCA, svd, compare two groups.

5 views (last 30 days)
sas0701
sas0701 on 26 Feb 2014
Answered: Aditya on 3 Feb 2025 at 4:56
Hi,
I have group 1 with 25x2000 (i.e. 25 variables and 2000 samples)
[u,s,v]=svd(group1) gives me u=25x25, s = 25x2000 and v = 2000 x 2000.I also have 1 princomp that explains most of the variance.
I want to now project group2 (12 x 2000) into the group1 space to see if the 1 princomp from group1 seperates the two groups.
Does this make sense?
Please correct me if there is another way of doing this..
S

Answers (1)

Aditya
Aditya on 3 Feb 2025 at 4:56
Hi Sas,
Yes, your approach makes sense and is a common method for projecting new data onto the principal component space derived from another dataset. You can use Singular Value Decomposition (SVD) results from group1 to project group2 onto the same principal component space. Here’s how you can do it:
1) Perform SVD on group1:
  • You've already done this with [u, s, v] = svd(group1).
  • u contains the left singular vectors (principal directions) for group1.
  • s contains the singular values.
  • v contains the right singular vectors.
2) Identify the Principal Component:
  • Since you mentioned that one principal component explains most of the variance, you will focus on the first column of u (i.e., u(:, 1)).
3) Project group2 onto the Principal Component:
  • To project group2 onto the principal component space of group1, use the first singular vector (u(:, 1)) as the basis for projection.
  • Multiply group2 by the principal component direction to obtain the projection scores.
% Assuming `group1` is 25x2000 and `group2` is 12x2000
[u, s, v] = svd(group1, 'econ'); % 'econ' for economy size decomposition
% Project group2 onto the first principal component of group1
principalComponent1 = u(:, 1); % First principal component direction
group2Projection = group2 * principalComponent1; % Projection scores
4) Analysis:
  • The group2Projection vector contains the projection scores of group2 onto the first principal component of group1.
  • You can compare these scores with the projection scores of group1 to see if the first principal component separates the two groups.
5) Visualization:
  • Plot the projection scores to visualize the separation:
% Project group1 onto its first principal component for comparison
group1Projection = group1 * principalComponent1;
% Plot the projections
figure;
hold on;
histogram(group1Projection, 'FaceColor', 'b', 'DisplayName', 'Group 1');
histogram(group2Projection, 'FaceColor', 'r', 'DisplayName', 'Group 2');
xlabel('Projection Score');
ylabel('Frequency');
title('Projection of Groups onto First Principal Component');
legend show;
hold off;

Categories

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

Tags

Community Treasure Hunt

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

Start Hunting!