# Transfering any point in PC space to original space

조회 수: 16(최근 30일)
Tom 2021년 9월 16일
댓글: the cyclist 2021년 9월 17일
Dear experts,
I have a difficult question for you. Basically I have a dataset with 6 variables and 27 cases. I did PCA and plottet it. Afterwards I created a circle around it that includes 95% of the points (the circle is regardless in this case.). I have created 8 new points next (A-D and W-Z) as you can See in the following image. Now I want to do PCA reproduction for these 8 points as I want to know what values the variables have for these points. I would be very glad if you could tell me how I can handle this problem. Thanks in advance.
To make it clear once more. I had 6 variables at first and then seperated 2 PCs, now I have 8 new points and I need to know what values the 6 variables have for them. I hope it´s possible and if it is, I would be very glad if you could tell me how I can handle this problem. Thanks in advance.
edit: I have already found a formular that has to do something with it but to be honest I can´t quite tell what i should do with this formular in my case.
Formular i found:
PCA reconstruction = PC scores * Eigenvectors + Mean
Kind Regards TG
##### 댓글 수: 5표시숨기기 이전 댓글 수: 4
Tom 2021년 9월 17일
Okey I´ll try but I basically think that @the cyclist already almost got it right.
data = table2arry(dataset(:,4:9)); %now I have a 27x6 table with 6 variables and 27 observations
data = data - mean(data);
[coeff, score, ~, ~, explained, mu] = pca(data)
figure; %now i´m plotting my data
hold on;
plot1 = plot(score(:,1), score(:,2),'r.');
set (plot1, 'Markersize', 16);
widthandheight_cosy = 25
set(gca, 'XLim', [-widthandheight_cosy, widthandheight_cosy], 'YLim',[-widthandheight_cosy,widthandheight_cosy], 'Box','on' );
axis square;
%then i plot the circle but that´s not meaningful for this
XtremeW = [radius_circle 0]; %plotting the extreme points
plot(XtremeW(:,1),XtremeW(:,2),'*black');
plot(XtremeY(:,1),XtremeY(:,2),'*black');
plot(XtremeX(:,1),XtremeX(:,2),'*black');
plot(XtremeZ(:,1),XtremeZ(:,2),'*black');
XtremeA = [XandYkoord XandYkoord];
plot(XtremeA(:,1),XtremeA(:,2),'*black');
text(XandYkoord,XandYkoord,' A');
XtremeB = [-XandYkoord XandYkoord];
plot(XtremeB(:,1),XtremeB(:,2),'*black');
text(-XandYkoord,XandYkoord,' B');
XtremeC = [XandYkoord -XandYkoord];
plot(XtremeC(:,1),XtremeC(:,2),'*black');
text(XandYkoord,-XandYkoord,' C');
XtremeD = [-XandYkoord -XandYkoord];
plot(XtremeD(:,1),XtremeD(:,2),'*black');
text(-XandYkoord,-XandYkoord,' D');
So that is basically everything important of my script for this. Now I would like to get values for the original variables 1 to 6 of the table that I loaded in the beginning for all of the 8 new Points XtremeA - XtremeZ. So Basically I want a new table where I have the 8 points as observations and the 6 original variables as variables and I want values for each variable for each of the points. I hope it makes sense now.
I will attach an excel document that looks similar to that one that i used.

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

### 채택된 답변

the cyclist 2021년 9월 16일
Borrowing the first few lines of code from my PCA tutorial ...
rng 'default'
M = 7; % Number of observations
N = 5; % Number of variables observed
X = rand(M,N);
% De-mean (MATLAB will de-mean inside of PCA, but I want the de-meaned values later)
X = X - mean(X); % Use X = bsxfun(@minus,X,mean(X)) if you have an older version of MATLAB
% Do the PCA
[coeff,score,latent,~,explained] = pca(X);
It is noted that there that coeff transforms the data from the original space to the PC space:
dataInPrincipalComponentSpace = X*coeff;
If we have data in the principal component space, we can transform back to the original space like this:
X_again = dataInPrincipalComponentSpace*inv(coeff); % Will be the same as X (within floating point error)
That particular line of code will transform all of the original data points back from PC space to the original coordinates. Each row of dataInPrincipalComponentSpace is the coordinates of one of the original data points.
If you want to transform some other points, then just use those points' coordinates as rows. Here, I'll just choose those coordinates at random:
random_point_in_pc_space = rand(2,N); % Randomly chosen coordinates for two points in the 5-dimensional PC space
random_point_in_orginal_space = random_point_in_pc_space * inv(coeff); % Same random point, in original coordinate system
Instead of random points, you'll want to use the coordinates of your points (A, B, etc).
A wrinkle in your case is that your points are only specified by the first two PC dimensions, PC1 and PC2. So, your W could be
W = [17, 0, 0, 0, 0, 0]; % Coordinates of one possible W
but it could also be
W = [17, 0, 2, -3, 5, -7]; % Coordinates of a different possible W, with the same PC1 and PC2
In fact, an infinite number of points would project from your 6-dimensional space to your point W in PC coordinates, which means there are also an infinite number of data points from the original space that would transform to W.
##### 댓글 수: 3표시숨기기 이전 댓글 수: 2
the cyclist 2021년 9월 17일
Accepting and upvoting answers is the way to "rate" contributors here. No other rating required. :-)

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

R2019b

### Community Treasure Hunt

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

Start Hunting!