[FieldTrip] Time-frequency granger analysis

daniel.strahnen at uni-ulm.de daniel.strahnen at uni-ulm.de
Wed Jul 10 17:47:54 CEST 2019

Dear Jan Mathijs,


Thank you for the helpful advice!


I want to carry on with the statistical analysis, therefore I would be glad if you could briefly answer:


Is it valid to take the spectra I get using the beforementioned code and then take e.g. mean or max values to compare between two cohorts of test subjects?


Thanks and best regards







Von: fieldtrip <fieldtrip-bounces at science.ru.nl> Im Auftrag von Schoffelen, J.M. (Jan Mathijs)
Gesendet: Montag, 8. Juli 2019 10:06
An: FieldTrip discussion list <fieldtrip at science.ru.nl>
Betreff: Re: [FieldTrip] Time-frequency granger analysis


Hi Daniel, 


As with any connectivity metric that needs a cross-spectrum estimate (and specifically for NPSF-based Granger causality estimates), this estimate needs to make sense. In your case, it doesn’t, for several reasons;


1) you only have a single ’trial’ of data, i.e. for every time point the csd is extremely unstable, and will never-ever give meaningful results numerically, even if the rest of the conditions are favorable.

2) in order for the NPSF algorithm to work, the spectral representation needs to be a) smooth, requiring multitapers (+sufficient number of observations) and b) the spectrum needs to be defined from DC to Nyquist.


I recommend you read a bit more in the documentation (and references mentioned) about the underlying algorithmic machinery, and look for some example code in the tutorials/FAQs to get in a more favorable starting position.



1) forget about the ’time-frequency’ aspect, and focus on frequency only.

2) this means that you cut your data into smaller snippets, which are to be used as ovbservations, this can be done with ft_redefinetrial

3) then, use ‘mtmfft’ as method for ft_freqanalysis in combination with an appropriate amount of spectral smoothing (’tapsmofrq’) + ‘fourier’ as output.

4) then, think about what your data represents (in terms of referencing etc.) -> if you want a full multivariate NPSF while the data are rank deficient (e.g. with a common average, or another funky referencing scheme), the result will probably be NaN. In which case you’d need to specify cfg.granger.sfmethod = ‘bivariate’, or ditch one of the channels from your multivariate decomposition.




On 6 Jul 2019, at 16:23, daniel.strahnen at uni-ulm.de <mailto:daniel.strahnen at uni-ulm.de>  wrote:


Dear FieldTrip – Community,


My goal is to analyse changes of Granger Causality over a certain time period.

Here is the code I use to calculate the wavelet analysis:


data.label = {'CH1'; 'CH2'; 'CH3'; 'CH4'; 'CH5'; 'CH6'; 'CH7'};

data.fsample = 1000; % Sampling rate of 1kH

data.time{1} = 1:600000;

data.trial{1} = Output_data'; % Matrix organised as follows: 7 chan x 600000 samples


%% Wavelets for time-frequency power analysis

cfg              = [];

cfg.output       = 'powandcsd';

cfg.method       = 'wavelet';

cfg.foi          = 1:48;     % Frequency range from 1 to 48Hz                     

cfg.t_ftimwin    = ones(length(cfg.foi),1).*0.5;   % length of time window = 0.5 sec

cfg.toi          = 0:600; % 600 seconds (10min) time period

freq_data          = ft_freqanalysis(cfg, data);


Up to this point everything seems to be correct, but the granger analysis only gives my NaNs.


%% Granger causality analysis

cfg_conn = [];

cfg_conn.method = 'granger';

granger_str = ft_connectivityanalysis(cfg_conn, freq_data); 


Does anyone has a suggestion what might be the mistake in my code?


Thank you very much and best regards




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/20190710/8feae453/attachment-0002.html>
-------------- next part --------------
fieldtrip mailing list

More information about the fieldtrip mailing list