[FieldTrip] Error using indepsamplesZcoh function for calculating coherence differences

Raghavan Gopalakrishnan gopalar.ccf at gmail.com
Tue Aug 31 05:27:42 CEST 2021


Hi Jan-Mathijs,
I would like to follow up on the below message exchange between you and Bushra regarding using indepsamplesZcoh.
Your suggestions works well for method ‘mtmfft’ when computing frequency. However when using ‘mtmconvol’ to get time-freq representation of coherence, the code ends up with an error. Please see below.
There seems to be an issue in line 210 Clusterstat.m that it is unable to reshape the statistics to original dimension. cfg.origdim option doesn’t seem to work.
Any help us much appreciated.

% computing Frequency
cfgf                 = [];
cfgf.output          = 'fourier';
cfgf.method          = 'mtmconvol';
cfgf.foi             = 5:1:40;
cfgf.t_ftimwin       =  3 ./ cfgf.foi; %length of the sliding time window in seconds
cfgf.toi             = 0:0.01:1;
cfgf.trials     = find(data_preproc.trialinfo(:,1)==284);
cfgf.taper      = 'hanning';
freq1 = ft_freqanalysis(cfgf, data_preproc);
cfgf.trials     = find(data_preproc.trialinfo(:,1)==280);
freq2 = ft_freqanalysis(cfgf, data_preproc);
cfga=[];
cfga.appenddim='rpt';
comb_freq = ft_appendfreq(cfga,freq1,freq2);

%Permutation

