[FieldTrip] multiple subject code

mubeen afzal mubafzal at hotmail.com
Fri Mar 11 10:55:48 CET 2022


Thanks alot Xavier. This worked well and am able to progress.
Can I also query on design matrix as I am having difficulty understanding the concept.
I have got two groups I am comparing 2 second epileptiform discharges - 57 subjects in group A and 99 subjects in group B with grandaverage structures - dimord subj_chan_freq structures
I want to compare their powerspectrum using cluster statistics
How do I design a design matrix.

cfg = [];
cfg.channel          = {'Fp1' 'Fp2' 'F7' 'F3' 'F4' 'F8' 'Fz'};
cfg.latency          = 'all';
cfg.frequency        = [2 50];
cfg.method           = 'montecarlo';
cfg.statistic        = 'ft_statfun_indepsamplesT';
cfg.correctm         = 'cluster';
cfg.clusteralpha     = 0.025;
cfg.clusterstatistic = 'maxsum';
cfg.alpha            = 0.05;
cfg_neighb.method    = 'distance';
cfg.neighbours       = neighbours
cfg.design = [ones(1,57) ones(1,99)*2]
cfg.ivar = 1
[stat] = ft_freqstatistics(cfg, results1, results2)

I am getting some problem in the code as all my stat.prob is ones?  I am having trouble I think with the cfg.design and ivar.
Its two groups their spontaneous abnormal discharges and comparing the powerspectra of their discharges.
Any assistance will be highly appreciated.

Regards,
Mubeen J
________________________________
From: fieldtrip <fieldtrip-bounces at science.ru.nl> on behalf of Xavier Vrijdag via fieldtrip <fieldtrip at science.ru.nl>
Sent: Monday, February 28, 2022 3:31 AM
To: FieldTrip discussion list <fieldtrip at science.ru.nl>
Cc: Xavier Vrijdag <x.vrijdag at auckland.ac.nz>
Subject: Re: [FieldTrip] multiple subject code


Hi Mubeen,



If your code is working fine for each of the data files individually, you can put it in a for loop with an iterator (k) that has the length of the number of data files. You can automatically construct the list of data files with the dir function. In your code you have to change the line where the cfg.dataset is called to point to the datafile of that iteration. Secondly, you have to add a line at the end of your code (in the loop) to save the results from the calculations into a datastruct. After the loop you can call ft_freqgrandaverage to perform the grand average



It will all look like this:

datapath = 'C:\Users\mubaf\OneDrive\Desktop\MY BRAINSTORM\Cases GGE\’;

datasetlist = dir([datapath '*.edf']);



for k=1:size(datasetlist,1)

        cfg =[];

cfg.dataset    = [datapath datasetlist(k).name];



% your code



data_combined{k}=descrip;

end



cfg=[];

cfg.parameter  = ; % enter your parameter

results= ft_freqgrandaverage(cfg,data_combined{:});



It is good habit to call cfg:[]; every time you start configuring the settings for the next step in you analysis as settings of a previous step might influence the next step of your analysis.

To speed up the analysis you might want to consider removing the databrowser step for each iteration to reduce your loop time. Unless you want to see the data in each step.



Happy to help if you have any questions.



Regards,



Xavier



From: fieldtrip <fieldtrip-bounces at science.ru.nl> on behalf of mubeen afzal via fieldtrip <fieldtrip at science.ru.nl>
Reply to: FieldTrip discussion list <fieldtrip at science.ru.nl>
Date: Monday, 28 February 2022 at 9:40 AM
To: "fieldtrip at science.ru.nl" <fieldtrip at science.ru.nl>
Cc: mubeen afzal <mubafzal at hotmail.com>
Subject: [FieldTrip] multiple subject code



Hi I have a silly question,



How does one use a folder of edf files of subjects to repeat the code below so that I can perform a grand average in the end? Or does each file have to be run seperately with seperate codes?



Regards,

Mubeen







cfg            = [];

cfg.dataset    = 'C:\Users\mubaf\OneDrive\Desktop\MY BRAINSTORM\Cases GGE\JJ_05-01-2017.edf';

cfg.channel    = {'EEG Fp1' 'EEG Fp2' 'EEG F7' 'EEG F3' 'EEG Fz' 'EEG F4'...

    'EEG F8' 'EEG T7' 'EEG C3' 'EEG Cz' 'EEG T8' 'EEG P7' 'EEG P3' 'EEG C4'...

    'EEG Pz' 'EEG P4' 'EEG O1' 'EEG O2', 'EEG T3', 'EEG T5', ...

    'EEG T4', 'EEG T6' 'Fp1' 'Fp2' 'F7' 'F3' 'Fz' 'F4' 'F8' 'T7' 'C3'...

    'Cz' 'C4' 'T8' 'P7' 'P3' 'Pz' 'P4' 'O1' 'O2', 'T3', 'T5', 'T4', 'T6'};%'P8'

hdr = ft_read_header(cfg.dataset);

event = ft_read_event(cfg.dataset, 'detectflank', []);



cfg.trialdef.prestim   = 0.5;                   % in seconds

cfg.trialdef.poststim  = 2.5;     % in seconds

cfg.trialdef.eventtype = 'annotation'

cfg.trialdef.eventvalue = 'Ep.sw';

cfg = ft_definetrial(cfg);



datatrials  = ft_preprocessing(cfg);

cfg.continuous              = 'no'

cfg.blocksize  = 10

cfg.channel = 'eeg'

cfg = ft_databrowser(cfg, datatrials)



%power analysis (calls 1 function)

cfg.method = 'mtmfft'

cfg.output ='pow'

cfg.channel  = 'all';

cfg.trials = 'all'

cfg.keeptrials = 'yes' %all trials powerspectrum available if yes in freq.powspctrm

cfg.keeptapers = 'no'

cfg.pad = 'maxperlen'

cfg.polyremoval = 0 %(0 demeans only/1 demeans and detrends/-1 no removal)

cfg.taper = 'hann'

cfg.foilim = [2 50]

freq = ft_freqanalysis(cfg, datatrials);



cfg.variance      = 'yes'

cfg.jackknife     = 'no'

cfg.keeptrials    = 'yes'

cfg.channel       = 'all'

cfg.trials        = 'all'

cfg.frequency     = [2 50]

cfg.latency       = 'all'

[descrip] = ft_freqdescriptives(cfg, freq)




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20220311/eee4ea65/attachment.htm>


More information about the fieldtrip mailing list