[FieldTrip] Help with ft_freqstatistics

Tzvetan Popov tzvetan.popov at uni-konstanz.de
Thu Mar 24 09:57:07 CET 2022


Dear Zito,

In my reading, the reason for the error is, you provide a power spectra matrices. Yet, ft_freqstatistics expects a data structure that comes out from ft_freqanalysis.
From your code I understand that you aim to perform statistics between subjects (e.d. cfg.design matrix). However, during the call to ft_freqanalysis you specify cfg.keeptrials = ‘yes’. This would allow you to compute statistics within a given subject between the trials corresponding to 2 different conditions.

My suggestion is:
1. Compute power spectra for data1 and data9 with cfg.keeptrials no per subject
2. The resulting freq1 and freq9 per subject can be organised in cell array, e. <http://e.gl/>g. all1{:} and all9{:}.
3. Make a call to ft_freqstatistics : stat = ft_freqstatistics(cfg, all1{:}, all9{:})

If you are interested in a specific frequency band, you can simply specify cfg.frequency = [freglow freqhigh] as you do in your uncommented code.
Good luck,
Tzvetan


> On 24 Mar 2022, at 09:20, Zito Giuseppe Angelo via fieldtrip <fieldtrip at science.ru.nl> wrote:
> 
> Dear Fieldtrip Community,
>  
> I would like to ask a question on ft_freqstatistics.
>  
> I have a design with 20 subjects and 2 conditions, which I imported from EEGlab with the function ft_preprocessing. I the extract the power in the frequency band of interest and I save it using ft_freqanalysis (see link to myData.mat).
> I also created a layout where I modified the standard GSN-HydroCel-129 cap to fit with my own layout, and I computed the neighbours with the function ft_prepare neighbours (see link to myClusters.mat)
>  
> I then tried to run the stats with ft_freqstatistics to study differences in power spectrum between conditions in a within-subject design. However, when running ft_freqstatistics, I receive the following error:
>  
>  
> Error using ft_checkdata (line 538)
> This function requires freq data as input, see ft_datatype_freq.
>  
> Error in ft_freqstatistics (line 91)
>   varargin{i} = ft_checkdata(varargin{i}, 'datatype', 'freq', 'feedback', 'no');
>  
>  
> It seems to be related with the wrong formatting of the input, but the help of ft_checkdata states that the function should accept the data formatted with ft_freqanalysis.
> Here is my code:
>  
> %% Load data into FieldTrip and extract the frequencies
> for i = 1:length(participants)
>     for j = 1:length(conditions)
>        
>         fileName = [folderPath participants{i} '\' participants{i} '_' conditions{j} '.set'];
>        
>         cfg = [];
>         cfg.dataset = fileName;
>         % Load the data from EEGlab to FieldTrip
>         data{i,j} = ft_preprocessing(cfg);
>        
>         % Set parameters
>         cfg.method = 'mtmfft';
>         cfg.output = 'pow';
>         cfg.channel = 'all';
>         cfg.trials = 'all';
>         cfg.keeptrials = 'yes';
>         cfg.pad = 'nextpow2';
>         cfg.foilim = [4 36]; % frequency band of interest
>         cfg.taper = 'dpss';
>         cfg.tapsmofrq  = 2;
>        
>         % Extract the frequencies
>         freq{i,j} = ft_freqanalysis(cfg, data{i,j});
>     end
> end
> freq1 = freq(:,1)';
> freq9 = freq(:,9)';
>  
>  
> %% Run the stats
> clear
> load myData.mat
> load myClusters.mat
> cfg = [];
> % cfg.neighbours = myClusters;
> cfg.channel     = 'all';
> cfg.parameter   = 'powspctrm';
> cfg.method      = 'montecarlo';
> % cfg.frequency   = [4 36];
> %cfg.method = 'analytic';
> cfg.statistic = 'depsamplesT';
> %cfg.statistic = 'ft_statfun_depsamplesFmultivariate';
> cfg.channels = 'all';
> cfg.alpha       = 0.05;
> cfg.tail = 0;
> % cfg.correctm    = 'cluster';
> cfg.correcttail = 'alpha';
> cfg.numrandomization = 'all';
> cfg.ivar                = 2; % the independent variable
> cfg.uvar                = 1;
> nSub = 20;
> cfg.design(1,1:2*nSub)  = [1:nSub 1:nSub];
> cfg.design(2,1:2*nSub)  = [ones(1,nSub) 2*ones(1,nSub)];
>  
> stat = ft_freqstatistics(cfg, freq1,freq9);
>  
> Any idea of where the problem is?
> Please, find here the link to the files:
> https://polybox.ethz.ch/index.php/s/6nTJuNXICnRK1Uc <https://polybox.ethz.ch/index.php/s/6nTJuNXICnRK1Uc>
> https://polybox.ethz.ch/index.php/s/3IA5vhgz6c7X0Bd <https://polybox.ethz.ch/index.php/s/3IA5vhgz6c7X0Bd>
>  
> Thank you very much,
> Giuseppe
> _______________________________________________
> fieldtrip mailing list
> https://mailman.science.ru.nl/mailman/listinfo/fieldtrip <https://mailman.science.ru.nl/mailman/listinfo/fieldtrip>
> https://doi.org/10.1371/journal.pcbi.1002202 <https://doi.org/10.1371/journal.pcbi.1002202>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20220324/a0b3fcd5/attachment.htm>


More information about the fieldtrip mailing list