cfg = [];
cfg.method            = 'montecarlo';           % use the Monte Carlo Method to calculate the significance probability
cfg.statistic         = 'indepsamplesZcoh';        % use the independent samples T-statistic as a measure to evaluate the effect at the sample level
cfg.correctm          = 'cluster';
cfg.clusteralpha      = 0.05;                   % alpha level of the sample-specific test statistic that will be used for thresholding
cfg.clustertail       = 0;
cfg.clusterstatistic  = 'maxsum';               % test statistic that will be evaluated under the permutation distribution.
cfg.tail              = 0;                      % -1, 1 or 0 (default = 0); one-sided or two-sided test
cfg.correcttail       = 'prob';                 % the two-sided test implies that we do non-parametric two tests
cfg.alpha             = 0.05;                   % alpha level of the permutation test
cfg.numrandomization  = 50;                   % number of draws from the permutation distribution
cfg.design            = [comb_freq.trialinfo(:,1)']; % design matrix, note the transpose
cfg.ivar              = 1;                      % the index of the independent variable in the design matrix
cfg.neighbours        = [];                     % there are no spatial neighbours, only in time and frequency
cfg.channel           = {‘FC1’ 'mean*'};
cfg.parameter = 'fourierspctrm';
cfg.clustercritval = 0.05;
cfg.origdim = [1 numel(comb_freq.freq)];
cfg.connectivity = false;
cfg.design=[];
trlblk=unique(comb_freq.trialinfo(:,1)); %trlblk=trlblk(logical(trlblk>10));
cfg.design(comb_freq.trialinfo(:,1)== trlblk(1)) = 1; % OFF condition
cfg.design(comb_freq.trialinfo(:,1)==trlblk(2)) = 2; % ON condition
stat = ft_freqstatistics(cfg, comb_freq);


Error using reshape
Number of elements must not change. Use [] as one of the
size inputs to automatically calculate the appropriate
size for that dimension.

Error in clusterstat (line 210)
        tmp = reshape(postailobs, [cfg.dim 1]);

Error in ft_statistics_montecarlo (line 364)
  [stat, cfg] = clusterstat(cfg, statrand, statobs);

Error in ft_freqstatistics (line 194)
  [stat, cfg] = statmethod(cfg, dat, design);

Error in Priming_task_permutation (line 68)
stat = ft_freqstatistics(cfg, comb_freq);



Schoffelen, J.M. (Jan Mathijs) jan.schoffelen at donders.ru.nl<mailto:fieldtrip%40science.ru.nl?Subject=Re%3A%20%5BFieldTrip%5D%20Error%20using%20indepsamplesZcoh%20function%20for%0A%20calculating%20coherence%20differences&In-Reply-To=%3CA525165A-72A2-4EBE-98A4-A709C95B137A%40donders.ru.nl%3E>
Tue May 18 16:21:58 CEST 2021

  *   Previous message (by thread): [FieldTrip] Error using indepsamplesZcoh function for calculating coherence differences<https://mailman.science.ru.nl/pipermail/fieldtrip/2021-May/040872.html>
  *   Next message (by thread): [FieldTrip] Scaling of Laplacian transformed ERPs<https://mailman.science.ru.nl/pipermail/fieldtrip/2021-May/040864.html>
  *   Messages sorted by: [ date ]<https://mailman.science.ru.nl/pipermail/fieldtrip/2021-May/date.html#40873> [ thread ]<https://mailman.science.ru.nl/pipermail/fieldtrip/2021-May/thread.html#40873> [ subject ]<https://mailman.science.ru.nl/pipermail/fieldtrip/2021-May/subject.html#40873> [ author ]<https://mailman.science.ru.nl/pipermail/fieldtrip/2021-May/author.html#40873>

________________________________

Hi Bushra,



Thank you for your reply. I am stuck with this for couple of days now.



Welcome to science.



 >Can you please specify the cfg to ft_freqstatistics as well? Otherwise, we don’t know what you did exactly.

cfg            = [];

cfg.method = 'montecarlo';

cfg.statistic = 'indepsamplesZcoh';

cfg.design(1,1:148)=1;

cfg.design(1,149:296)=2;

cfg.numrandomization = 1000;

cfg.correctm         = 'cluster';

cfg.neighbours=[];

cfg.parameter='crsspctrm';

cfg.alpha            = 0.05;

cfg.clusteralpha     = 0.05;

stat=ft_freqstatistics(cfg,freq_coh);



Sorry I didnt follow this point. I am calling freqstatistics with above cfg parameters



To reiterate, you need to use cfg.parameter = ‘fourierspctrm’, and (cfg.output = ‘fourier’ when calling ft_freqanalysis). The low-level ft_statfun_indepsamplesZcoh assumes that the input data are fourier coefficients.



Next, as a disclaimer: I think that indepsamplesZcoh has hardly been used recently, so it could very well be that it’s functional behavior has not been kept up-to-date with the state of the rest of the toolbox.



>Also, ft_freqstatistics with cfg.statistic = ’indepsamplesZcoh’ requires frequency data that has been computed with >‘fourier’ rather than ‘powandcsd’ as cfg.method for ft_freqanalysis



when freq_coh is calculated with fourier method, then above code give following error



Error using ft_freqstatistics (line 177)

the length of the design matrix (1) does not match the number of observations in the data (2072)



It seems as if the dimord for fourier data is not read correctly, rpttap_chan_freq is getting confused with rpt_chan_freq as 2072 are rpttap , number of repetitions are only 296



If you use multitaper spectral analysis, each ’trial’ (aka rpt) gets more than one taper assigned, in your case about 7. These are the number of columns in your data matrix, so that needs to be reflected in the design. Therefore, the design have 2072 columns. In addition, for the randomization to be done correctly, you need to specify in the design, which columns belong to the same trial. So you need to define a second column consisting of [1 1 … 1 2 2 .. 2 …296] coding the individual trials. Then you need to appropriately set the cfg.ivar=1, and cfg.wvar=2 -> please consult the documentation on the fieldtrip website for this.

In addition you may need to specify cfg.origdim = [1 numel(freq_coh.freq)], and cfg.connectivity = false; before calling ft_freqstatistics.



Moreover, you may need to comment out lines 127 and 150 in ft_statfun_indepsamplesZcoh.m



I hope that this will help you on your way, to get it resolved for you. Perhaps you could filie a Pull Request on our github repository with the required change to ft_statfun_indepsamplesZcoh. Also it would be superhelpful for the rest of the community, if your experiences will be solidified in an example script that can be hosted on: https://www.fieldtriptoolbox.org/example/



Best wishes,

Jan-Mathijs









The error can be reproduced by running following script

https://www.dropbox.com/s/7bupsr8gkdmy28c/testcode.m?dl=0<https://urldefense.com/v3/__https://www.dropbox.com/s/7bupsr8gkdmy28c/testcode.m?dl=0__;!!HJOPV4FYYWzcc1jazlU!og3YlDTnQJXpbwiNKFrIAwklgaHzW9Gkdlv-WeCI05whozlcD9pwXXXbKggQyxNDb85XDPxE$<https://www.dropbox.com/s/7bupsr8gkdmy28c/testcode.m?dl=0%3Chttps://urldefense.com/v3/__https://www.dropbox.com/s/7bupsr8gkdmy28c/testcode.m?dl=0__;!!HJOPV4FYYWzcc1jazlU!og3YlDTnQJXpbwiNKFrIAwklgaHzW9Gkdlv-WeCI05whozlcD9pwXXXbKggQyxNDb85XDPxE$>>

with this data

https://www.dropbox.com/s/6gfj97srttteawy/Coh_data.mat?dl=0<https://urldefense.com/v3/__https://www.dropbox.com/s/6gfj97srttteawy/Coh_data.mat?dl=0__;!!HJOPV4FYYWzcc1jazlU!og3YlDTnQJXpbwiNKFrIAwklgaHzW9Gkdlv-WeCI05whozlcD9pwXXXbKggQyxNDb1di9xyl$<https://www.dropbox.com/s/6gfj97srttteawy/Coh_data.mat?dl=0%3Chttps://urldefense.com/v3/__https://www.dropbox.com/s/6gfj97srttteawy/Coh_data.mat?dl=0__;!!HJOPV4FYYWzcc1jazlU!og3YlDTnQJXpbwiNKFrIAwklgaHzW9Gkdlv-WeCI05whozlcD9pwXXXbKggQyxNDb1di9xyl$>>



Thank you

Kind regards

Bushra Riaz

________________________________

From: fieldtrip <fieldtrip-bounces at science.ru.nl<https://mailman.science.ru.nl/mailman/listinfo/fieldtrip><mailto:fieldtrip-bounces at science.ru.nl<https://mailman.science.ru.nl/mailman/listinfo/fieldtrip>>> on behalf of Schoffelen, J.M. (Jan Mathijs) <jan.schoffelen at donders.ru.nl<https://mailman.science.ru.nl/mailman/listinfo/fieldtrip><mailto:jan.schoffelen at donders.ru.nl<https://mailman.science.ru.nl/mailman/listinfo/fieldtrip>>>

Sent: 18 May 2021 14:05

To: FieldTrip discussion list <fieldtrip at science.ru.nl<https://mailman.science.ru.nl/mailman/listinfo/fieldtrip><mailto:fieldtrip at science.ru.nl<https://mailman.science.ru.nl/mailman/listinfo/fieldtrip>>>

Subject: Re: [FieldTrip] Error using indepsamplesZcoh function for calculating coherence differences



Hi Bushra,



Can you please specify the cfg to ft_freqstatistics as well? Otherwise, we don’t know what you did exactly.



Also, ft_freqstatistics with cfg.statistic = ’indepsamplesZcoh’ requires frequency data that has been computed with ‘fourier’ rather than ‘powandcsd’ as cfg.method for ft_freqanalysis



Best wishes,

Jan_Mathijs





On 14 May 2021, at 13:36, Bushra Riaz Syeda <bushra.riaz at gu.se<https://mailman.science.ru.nl/mailman/listinfo/fieldtrip><mailto:bushra.riaz at gu.se<https://mailman.science.ru.nl/mailman/listinfo/fieldtrip>>> wrote:



Hello,

I am trying to do the analysis based on the paper "nonparametric statistical testing of coherence differences" in fieldtrip for comparing differences between two conditions on single subject level.



I am using the following code



cfg            = [];

cfg.method = 'montecarlo';

cfg.statistic = 'indepsamplesZcoh';

cfg.design(1,1:148)=1;

cfg.design(1,149:296)=2;

cfg.numrandomization = 1000;

cfg.correctm         = 'cluster';

cfg.neighbours=[];

cfg.parameter='crsspctrm';

cfg.alpha            = 0.05;

cfg.clusteralpha     = 0.05;

stat=ft_freqstatistics(cfg,freq_coh);





Where freq_coh is calculated as

cfg            = [];

cfg.output     = 'powandcsd';

cfg.method     = 'mtmfft';

cfg.foilim     = [1 40];

cfg.tapsmofrq  = 2;

cfg.pad = 'nextpow2';

cfg.keeptrials = 'yes';

freq_coh          = ft_freqanalysis(cfg, Coh_data);



I am getting the following error



Error using ft_statistics_montecarlo (line 250)

could not determine the parametric critical value for clustering



Error in ft_freqstatistics (line 194)

  [stat, cfg] = statmethod(cfg, dat, design);



Sample data can be found at the following link

https://www.dropbox.com/s/6gfj97srttteawy/Coh_data.mat?dl=0<https://urldefense.com/v3/__https://www.dropbox.com/s/6gfj97srttteawy/Coh_data.mat?dl=0__;!!HJOPV4FYYWzcc1jazlU!rzdciE12ryfrSpIQp-4LAZj3EK_9U0i1XJby6k79PqsvZKuG4jrCMN-qjHXKDzonA-cj5upg$<https://www.dropbox.com/s/6gfj97srttteawy/Coh_data.mat?dl=0%3Chttps://urldefense.com/v3/__https://www.dropbox.com/s/6gfj97srttteawy/Coh_data.mat?dl=0__;!!HJOPV4FYYWzcc1jazlU!rzdciE12ryfrSpIQp-4LAZj3EK_9U0i1XJby6k79PqsvZKuG4jrCMN-qjHXKDzonA-cj5upg$>>

[https://www.dropbox.com/static/images/spectrum-icons/generated/content/content-unknown-large.png]<https://urldefense.com/v3/__https://www.dropbox.com/s/6gfj97srttteawy/Coh_data.mat?dl=0__;!!HJOPV4FYYWzcc1jazlU!rzdciE12ryfrSpIQp-4LAZj3EK_9U0i1XJby6k79PqsvZKuG4jrCMN-qjHXKDzonA-cj5upg$<https://urldefense.com/v3/__https:/www.dropbox.com/s/6gfj97srttteawy/Coh_data.mat?dl=0__;!!HJOPV4FYYWzcc1jazlU!rzdciE12ryfrSpIQp-4LAZj3EK_9U0i1XJby6k79PqsvZKuG4jrCMN-qjHXKDzonA-cj5upg$>>



Coh_data.mat<https://urldefense.com/v3/__https://www.dropbox.com/s/6gfj97srttteawy/Coh_data.mat?dl=0__;!!HJOPV4FYYWzcc1jazlU!rzdciE12ryfrSpIQp-4LAZj3EK_9U0i1XJby6k79PqsvZKuG4jrCMN-qjHXKDzonA-cj5upg$<https://urldefense.com/v3/__https:/www.dropbox.com/s/6gfj97srttteawy/Coh_data.mat?dl=0__;!!HJOPV4FYYWzcc1jazlU!rzdciE12ryfrSpIQp-4LAZj3EK_9U0i1XJby6k79PqsvZKuG4jrCMN-qjHXKDzonA-cj5upg$>>

Shared with Dropbox

www.dropbox.com<https://urldefense.com/v3/__http://www.dropbox.com__;!!HJOPV4FYYWzcc1jazlU!rzdciE12ryfrSpIQp-4LAZj3EK_9U0i1XJby6k79PqsvZKuG4jrCMN-qjHXKDzonA7PXFKq_$<https://urldefense.com/v3/__http:/www.dropbox.com__;!!HJOPV4FYYWzcc1jazlU!rzdciE12ryfrSpIQp-4LAZj3EK_9U0i1XJby6k79PqsvZKuG4jrCMN-qjHXKDzonA7PXFKq_$>>





any help would be highly appreciated

Kind regards

Bushra Riaz

_______________________________________________

fieldtrip mailing list

https://mailman.science.ru.nl/mailman/listinfo/fieldtrip

https://urldefense.com/v3/__https://doi.org/10.1371/journal.pcbi.1002202__;!!HJOPV4FYYWzcc1jazlU!rzdciE12ryfrSpIQp-4LAZj3EK_9U0i1XJby6k79PqsvZKuG4jrCMN-qjHXKDzonA0G39K1J$<https://urldefense.com/v3/__https:/doi.org/10.1371/journal.pcbi.1002202__;!!HJOPV4FYYWzcc1jazlU!rzdciE12ryfrSpIQp-4LAZj3EK_9U0i1XJby6k79PqsvZKuG4jrCMN-qjHXKDzonA0G39K1J$>



_______________________________________________

fieldtrip mailing list

https://mailman.science.ru.nl/mailman/listinfo/fieldtrip

https://urldefense.com/v3/__https://doi.org/10.1371/journal.pcbi.1002202__;!!HJOPV4FYYWzcc1jazlU!og3YlDTnQJXpbwiNKFrIAwklgaHzW9Gkdlv-WeCI05whozlcD9pwXXXbKggQyxNDbwSy0ZCd$<https://urldefense.com/v3/__https:/doi.org/10.1371/journal.pcbi.1002202__;!!HJOPV4FYYWzcc1jazlU!og3YlDTnQJXpbwiNKFrIAwklgaHzW9Gkdlv-WeCI05whozlcD9pwXXXbKggQyxNDbwSy0ZCd$>



-------------- next part --------------

An HTML attachment was scrubbed...

URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20210518/be18b5fa/attachment.htm>

________________________________

  *   Previous message (by thread): [FieldTrip] Error using indepsamplesZcoh function for calculating coherence differences<https://mailman.science.ru.nl/pipermail/fieldtrip/2021-May/040872.html>
  *   Next message (by thread): [FieldTrip] Scaling of Laplacian transformed ERPs<https://mailman.science.ru.nl/pipermail/fieldtrip/2021-May/040864.html>
  *   Messages sorted by: [ date ]<https://mailman.science.ru.nl/pipermail/fieldtrip/2021-May/date.html#40873> [ thread ]<https://mailman.science.ru.nl/pipermail/fieldtrip/2021-May/thread.html#40873> [ subject ]<https://mailman.science.ru.nl/pipermail/fieldtrip/2021-May/subject.html#40873> [ author ]<https://mailman.science.ru.nl/pipermail/fieldtrip/2021-May/author.html#40873>

________________________________
More information about the fieldtrip mailing list<https://mailman.science.ru.nl/mailman/listinfo/fieldtrip>

Please consider the environment before printing this e-mail
Cleveland Clinic is currently ranked as one of the nation’s top hospitals by U.S. News & World Report (2021-2022). Visit us online at http://www.clevelandclinic.org for a complete listing of our services, staff and locations. Confidentiality Note: This message is intended for use only by the individual or entity to which it is addressed and may contain information that is privileged, confidential, and exempt from disclosure under applicable law. If the reader of this message is not the intended recipient or the employee or agent responsible for delivering the message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please contact the sender immediately and destroy the material in its entirety, whether electronic or hard copy. Thank you.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20210831/993b2294/attachment.htm>


More information about the fieldtrip mailing list