[FieldTrip] error while using ft_freqanalysis

Konstantinos Tsilimparis konstantinos.tsilimparis at outlook.com
Fri Jun 28 15:30:16 CEST 2024


Hi Mohamed,

Do you have trials of varying lengths?

I believe the error occurs because cfg.toi = data_epoched.time{1}; selects the time points only from the first trial, while your subsequent trials might include more or different time points.

This should be fixed if cfg.toi is at least as long as the longest trial in your data or you may try to do a loop in which you call ft_freqanalysis
by selecting a new trial each time with cfg.trials & cfg.toi.

Cheers,
Konstantinos Tsilimparis


-----Original Message-----
From: fieldtrip <fieldtrip-bounces at science.ru.nl> On Behalf Of fieldtrip-request at science.ru.nl
Sent: Wednesday, June 26, 2024 12:00 PM
To: fieldtrip at science.ru.nl
Subject: fieldtrip Digest, Vol 163, Issue 18

Send fieldtrip mailing list submissions to
	fieldtrip at science.ru.nl

To subscribe or unsubscribe via the World Wide Web, visit
	https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
or, via email, send a message with subject or body 'help' to
	fieldtrip-request at science.ru.nl

You can reach the person managing the list at
	fieldtrip-owner at science.ru.nl

When replying, please edit your Subject line so it is more specific than "Re: Contents of fieldtrip digest..."


Today's Topics:

   1. error while using ft_freqanalysis (MOHAMED.ISSA at fci.bu.edu.eg)
   2. Re: Cluster based permutation test between trials
      (conditions) (Meedy P.)


----------------------------------------------------------------------

Message: 1
Date: Tue, 25 Jun 2024 16:45:32 +0000
From: "MOHAMED.ISSA at fci.bu.edu.eg" <MOHAMED.ISSA at fci.bu.edu.eg>
To: "fieldtrip at science.ru.nl" <fieldtrip at science.ru.nl>
Subject: [FieldTrip] error while using ft_freqanalysis
Message-ID:
	<DU0PR01MB10164710B109478FEA9D1F0EF98D52 at DU0PR01MB10164.eurprd01.prod.exchangelabs.com>
	
Content-Type: text/plain; charset="utf-8"

