<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
Dear Tom, dear all,
<div class=""><br class="">
</div>
<div class="">Let met reply to this e-mail on the discussion list, ’ter lering ende vermaak’ of - hopefully - many.</div>
<div class=""><br class="">
</div>
<div class=""><br class="">
<div><br class="">
<blockquote type="cite" class="">
<div class="">Begin forwarded message:</div>
<br class="Apple-interchange-newline">
<div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;" class="">
<span style="font-family: -webkit-system-font, Helvetica Neue, Helvetica, sans-serif; color:rgba(0, 0, 0, 1.0);" class=""><b class="">From:
</b></span><span style="font-family: -webkit-system-font, Helvetica Neue, Helvetica, sans-serif;" class="">Tom Marshall <<a href="mailto:tom.marshall@psy.ox.ac.uk" class="">tom.marshall@psy.ox.ac.uk</a>><br class="">
</span></div>
<div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;" class="">
<span style="font-family: -webkit-system-font, Helvetica Neue, Helvetica, sans-serif; color:rgba(0, 0, 0, 1.0);" class=""><b class="">Subject:
</b></span><span style="font-family: -webkit-system-font, Helvetica Neue, Helvetica, sans-serif;" class=""><b class="">fieldtrip cluster stats on circular data?</b><br class="">
</span></div>
<div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;" class="">
<span style="font-family: -webkit-system-font, Helvetica Neue, Helvetica, sans-serif; color:rgba(0, 0, 0, 1.0);" class=""><b class="">Date:
</b></span><span style="font-family: -webkit-system-font, Helvetica Neue, Helvetica, sans-serif;" class="">30 November 2020 at 17:50:13 CET<br class="">
</span></div>
<div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px;" class="">
<span style="font-family: -webkit-system-font, Helvetica Neue, Helvetica, sans-serif; color:rgba(0, 0, 0, 1.0);" class=""><b class="">To:
</b></span><span style="font-family: -webkit-system-font, Helvetica Neue, Helvetica, sans-serif;" class="">"Schoffelen, J.M. (Jan Mathijs)" <<a href="mailto:jan.schoffelen@donders.ru.nl" class="">jan.schoffelen@donders.ru.nl</a>><br class="">
</span></div>
<br class="">
<div class="">
<div class="WordSection1" style="page: WordSection1; caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;">
<div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
Hi JM,<o:p class=""></o:p></div>
<div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<o:p class=""> </o:p></div>
<div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
Is there support for using the fieldtrip cluster-stat functions if the axis I want to cluster over is<span class="Apple-converted-space"> </span><i class="">circular</i>?<o:p class=""></o:p></div>
<div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
<o:p class=""> </o:p></div>
<div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif;" class="">
E.g., say I have spike counts at evenly-spaced phase bins of an oscillation, in two conditions, and I want to test the hypothesis of a difference between the way the spikes phase-cluster in condition A vs condition B. So instead of a time-axis, my data have
 a<span class="Apple-converted-space"> </span><i class="">phase</i>-axis that spans 0-2pi.<span class="Apple-converted-space"> </span><span style="font-size: 11pt;" class=""><font color="#a811d1" class="">It seems like you could use cluster-based permutation
 to test that hypothesis. In fact you could just hack those data into a fieldtrip structure and plug them into ft_timelockstatistics right away. But ft_timelockstatistics would then not identify clusters if they cross the arbitrary 0/2pi point (because 0 is
 at the beginning of the vector and 2pi at the end); you would be biased towards finding clusters in certain parts of the phase-space and not others by ignoring its circularity.</font></span></div>
</div>
</div>
</blockquote>
<div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif; caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);" class="">
<o:p class=""></o:p></div>
<div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif; caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);" class="">
<br class="">
</div>
<div><br class="">
</div>
<div>Well, the first thing that comes to mind, is that you could - rather than framing this in terms of a ’statfun’ - look into computing spike-field coherence <a href="https://www.fieldtriptoolbox.org/tutorial/spikefield/" class="">https://www.fieldtriptoolbox.org/tutorial/spikefield/</a>.
 That is, spike-field coherence (or a similar measure that quantifies the extent to which the timing of point-process are aligned to a preferred phase of an oscillatory process. Then, what you’re after is to statistically compare the spike-field coherence across
 conditions (provided you control for difference in overall spike rate, and the SNR of the oscillation signal.</div>
<div><br class="">
</div>
<div>Alternatively, and that’s what you asked about, one can think of designing a ’statfun’ that takes the circularity of the independent variable into account. So, in such a context, one would have a bunch of observed (dependent variables) values (e.g. spike
 rate), which are paired with an independent variable (i.e. the phase of an oscillation at which the spike rate was estimated). What I have done in the past was to operationalize your question into a test-statistic that quantified (least-squares) the amplitude
 of a cosine function to the data points, as a function of phase. As a  matter of fact, following up on a related discussion I recently had in house, I just created a FAQ about this: <a href="https://www.fieldtriptoolbox.org/faq/how_can_i_test_whether_a_behavioral_measure_is_phasic/" class="">https://www.fieldtriptoolbox.org/faq/how_can_i_test_whether_a_behavioral_measure_is_phasic/</a></div>
<div><br class="">
</div>
<div>In this FAQ I pasted the code for a statufn (ft_statfun_cosinefit), which basically estimates the amplitude of the best-fitting cosine wave, determined by the phase values in the design. By default, it does not care about the optimal phase (although the
 function allows for the constraint to fit a cosine wave with a fixed (specified) phase). One could of course think of other - perhaps more appropriate - test statistics, e.g. the concentration parameter of a von Mises distribution (or the goodness-of-fit of
 a (mixture of) von Mises distributions, which also would address the question as to whether there’s a single preferred phase to begin with).</div>
<div><br class="">
</div>
<div>The tricky bit would be to think of an appropriate randomization scheme, in order to test a null hypothesis at the first level.</div>
<div><br class="">
</div>
<div>Yet, in your case, it seems you want to do a second level test (i.e. is the amplitude of the cosinefit in condition A systematically larger than in condition B), so the permutation only comes into play when you start permuting across conditions (in which
 case you can just use a depsamplesT based test statistic.</div>
<div><br class="">
</div>
<div>Best wishes,</div>
<div><br class="">
</div>
<div>JM</div>
<div><br class="">
</div>
<div><br class="">
</div>
<div>
<blockquote type="cite" class="">
<div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif; caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);" class="">
So question part A: Has anyone implemented this before and if so is there code for it?</div>
</blockquote>
<div><br class="">
</div>
Yes, and yes. See above.</div>
<div><br class="">
<blockquote type="cite" class="">
<div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif; caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);" class="">
<o:p class=""></o:p></div>
<div style="margin: 0cm; font-size: 11pt; font-family: Calibri, sans-serif; caret-color: rgb(0, 0, 0); color: rgb(0, 0, 0);" class="">
Part B: <wild guesses welcome> Do you think adapting the cluster-stats code would be a big/difficult job for a moderately-experienced coder who knows the fieldtrip source a bit (i.e., me)? Which low-level functions are the right place to start looking? And
 would this be useful for the fieldtrip user base? If so I’d happily try to implement it and submit a PR.</div>
</blockquote>
<br class="">
</div>
<div>Thanks. Let’s follow this up if you were thinking of another solution as the one outlined above.</div>
<div><br class="">
</div>
<div><br class="">
</div>
</div>
</div>
</body>
</html>