Transfering any point in PC space to original space
14 views (last 30 days)
Show older comments
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 Comments
Image Analyst
on 16 Sep 2021
We don't need your trusted data. Can you make up some generic, non-proprietary data and attach that? And we're still not sure what you want. OK, so you have 4 variables and 27 observations. So what do you want to know? Do you just want 6 PC variables? If so, why -- what are you going to do with them? Or do you want to model the data and use the 6 variables to predict some kind of output value?
Accepted Answer
the cyclist
on 16 Sep 2021
rng 'default'
M = 7; % Number of observations
N = 5; % Number of variables observed
% Made-up data
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.
I don't know your application, so I can't help you interpret the implications for you.
3 Comments
the cyclist
on 17 Sep 2021
I'm glad it worked out.
Accepting and upvoting answers is the way to "rate" contributors here. No other rating required. :-)
More Answers (1)
BOMMALA SILPA
on 14 Dec 2021
Hello everyone,
I have a question in PCA.I'm working on EEG, I have taken EEG data applied EEMD, got IMFs then applied PCA on IMFs.
[coeff,score,latent,~,explained] = pca(modos);
dataInPrincipalComponentSpace = modos*coeff;
X_again = dataInPrincipalComponentSpace*inv(coeff)';
for me 2 or 3 PCs are enough to retrive the original data. I have tried with above 2 lines but I'm unable to get it.please suggest me how to do it.
8 Comments
BOMMALA SILPA
on 16 Dec 2021
I think you were not clear with my question
I have an EEG signal,i want to extract the EOG activity in that.
EEMD was performed on the contaminated EEG signal to get the IMFs. We have determined the principal components and arranged them in decreasing order of their respective variation after performing PCA on the IMFs.
only 2 or 3 PCs were sufficient to extract EOG features from the data. This is the thing I have to do.
I have written the code like
load('sc4002e0_recm.mat');
% EEMD
Nstd=0.3*std(X);
NR=100;
MaxIter=10;
[modos its]=eemd(X,Nstd,NR,MaxIter);
for i=1:K
IMF(:,i)=modos(i,:)';
end
%% PCA
[coeff, score, latent, tsquared, explained]=pca(IMF);
then what is the process to extract the EOG from EEG using 2 or 3 PCs. I have tried with this formula also
Re_IMF=score * coeff' + mu;
but I'm not getting the results
See Also
Categories
Find more on EEG/MEG/ECoG in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!