i got this error
Index in position 2 is invalid. Array indices must be positive integers or logical values.
Error in ft_specest_hilbert (line 214)
spectrum(:,ifreqoi,:) = dum(:,timeboi+prepad); Error in ft_freqanalysis (line 697) [spectrum,foi,toi] = ft_specest_hilbert(dat, time, 'timeoi', cfg.toi, 'width', cfg.width, bpfiltoptions{:}, options{:}, 'feedback', fbopt, 'edgeartnan', cfg.edgeartnan); while trying to process the folowing code cfg = []; cfg.method = 'hilbert'; cfg.output = 'fourier'; cfg.foi = 1:0.5:15; cfg.channel = 'all'; cfg.bpfilttype = 'firws'; % Default filter type cfg.bpfiltord = 4; % Filter order, can be adjusted as needed cfg.pad = 'nextpow2'; % Padding option to improve FFT efficiency cfg.toi = data_epoched.time{1}; % Perform frequency analysis with FieldTrip freq = ft_freqanalysis(cfg, data_epoched);



  *   Operating System: [Windows 11
  *   MATLAB version R2023a
  *   FieldTrip version [e.g., 20240504


​​--
Accept all My Regards

​​Mohamed Issa
Postdoctoral Researcher at BCBL
www.bcbl.eu

-----------------------------------------------------------------------
We are working flexibly at BCBL. I am sending this message at a time that suits me. Please feel comfortable knowing that I do not expect you to read, respond to or action it outside of regular working hours.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20240625/6be02523/attachment-0001.htm>

------------------------------

Message: 2
Date: Tue, 25 Jun 2024 19:23:40 +0000
From: "Meedy P." <meedy.p at hotmail.de>
To: FieldTrip discussion list <fieldtrip at science.ru.nl>
Subject: Re: [FieldTrip] Cluster based permutation test between trials
	(conditions)
Message-ID:
	<AS1P192MB1447935CF5AC5CABCEC0269C81D52 at AS1P192MB1447.EURP192.PROD.OUTLOOK.COM>
	
Content-Type: text/plain; charset="utf-8"

Hi Jan-Mathijs,

Thanks for the swift reply!
I believe there is a meaningful connection, hence I modified my code to fit the paired test-statistic.
Thanks for the advice!

All the best,
Meedy


Am 24.06.2024 um 15:55 schrieb Schoffelen, J.M. (Jan Mathijs) via fieldtrip <fieldtrip at science.ru.nl>:

 Hi Meedy Phung,

If your trials are paired across conditions, i.e. there is a meaningful connection between the x’th trial in condition 1, and the y’th trial in condition 2, you can use a paired test-statistic (a.k.a. depsamplesT). If the former conditions is not fulfilled, you should use an unpaired test statistic (a.k.a. indepsamplesT)

Best wishes and good luck,
Jan-Mathijs


On 20 Jun 2024, at 17:44, Meedy Phung via fieldtrip <fieldtrip at science.ru.nl> wrote:

Hi fieldtrip community!

I'd be grateful for insights on the cluster based permutation test between trials of a single subject.

First some info:
I have EEG data from 3 patients, all of them conducted the same experiment and I have trials of different conditions.
Specifically, I have binary answers of 'yes' and 'no' and baselines preceding the yes/no answers

I only want to test within a single subject, for example difference between yes and the baseline for subject i

I am looping through subjects, days and sessions and this is the config for the test:

% initialize cell array for yes/baseline stat results for each patient stat_yesbl_delta= cell(nsubj, 1);

% test null-hypothesis of exchangeability between YES and BASELINE YES for subi = 1:nsubj stat_yesbl_delta{subi} = cell(1, numel(tfpow_yes{subi})); % cell for each day for dayi = 1:numel(tfpow_yes{subi}) stat_yesbl_delta{subi}{dayi} = cell(1, numel(tfpow_yes{subi}{dayi})); % cell for each session for sessi = 1:numel(tfpow_yes{subi}{dayi})

% design matrix for the statistical evaluation design = [ones(1, length(tfpow_yes{subi}{dayi}{sessi}.trialinfo)), ones(1, length(tfpowbase_yes{subi}{dayi}{sessi}.trialinfo))*2];

% config
cfg = [];
cfg.channel = 'all';
cfg.latency = 'all';
cfg.frequency = [1 4]; % theta(4-8) and alpha(8-13) // beta(13-30), gamma(30-45), delta(1-4) cfg.method = 'montecarlo'; cfg.statistic = 'indepsamplesT'; % independent or dependent??
cfg.correctm = 'cluster';
cfg.clusterstatistic = 'maxsum';
cfg.clustertail = 0;
cfg.clusteralpha = 0.05; % alpha level of the sample-specific test statistic that will be used for thresholding cfg.alpha = 0.025; % corresponding to a false alarm rate of 0.05 in a two-sided test cfg.tail = 0; % one-sided (-1 or 1) or two-sided (0) test cfg.correcttail = 'prob'; cfg.numrandomization = 10000; cfg.design = design; cfg.neighbours = []; % clustering done along the freq and time dimensions cfg.ivar = 1; % row in design indicating condition

stat_yesbl_delta{subi}{dayi}{sessi} = ft_freqstatistics(cfg, tfpow_yes{subi}{dayi}{sessi}, tfpowbase_yes{subi}{dayi}{sessi});

end
end
end

As you can see i have been using cfg.statistic = 'indepsamplesT'; I have read though in some other papers that they used 'depsamplesT' for tests within a single subject and i asked chatgpt and he confirmed it.

I chose 'indepsamplesT' though because based from the tutorial here: https://www.fieldtriptoolbox.org/tutorial/cluster_permutation_freq/#between-trial-experiments
This should be a between trial experiment?

I am quite confused which is correct. I am sorry if this question seems trivial, I am quite new to this field.

However, when testing the 'depsamplesT' statistic, i am getting this error:
Error using ft_statistics_montecarlo could not determine the parametric critical value for clustering Error in ft_freqstatistics (line 194) [stat, cfg] = statmethod(cfg, dat, design); explain While when i am using 'indepsamplesT' i am getting no error.
I'd be grateful for any help and advice!

_______________________________________________
fieldtrip mailing list
https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
https://doi.org/10.1371/journal.pcbi.1002202

_______________________________________________
fieldtrip mailing list
https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
https://doi.org/10.1371/journal.pcbi.1002202
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20240625/fa105ec7/attachment-0001.htm>

------------------------------

Subject: Digest Footer

_______________________________________________
fieldtrip mailing list
https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
_______________________________________________
fieldtrip mailing list
https://mailman.science.ru.nl/mailman/listinfo/fieldtrip
https://doi.org/10.1371/journal.pcbi.1002202


------------------------------

End of fieldtrip Digest, Vol 163, Issue 18
******************************************



More information about the fieldtrip mailing list