Problem reconstructing retained principal components

조회 수: 4 (최근 30일)
Eric
Eric 2013년 8월 14일
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

채택된 답변

Ilya
Ilya 2013년 8월 14일
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).
  댓글 수: 4
Eric
Eric 2013년 8월 14일
The latter is true. It just seems odd that for the entire sample that regardless of how many PCs are retained and compared there is the same ensemble mean for PC3(:) as PC_all(:).
Ilya
Ilya 2013년 8월 14일
Suppose you center your data. Or, to put it differently, move the coordinate origin to the computed center of the dataset. After you do that, the mean of observed values for any variable is zero. Equivalently, if you draw a vector from the new origin to each point in the dataset and add all the vectors, you will get a vector of zeros. The PCA transformation is an orthogonal rotation with respect to the new origin. An orthogonal rotation applied to a zero vector returns a zero vector. The mean of any variable, either in the (centered) space of original variables or in the rotated space, is zero.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Dimensionality Reduction and Feature Extraction에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by