MATLAB: Problem reconstructing retained principal components

repmat princomp

Hi,
I think I am having an issue reconstructing retained principal components. I have a data set called data, size(40,101). So, I have 40 observations (subjects) and 101 variables (PCs). I would like to reconstruct the signal using all 101 pcs, then only PC1, PC2, and PC3. Here is my code:
[coeff, score, eigval] = princomp(data); subjects = 40;
pc_all = repmat(mean((data),1),subjects,1) + score(:,:)*coeff(:,:)';%all PC
pc1 = repmat(mean((data),1),subjects,1) + score(:,1)*coeff(:,1)';%PC1
pc2 = repmat(mean((data),1),subjects,1) + score(:,2)*coeff(:,2)';%PC2
pc3 = repmat(mean((data),1),subjects,1) + score(:,3)*coeff(:,3)';%PC3
When I take the mean(sd) for each PC, I end up with the same mean for each variable but a different sd.
ensem_pc_all(:,1) = mean(pc_all(1:subjects,:),1);
ensem_pc_all(:,2) = std(pc_all(1:subjects,:),0,1);
ensem_pc1(:,1) = mean(pc1(1:subjects,:),1);
ensem_pc1(:,2) = std(pc1(1:subjects,:),0,1); %…etc
Is there a reason the mean does not change depending on the number of components I retain?
Thanks, Eric

Best Answer

PCA is applied to centered data. Observe that mean(score) is close to a vector of zeros. Rotating the scores back to the original coordinates should also produce vectors with means close to zero. For all pc's defined as they are above, the mean should be fairly close to mean(data).
Related Question