[FieldTrip] Relationship between trial numbers and ft_sourceanalysis

Barnett, Benjy benjy.barnett.20 at ucl.ac.uk
Fri Dec 15 13:24:46 CET 2023


Hey guys,

I have six within-subject conditions, where subjects saw a different visual stimulus for each condition. I am running ft_sourceanalysis with a lcmv beamformer on the conditions separately, using the filters computed over all conditions. When I plot the grand average absolute dipole moments that I compute from ft_sourceanalysis .mom output, I get sensible looking ERFs that ‘ramp up’ at stimulus presentation for each condition.

However, I noticed that when I call ft_sourceanalysis on 5 conditions combined (using the same filters), and compare the resulting ERF to the ERFs for the individual conditions, it has a significantly reduced baseline. I have attached an image of this plot. You can see the outlier ERF at the bottom of the plot. Could someone explain why it is not simply a rough average of the ERFs belonging to the conditions that it itself is computed from?

The only reason I can think of is that there is a greater number of trials going into the source analysis with 5 conditions (roughly 5 times the number), and perhaps that reduces the noise within the source analysis, bringing the dipole moments' baselines closer to 0? If this is correct, how can you meaningfully compare source level ERFs if conditions have a different number of trials? I’m unsure of this, though, as I’m taking the average over all trials prior to calling ft_sourceanalysis(). I attach my code below for your reference.

Thanks,
Benjy


conditions = 0:6;
for subj = 1:length(subjects)

    subject = subjects{subj};

    %Create Forward Model
    disp(subject)
    cfg = [];
    cfg.rawDir =  'D:\Raw';
    cfg.trim = false;
    [headmodel,sourcemodel,grad,~,~,M] = ForwardModel(cfg,subject);


    load(fullfile('D:\trials.mat'));
    cfg = [];
    cfg.channel = 'meg';
    cfg.latency = [0.1 0.45]; %select latency used to compute filters in contrasts
    meg_data = ft_selectdata(cfg,trials);
    meg_data.grad = grad;

    % Compute Covariance Matrix
    cfg = [];
    cfg.covariance = 'yes';
    cfg.channel = 'MEG';
    cfg.covariancewindow = 'all';
    avg = ft_timelockanalysis(cfg,meg_data);

    % Warp the MNI co-orindates of a significant cluster to the subject specific grid.pos.
    gridpos= ft_warp_apply(M,stat.pos(stat.mask,:));
    %figure; ft_plot_headmodel(headmodel,'facealpha',0.01); hold on; ft_plot_mesh(gridpos,'vertexcolor','r','vertexsize',30);


    %Calculate spatial filter for each voxel over all data
    cfg = [];
    cfg.method = 'lcmv';
    cfg.sourcemodel = sourcemodel;
    cfg.sourcemodel.pos = gridpos;
    cfg.sourcemodel.inside = true(size(gridpos,1),1);
    cfg.headmodel = headmodel;
    cfg.unit = sourcemodel.unit;
    cfg.lcmv.fixedori = 'yes';
    cfg.lcmv.keepfilter = 'yes';
    cfg.lcmv.lambda = '1%';
    cfg.channel = {'MEG'};
    cfg.senstype = 'MEG';
    source_idx = ft_sourceanalysis(cfg, avg);


    %Perform source analysis on each condition separately, and also on the combined conditions 1-5.
    for cond = 1:length(conditions)
        Condition = conditions(cond);

        if condition < 6
            %Here we take the precomputed filters and run source analysis on each of the six conditions separately
            cfg = [];
            cfg.channel = 'meg';
            cfg.trials = meg_data.trialinfo(:,5) == cond & meg_data.trialinfo(:,4) == 1;
            datacond = ft_selectdata(cfg,trials);
        elseif condition == 6
            %Here we take 5 conditions all together, so roughly 5x number of trials
            cfg = [];
            cfg.channel = 'meg';
            cfg.trials = meg_data.trialinfo(:,5) > 0 & meg_data.trialinfo(:,4) == 1;
            datacond = ft_selectdata(cfg,trials);
        end


        cfg = [];
        avgcond = ft_timelockanalysis(cfg,datacond);

        %Now apply these filters to the data
        cfg = [];
        cfg.method = 'lcmv';
        cfg.sourcemodel = sourcemodel;
        cfg.sourcemodel.pos = gridpos;
        cfg.sourcemodel.inside = true(size(gridpos,1),1);
        cfg.sourcemodel.filter = source_idx.avg.filter;
        cfg.headmodel = headmodel;

        cfg.senstype = 'meg';
        VCs{subj,cond} = ft_sourceanalysis(cfg, avgcond);

    end

end


%Plot source level ERFs
zero_mom = {VCs{:,1}};
one_mom = {VCs{:,2}};
two_mom = {VCs{:,3}};
three_mom = {VCs{:,4}};
four_mom = {VCs{:,5}};
five_mom = {VCs{:,6}};
notzero_mom = {VCs{:,end}};

grpzero = [];
grpnotzero = [];
grpone = [];
grptwo = [];
grpthree = [];
grpfour = [];
grpfive = [];

for subj = 1:length(zero_mom)
%subject level ERFs by calculating mean absolute dipole moments across voxels
    zero_momsubj = mean(abs(vertcat(zero_mom{subj}.avg.mom{:})));
    one_momsubj = mean(abs(vertcat(one_mom{subj}.avg.mom{:})));
    two_momsubj = mean(abs(vertcat(two_mom{subj}.avg.mom{:})));
    three_momsubj = mean(abs(vertcat(three_mom{subj}.avg.mom{:})));
    four_momsubj = mean(abs(vertcat(four_mom{subj}.avg.mom{:})));
    five_momsubj = mean(abs(vertcat(five_mom{subj}.avg.mom{:})));
    notzero_momsubj = mean(abs(vertcat(notzero_mom{subj}.avg.mom{:})));

    grpzero = [grpzero; zero_momsubj];
    grpone = [grpone; one_momsubj];
    grptwo = [grptwo; two_momsubj];
    grpthree = [grpthree; three_momsubj];
    grpfour = [grpfour; four_momsubj];
    grpfive = [grpfive; five_momsubj];
    grpnotzero = [grpnotzero; notzero_momsubj];
end

%grand average ERFs
meanzero = mean(grpzero,1);
meanone = mean(grpone,1);
meantwo = mean(grptwo,1);
meanthree = mean(grpthree,1);
meanfour = mean(grpfour,1);
meanfive = mean(grpfive,1);
meannotzero = mean(grpnotzero,1);

 figure; plot(zero_mom{1}.time,meanzero,'r'); hold on;
 plot(zero_mom{1}.time,meanone); hold on;
 plot(zero_mom{1}.time,meantwo); hold on;
 plot(zero_mom{1}.time,meanthree); hold on;
 plot(zero_mom{1}.time,meanfour); hold on;
 plot(zero_mom{1}.time,meanfive); hold on;
 plot(zero_mom{1}.time,meannotzero)

legend;

[cid:A71611F8-1548-406B-8BF7-0B4D85398C53 at cust.communityfibre.co.uk]


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20231215/a1ac1585/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PastedGraphic-1.tiff
Type: image/tiff
Size: 160346 bytes
Desc: PastedGraphic-1.tiff
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20231215/a1ac1585/attachment-0001.tiff>


More information about the fieldtrip mailing list