[FieldTrip] Computing pca variables (i.e. Latent, and coefficient variables) after ft_componentanalysis
Isac Sehlstedt
isac.sehlstedt at psy.gu.se
Wed Sep 20 09:15:56 CEST 2017
Dear fieldtripers,
This is a follow-up question to a previous question with the same mail-topic.
I have included my code below to show what I am doing (in case I have made errors) and print screens (which are also attached) of the variables I get after the ft_componentanalysis that I get.
Sadly, I cannot see any variable named comp.trial (see Unknown.tiff, or Unknown-1.tiff). Also, when running the PCA in matlab, I get a coefficient array that has as many entries as there are time-points in my trials (see Unknown.tiff-2) . Why am I not getting that in ft? Is it possible to get that using ft?
Very Best,
Isac
----------------- The code -----------------
clear all; close all;
%% Load
load('averages_for_ft.mat')
%% define layout
cfg = [];
cfg.elec=PreOdd_ft{1, 1}.elec;
cfg.rotate=90; %rotation around the z-axis in degrees (default = [], which means automatic)
layout = ft_prepare_layout(cfg)
%% Make the computations
% Dummy varibles
Cond1 = [];
Cond2 = [];
theDiff = [];
theDiff_ft = {};
%% Start loop
for i=1:size(Cond1_ft,2)
%Get the basic condtitions
curr_Cond2 = Cond2_ft{i}.avg;
curr_Cond1 = Cond1_ft{i}.avg;
%Get the basic condtitions
cfg = [];
curr_Cond2_ft = ft_timelockanalysis(cfg, Cond2_ft{i});
curr_Cond1_ft = ft_timelockanalysis(cfg, Cond1_ft{i});
% Then take the difference of the averages using ft_math
cfg = [];
cfg.operation = 'subtract';
cfg.parameter = 'avg';
curr_difference = ft_math(cfg,curr_Cond1_ft,curr_Cond2_ft);
curr_difference_avg = curr_difference.avg;
% Creating a struct with the subjectwise differences between conditions
theDiff_ft{i} = curr_difference
% constructing concatenated averaged sets for the PCA.
Cond2 = [Cond2 curr_Cond2];
Cond1 = [Cond1 curr_Cond1];
theDiff = [theDiff curr_difference_avg];
end
%% Create dummy subjects in order to run the PCA over subjects
dummy_Cond2 = Cond2_ft{1};
dummy_Cond2.avg = Cond2;
dummy_Cond2.time = 1:1:size(Cond2,2);
dummy_Cond1 = Cond1_ft{1};
dummy_Cond1.avg = Cond1;
dummy_Cond1.time = 1:1:size(Cond1,2);
dummy_theDiff = Cond1_ft{1};
dummy_theDiff.avg = theDiff;
dummy_theDiff.time = 1:1:size(theDiff,2);
%% Run the PCA
cfg = [];
cfg.method = 'pca';
cfg.layout = layout;
Cond1_comp = ft_componentanalysis(cfg, dummy_Cond1);
Cond2_comp = ft_componentanalysis(cfg, dummy_Cond2);
theDiff_comp = ft_componentanalysis(cfg, dummy_theDiff);
%% Revert back to subject level
cfgCond2 = [];
cfgCond2.unmixing = Cond2_comp.unmixing;
cfgCond2.topolabel = Cond2_comp.topolabel;
cfgCond1 = [];
cfgCond1.unmixing = Cond1_comp.unmixing;
cfgCond1.topolabel = Cond1_comp.topolabel;
cfgtheDiff = [];
cfgtheDiff.unmixing = theDiff_comp.unmixing;
cfgtheDiff.topolabel = theDiff_comp.topolabel;
for i=1:size(Cond1_ft,2)
Cond1_rs{i} = ft_componentanalysis(cfgCond1, Cond1_ft{i});
Cond2_rs{i} = ft_componentanalysis(cfgCond2, Cond2_ft{i});
theDiff_rs{i}= ft_componentanalysis(cfgtheDiff, theDiff_ft{i} );
end
----------------- The variables/results -----------------
[X]
[X]
[X]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20170920/7f74325b/attachment-0002.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Unknown.tiff
Type: image/tiff
Size: 987824 bytes
Desc: Unknown.tiff
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20170920/7f74325b/attachment-0006.tiff>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Unknown-1.tiff
Type: image/tiff
Size: 1158488 bytes
Desc: Unknown-1.tiff
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20170920/7f74325b/attachment-0007.tiff>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Unknown-2.tiff
Type: image/tiff
Size: 293336 bytes
Desc: Unknown-2.tiff
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20170920/7f74325b/attachment-0008.tiff>
More information about the fieldtrip
mailing list