[FieldTrip] Follow up question: Computing pca variables (i.e. Latent, and coefficient variables) after ft_componentanalysis

Isac Sehlstedt isac.sehlstedt at psy.gu.se
Fri Sep 29 12:19:51 CEST 2017


Dear fieldtripers,


This is a kind reminder of 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 (follow dropbox-link below) of the variables I get after the ft_componentanalysis that I get.


Sadly, I cannot see any variable named comp.trial (see ft_componentanalysis-result1.tiff, or ft_componentanalysis-result2.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 matlab_pca_results.tiff) . Why am I not getting that in ft? Is it possible to get that using ft?


Pictures are found using this link:

https://www.dropbox.com/sh/k6ax6bvjb5yi13l/AADvwBzGduIXlCLaPBS4_ELya?dl=0


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20170929/e43ce34e/attachment-0001.html>


More information about the fieldtrip mailing list