<html><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:12pt"><div><span>Hi,</span></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal;"><br></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal;">I am trying to compute granger<span> spectra for simulated single trials. Whenver I run granger causality on a single trial with 2 or more channels I got the following warning:</span></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style:
normal;"><br><span></span></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal;"><span>Warning: Matrix is singular, close to singular or badly scaled. Results may be inaccurate. RCOND = NaN. <br>> In connectivity/private/sfactorization_wilson at 81<br> In ft_connectivity_csd2transfer at 180<br> In ft_connectivityanalysis at 400<br> In example_maillingList at 51 <br></span></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal;"><br><span></span></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal;"><span>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). <br></span></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal;"><br><span></span></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal;"><span>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.</span></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style:
normal;"><br><span></span></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal;"><span>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:</span></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal;"><br><span></span></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal;"><span>nTrials = 5;<br><br>for tr = 1 : nTrials<br> <br> <br> %% Simulate data<br> <br>
cfg = [];<br> cfg.ntrials = 1;<br> cfg.triallength = 2; % in secs<br> cfg.nsignal = 2;<br> cfg.fsample = 200;<br> cfg.method = 'ar';<br> cfg.bpfilter = 'no'; % (or 'no')<br> cfg.bpfreq = [0 300]; % (default: [15 25])<br> <br> cfg.params(:,:,1) = [ 0.8 0 ; <br> 0.9 0.9];<br> <br> cfg.params(:,:,2) = [-0.5 0;
<br> 0.9 -0.8];<br> <br> cfg.noisecov = [ 0.3 0; 0 0.2];<br> <br> data = ft_connectivitysimulation(cfg); <br> <br> %% Non-parametric computation of the cross-spectral density matrix<br> <br> cfg = [];<br> cfg.ntrials = 1;<br> cfg.triallength = 2; % in secs<br>
cfg.nsignal = 2;<br> cfg.method = 'mtmconvol';<br> cfg.output = 'fourier';<br> cfg.taper = 'hanning';<br> cfg.foi = 2:2:100;<br> cfg.t_ftimwin = 0.05 .* ones(size(4./cfg.foi', 1), 1);<br> cfg.toi = 0:0.05:2;<br> <br> freq = ft_freqanalysis(cfg, data);<br> <br> <br> %% GRANGER
CAUSALITY<br> <br> cfg = [];<br> cfg.method = 'granger';<br><br> granger = ft_connectivityanalysis(cfg, freq);<br> <br> sp_chan1_chan2(:,:,tr) = squeeze(granger.grangerspctrm(1,2, :, :)); %#ok<br> sp_chan2_chan1(:,:,tr) = squeeze(granger.grangerspctrm(2,1, :, :)); %#ok<br><br> <br>end<br><br></span></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal;">Thanks a lot<br><span></span></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style:
normal;"><br><span></span></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal;"><span>Cheers<br></span></div><div style="color: rgb(0, 0, 0); font-size: 16px; font-family: HelveticaNeue,Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif; background-color: transparent; font-style: normal;"><br></div><div> </div><div><span style="font-style:italic;">Lisandro Kaunitz<br></span><font size="2"><br></font><br></div></div></body></html>