[FieldTrip] Dynamic ROI for cluster-based permutation statistics

Schoffelen, J.M. (Jan Mathijs) jan.schoffelen at donders.ru.nl
Fri Jun 4 13:52:48 CEST 2021

Hi Cihan,

Thanks for your reply.

I am still somewhat confused by your reply, because I don’t see why (at least if indeed you agree to saying that you want to achieve my suggested scenario 1) you would need to have the neighbourhood matrix to be time variant? If you want the spatial data points to be included for the clustering algorithm to vary over time, it would suffice to mask out the non-relevant data points. If it’s done in a way that these get a value such that the clusterthreshold is not exceeded, they will never contribute to the clustering. I don’t think that this is to be addressed in clusterstat/findcluster, but needs can be addressed at the level at which the input data to the function is to be defined. One way in which this can be done would be to replace the irrelevant space-time-frequency points in the input data by a NaN.

Best wishes,


On 4 Jun 2021, at 13:30, Cihan Dogan <cd549 at kent.ac.uk<mailto:cd549 at kent.ac.uk>> wrote:

Hi Jan,

Many thanks for picking this up.

From my understanding, currently what enters the clustering is a neighbourhood of electrodes, these are then used throughout the entire time period for clustering. Rather than have a ‘static’ number of channels for the entire time duration, I would like to change the channels used in clustering at each time point. I believe this would fall under 1.

Currently to make these changes I am working under the following assumptions:


From what I gather, to make the changes there are three main MATLAB files, ft_statistics_montecarlo.m, clusterstat.m, and findcluster.m.  ft_statistics_montecarlo.m

So the first action is define my connectivity matrix which is of size electrode*electrode where a 1 in matrix indicates if two electrodes are connected. Currently this is done for the static neighbourhood which is defined in cfg.neighbourhood. So I essentially I need to create a connectivity matrix for each point in time based on my dynamic ROI.

From here there are two statistics that are computed, one for the observed data and randomised data over n permutations, in our case we are using the ft_statfun_indepesampleregrT function to regress against our behavioural variables.

The next step is now the clustering where clusterstat.m is called - we pass in both our observed and random statistics toclusterstat.m. Using findcluster.m located in clusterstat.m we first take in the observed data along with the connectivity matrix.

Essentially findcluster.m takes each channel combination to find connected time-frequency clusters from the statistics, from here, we then combine clusters that are connected in neighbouring channels to form a large cluster. I believe here is where I should make the changes.


Many thanks,

From: Schoffelen, J.M. (Jan Mathijs) <jan.schoffelen at donders.ru.nl<mailto:jan.schoffelen at donders.ru.nl>>
Sent: 04 June 2021 09:38
To: FieldTrip discussion list <fieldtrip at science.ru.nl<mailto:fieldtrip at science.ru.nl>>
Cc: Howard Bowman <H.Bowman at kent.ac.uk<mailto:H.Bowman at kent.ac.uk>>; Palaniappan Ramaswamy <R.Palani at kent.ac.uk<mailto:R.Palani at kent.ac.uk>>; Cihan Dogan <cd549 at kent.ac.uk<mailto:cd549 at kent.ac.uk>>
Subject: Re: [FieldTrip] Dynamic ROI for cluster-based permutation statistics

CAUTION: This email originated from outside of the organisation. Do not click links or open attachments unless you recognise the sender and know the content is safe.

Hi Cihan,

I don’t understand the question. Also, I don’t understand what you mean with ‘defining a ROI in cfg.neighbours’.

Do you want to

1. constrain for each time point the set of channels that enter into the clustering algorithm?


2. use a different spatial neighbourhood matrix for each time point?

These are two different things I think.

Best wishes,


On 19 May 2021, at 13:04, Cihan Dogan <CDogan1994 at hotmail.co.uk<mailto:CDogan1994 at hotmail.co.uk>> wrote:

Dear FT,

Currently I have an experiment setup to run a cluster-based permutation tests on time-frequency data regressing against some behavioural variables using the ft_statfun_indepsampleregrT function.

I have a prior precedent for using a particular ROI which I have defined in cfg.neighbours, however, I wish to change this ROI dynamically through time. So essentially for each timestep get the set of neighbours and use this to cluster at that point in time rather than apply a static ROI for the entire duration.

I was wondering if in FieldTrip it is possible to apply a dynamic region of interest through time? And if not, how much of a job it would be to make this addition myself.

I’ve started to look at some of the underlying code such as clusterstat.m and findcluster.m to make this addition /amendment and was wondering if anyone in the community has made such a change.

Many thanks,
fieldtrip mailing list

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.science.ru.nl/pipermail/fieldtrip/attachments/20210604/535eb294/attachment.htm>

More information about the fieldtrip mailing list