# How to separate groups using PCA?

I have two groups: A) controls: $25\times2000$, B) patients: $12\times2000$.

Group A has one PC explaining a lot of the variance. (Suggesting a homogenous population?) Group B cannot be explained by the first 2 or 3 (each of the PCs seem to be dominated by single patients).

If I use the group A PC1 as an example of "normal control", is there a way to show how "far" or "close" each of the patients are from this? I.e. How can I establish that some patients are very similar to the controls and some aren't?

I have 25 controls but only 12 patients. Each of them have a spectrogram (time x freq x channels) that is collapsed down to 1 vector.I have tried PCA on just the controls and get a good 1st PC (it's not dominated by any one subject) and looks like the individual data. With patients alone, I do not get this. If I do the PCA on both patients and normals [controls] together, the 1st PC still looks like the normals but it doesn't separate the 2 groups. So it was suggested to me to take the PCA of just normals and then project the patients into this space but how to do that is unclear.

Just want to add - I don't think there are two populations; i.e., controls and patients are not very different (at least on the measure that I am using here). But, some patients are "farther apart" than others from the controls; i.e., some look like normals but others are very far from them.

• Please explain what "$25\times 2000$" means: are these 25 subjects for which you have 2000 attributes or 2000 subjects with 25 attributes? Either way, the mismatch between (A) and (B) requires some explanation up front. Are any variables common to the two datasets? If so, how many? (The rest would appear to be irrelevant.) Did you do the PCA only on the common variables or on all variables in each dataset?
– whuber
Feb 27, 2014 at 21:07
• Hi, I have 25 controls but only 12 patients. Each of them have a spectrogram (time x freq x channels) that is collapsed down to 1 vector.I have tried PCA on just the controls and get a good 1st PC (its not dominated by any one subject) and looks like the individual data. With patients alone, I do not get this. If I do the PCA on both patients and normals together, the 1st PC still looks like the normals but it does'nt seperate the 2 groups. SO it was suggested to me to take the PCA of just normals and then project the patients into this space but how to do that is unclear. Feb 28, 2014 at 2:18
• Hi, Just want to add - I don't think there are two populations i.e. controls and patients are not very different (atleast on the measure that I am using here). BUT some patients are "farther apart" than others from the controls. i.e. some look like normals but others are very far from them. Feb 28, 2014 at 13:34
• Hi, is this called training on the controls and testing the patients? Feb 28, 2014 at 15:24

it was suggested to me to take the PCA of just normals and then project the patients into this space but how to do that is unclear

This is not difficult. Let's say that your control subjects data is combined in one matrix $\mathbf{X}$ with 25 rows and 2000 columns, and your patients' data -- in one matrix $\mathbf{Y}$ with 12 rows and 2000 columns. When you do PCA of your control subjects, you will get up to 24 (number of subjects minus 1) principal axes. Each principle axis is a vector in 2000-dimensional space. If you take the first principal axis $\mathbf{u}$ then you can project your control data onto this axis, obtaining $\mathbf{z_x} = \mathbf{X}\mathbf{u}$. This is the first principal component, it consists of 25 values, one for each subject.

Now if you need to project patients on the same axis, you simply compute $\mathbf{z_y} = \mathbf{Y}\mathbf{u}$. This will be a vector of length 12, the projection you were looking for.

Note that I would rather take two first principal axes and not just one, because then the projection onto this two-dimensional space can be nicely plotted as a scatter-plot. You can plot all your controls as black dots, and all your patients as red dots, this will give you a clear visualization.

• Hi! I think I understand but let me see.. Feb 28, 2014 at 20:43
• In matlab[coeff, score, latent, tsquared, explained, mu] = pca(X'); then coeff = 25x25 Feb 28, 2014 at 20:51
• Sorry -editing cut me off..BUt Coeff(:,1:2) does not multiply with Y. Feb 28, 2014 at 21:02
• sorry if i'm missing something fundamental Feb 28, 2014 at 21:03
• Try pca(X), not X'. Feb 28, 2014 at 21:04