[FieldTrip] Estimating Single-trial Granger Causality
Lisandro Kaunitz
luckyluke1979 at yahoo.com.ar
Mon Dec 16 08:21:17 CET 2013
Hi,
I am trying to compute grangerspectra for simulated single trials. Whenver I run granger causality on a single trial with 2 or more channels I got the following warning:
Warning: Matrix is singular, close to singular or badly scaled. Results may be inaccurate. RCOND = NaN.
> In connectivity/private/sfactorization_wilson at 81
In ft_connectivity_csd2transfer at 180
In ft_connectivityanalysis at 400
In example_maillingList at 51
This warning disappears if I use the same number of trials and channels / signals in my dataset (i.e, 2 trials with 2 channels, 3 trials for 3 channels, etc).
Is it possible to obtain granger spectra for single trials with Fieldtrip? I would like to average the spectra across single trials to run statistics and compare across conditions later on.
This is the code I am using in my simulation, if the value of cfg.ntrials is changed to 2 (both times is is declared), then the warning disappears:
nTrials = 5;
for tr = 1 : nTrials
%% Simulate data
cfg = [];
cfg.ntrials = 1;
cfg.triallength = 2; % in secs
cfg.nsignal = 2;
cfg.fsample = 200;
cfg.method = 'ar';
cfg.bpfilter = 'no'; % (or 'no')
cfg.bpfreq = [0 300]; % (default: [15 25])
cfg.params(:,:,1) = [ 0.8 0 ;
0.9 0.9];
cfg.params(:,:,2) = [-0.5 0;
0.9 -0.8];
cfg.noisecov = [ 0.3 0; 0 0.2];
data = ft_connectivitysimulation(cfg);
%% Non-parametric computation of the cross-spectral density matrix
cfg = [];
cfg.ntrials = 1;
cfg.triallength = 2; % in secs
cfg.nsignal = 2;
cfg.method = 'mtmconvol';
cfg.output = 'fourier';
cfg.taper = 'hanning';
cfg.foi = 2:2:100;
cfg.t_ftimwin = 0.05 .* ones(size(4./cfg.foi', 1), 1);
cfg.toi = 0:0.05:2;
freq = ft_freqanalysis(cfg, data);
%% GRANGER CAUSALITY
cfg = [];
cfg.method = 'granger';
granger = ft_connectivityanalysis(cfg, freq);
sp_chan1_chan2(:,:,tr) = squeeze(granger.grangerspctrm(1,2, :, :)); %#ok
sp_chan2_chan1(:,:,tr) = squeeze(granger.grangerspctrm(2,1, :, :)); %#ok
end
Thanks a lot
Cheers
Lisandro Kaunitz
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20131215/1ef5cd6a/attachment-0001.html>
More information about the fieldtrip
mailing list