<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Hello Max,<br>
<br>
I added a few comments to the questions regarding individual
parameters below. To address the general problem of TRENTOOL telling
you, that there are not enough sample points in your data: From what
I can see in your script, you probably don't have enough data points
in each time series to robustly estimate TE. You analyze 800 ms of
data sampled at 300 Hz, which gives you 240 samples per time series.
Can you maybe avoid downsampling to 300 Hz and downsample to 600 Hz
instead? Or could you analyze a longer time window of interest?<br>
Note that you also 'lose' data to embedding and the interaction
delay: The first point that can be used for TE estimation is at max.
embedding length + max. interaction delay in samples. For example:
max. embedding length = dim * tau_factor * ACT = 10 * 0.4 * 5 = 20
samples plus the max interaction delay of 30 ms = 9 samples. In this
example, you would be left with 240 - 29 samples for TE estimation
per trial. There is also the possibility to estimate time resolved
TE/TE for shorter time windows of interest (see section 4.4 in the
manual); however, this method requires the use of a GPU for TE
estimation.<br>
<br>
I would further recommend to use the new pipeline for group
statistics described in the manual in section 4.5 (the function
'TEgroup_calculate' is deprecated). The new pipeline allows you to
reconstruct the interaction delay and uses the following functions
(see also comments in the script):<br>
<br>
TEgroup_prepare -> prepares all data sets (all subjects/all
conditions) for group analysis (this means finding common embedding
parameters such that estimates are not biased between groups)<br>
InteractionDelayReconstruction_calculate -> estimates TE for
individual data sets and all assumed interaction delays u<br>
InteractionDelayReconstruction_analyze -> reconstructs the
interaction delay by selecting the u that maximizes TE for each
channel<br>
TEgroup_stats -> calculate group statistics using a
permutation test<br>
<br>
I can send you an example script for group TE analysis using this
pipeline to get you started. I hope this helps you to get the group
analysis running. Just write again if you're having trouble setting
up the pipeline or something is not clear about the parameters/my
comments.<br>
<br>
Best,<br>
Patricia<br>
<br>
<br>
<br>
<br>
On 09/04/2014 08:30 PM, Max Cantor wrote:<br>
<blockquote
cite="mid:CAFTjRaWs6kcyOf8x_Ex9mwVFKJ_ADC8r27bddQr+_QZ5cvtZaQ@mail.gmail.com"
type="cite">
<div dir="ltr">
<div>
<div>
<div>Hi fieldtrippers,<br>
<br>
</div>
I know trentool is not produced by the Donders Institute, so
I'm not 100% sure if it is appropriate to ask questions
about it here, but to the best of my knowledge they do not
have a mailing list and I saw a few trentool questions in
the archives, so I'm going to assume it's ok...<br>
<br>
</div>
In any case, below is my current pipeline (slightly modified
for comprehensibility):<br>
<br>
</div>
(notes in bold are comments/questions made in this email, not
present in the pipeline. Sorry in advance for the long post! Any
help would be greatly appreciated as I'm a bit over my head on
this but I think I'm close!)<br>
<div><br>
*****<br>
<br>
% Prepare group TE data<br>
<br>
cfgP = [];<br>
cfgP.Path2TSTOOL = <b>TSTOOLPATH</b> <br>
cfgP.TEcalctype = 'VW_ds';<br>
cfgP.channel = {'ctfdip_LAC' 'ctfdip_RAC'}; <br>
<br>
<b>I'm trying to find the transfer entropy between the left
and right auditory cortices in my experiment. The input is
virtual sensor data that was produced using SAM in fieldtrip
on real MEG data. </b><br>
<br>
% specify u to be scanned <br>
<br>
cfgP.predicttime_u = 30; <br>
cfgP.toi = [-0.4 0.4]; <br>
<br>
</div>
</div>
</blockquote>
<blockquote
cite="mid:CAFTjRaWs6kcyOf8x_Ex9mwVFKJ_ADC8r27bddQr+_QZ5cvtZaQ@mail.gmail.com"
type="cite">
<div dir="ltr">
<div><b>For clarification, the predicttime_u is in seconds but
the toi is in milliseconds. If I understand correctly, the
predicttime_u must fit within the toi, but beyond that are
there any benefits to it being earlier or later?</b> PW: The
predictiontime_u is in milliseconds and the toi is in seconds.
The prediction time is the assumed interaction delay between
your two sources and should fit within your toi. In general it
is preferable to use the method for interaction delay
reconstruction for TE estimation, because it allows you to
reconstruct the actual delay between your source and target
times series. A non-optimal u/interaction delay may cause an
underestimation of TE, so it is recommended to use the
pipeline for interaction delay reconstruction whenever
estimating TE for unknown delays. <br>
If you use the methods for interaction delay reconstruction
'predicttime_u' is replaced by<br>
cfgTEP.predicttimemin_u % minimum u to be scanned<br>
cfgTEP.predicttimemax_u % maximum u to be scanned<br>
cfgTEP.predicttimestepsize % time steps between u to be
scanned <br>
A large range for u values to be scanned increases computing
time a lot, so it is best to limit the u range to values that
are physiologically plausible. <br>
<br>
</div>
</div>
</blockquote>
<blockquote
cite="mid:CAFTjRaWs6kcyOf8x_Ex9mwVFKJ_ADC8r27bddQr+_QZ5cvtZaQ@mail.gmail.com"
type="cite">
<div dir="ltr">
<div>% ACT (Autocorrelation Time) estimation and constraints<br>
<br>
cfgP.maxlag = 150; <br>
cfgP.actthrvalue = 7.5; <br>
cfgP.minnrtrials = 5; <br>
<br>
</div>
<div><b>My understanding is maxlag should be 1/2 the sampling
rate, so since the data are downsampled to 300hz, it should
be 150. I know that the sample rate and filters are used to
determine the actthrvalue, but I don't actually know the
calculation. 7.5 was a rough guess just to test the
pipeline. I'm also uncertain of what minnrtrials should be.</b>
PW: You can set the actthrvalue based on the filtering you did
prior to TE analysis. If you for example highpass filtered at
10 Hz, you shouldn't find an ACT higher than 30 samples,
because you filtered out any components of the signal slower
than 10 Hz/30 samples (given your sampling frequency of 300
Hz). So in this scenario the actthrvalue would be 30.<br>
A good value for cfgP.minnrtrials is 12 (a minimum number of
trials is needed to realize the permutation test for
estimated TE values). </div>
</div>
</blockquote>
<blockquote
cite="mid:CAFTjRaWs6kcyOf8x_Ex9mwVFKJ_ADC8r27bddQr+_QZ5cvtZaQ@mail.gmail.com"
type="cite">
<div dir="ltr">
<div> </div>
<div> <br>
% Optimization<br>
<br>
cfgP.optimizemethod = 'ragwitz';<br>
cfgP.ragdim = 4:8;<br>
cfgP.ragtaurange = [0.2 0.4];<br>
cfgP.ragtausteps = 15;<br>
cfgP.repPred = 100;<br>
<b><br>
</b></div>
<div><b>I am completely at a loss for this. I've done some
reading into transfer entropy, mutual information, etc.,
cited in trentool, but I'm yet to understand how exactly
this optimization works and what the configuration should
be, given my data and experimental intentions.</b> PW: The
Ragwitz criterion tries to find optimal embedding parameters
dim and tau for the data. To do that, the method iteratively
takes all possible combinations of dim and tau values that are
provided in cfgP.ragdim and cfgP.ragtaurange/.ragtausteps and
tests how well these combinations embed the data. To test an
embedding, the method builds the embedding vectors from the
data; it then tests for each point how well the next point in
time can be predicted from the reference point's nearest
neighbours. So for each embedded point, the method searches
for the nearest neighbours and calculates the average of those
nearest neighbours. The difference between the
averaged/predicted point and the actual next point is the
error of the local predictor. The Ragwitz criterion will then
return the parameter combination for which this error over all
points is minimal. <br>
The parameters set the following: 'ragdim' are dimensions to
be tested by the method (I would reccomend to start with
2:10), 'ragtaurange' together with 'ragtausteps' specifies the
tau values to be tested (TRENTOOL will build a vector from 0.2
to 0.4 in 15 steps). Note, that the values here are factors
that are later multiplied with the ACT to obtain the actual
tau. 'repPred' is the number of points that will be used for
the local prediction, i.e. the Ragwitz criterion will test the
local prediction and calculate the error for the first 100
points in your time series. The two parameters 'flagNei' ans
'sizeNei' below specify the type of neighbour search conducted
by the Ragwitz criterion: 'flagNei' tells the method to either
conduct a kNN or range search; 'sizeNei' specifies the number
of neighbours or the radius to be searched by a range search.<br>
<br>
</div>
</div>
</blockquote>
<blockquote
cite="mid:CAFTjRaWs6kcyOf8x_Ex9mwVFKJ_ADC8r27bddQr+_QZ5cvtZaQ@mail.gmail.com"
type="cite">
<div dir="ltr">
<div> <br>
% Kernel-based TE estimation<br>
<br>
cfgP.flagNei = 'Mass';<br>
cfgP.sizeNei = 4; % Default<br>
<br>
cfgP.ensemblemethod = 'no';<br>
cfgP.outputpath = <b>OUTPUT PATH</b>; <br>
<br>
if ~exist(<b>Path for TEprepare data object</b>)<br>
load VSdat;<br>
TE_Wrd = {}; <br>
for i = 1:nConds<br>
for j = 1:Nsub<br>
TE_Wrd{i}{j} = TEprepare(cfgP,
VSdat{i}{j});<br>
end<br>
end<br>
clear VSdat;<br>
save('TE_Wrd', 'TE_Wrd');<br>
end<br>
<b><br>
</b></div>
<div><b>The configuration and virtual sensor data, organized in
a 3 x 15 cell of structures (condition by subject) are the
input. The TEprepare substructure is added to each
individual condition x subject .mat files' data structure
which are stored on disk independently.</b> <br>
</div>
<div><br>
% Use object_to_mat_conversion.m to replace individual
condition x subject virtual sensor data<br>
% .mat files with their TE_Wrd equivalent<br>
<b><br>
</b></div>
<div><b>I'm using a separate script to make some manipulations
to the objects from disk; this will all eventually be
integrated into the main pipeline</b>.<b> TRENTOOL seems to
handle data output very differently from fieldtrip and I've
had trouble thinking through the most logical way to handle
the data so it's a bit haphazard right now.</b><br>
</div>
<div><br>
load cond080sub01.mat<br>
<br>
cfgG = [];<br>
cfgG.dim =
cond080sub01.TEprepare.optdim;<br>
cfgG.tau =
cond080sub01.TEprepare.opttau;<br>
<br>
if isfield(cond080sub01, 'TEprepare')<br>
TEgroup_prepare(cfgG, fileCell);<br>
else<br>
error('Need to run TEprepare before TEgroup_prepare');<br>
end<br>
<b><br>
</b></div>
<div><b>For clarification, fileCell is a cell with the name of
each condition x subject .mat file, which as I said before
is collectively the same as the 3 x 15 VSdat structure
(condition x subject).</b><br>
</div>
<div><br>
% Replace .mat files with '_for_TEgroup_calculate' version in<br>
% object_to_mat_conversion.m<br>
<br>
% TE Group Calculate<br>
<br>
load cond080sub01.mat<br>
if isfield(cond080sub01, 'TEgroupprepare')<br>
for i = 1:length(fileCell)<br>
TEgroup_calculate(fileCell{i});<br>
end<br>
else<br>
error('Need to run TEgroup_prepare before
TEgroup_calculate');<br>
end<br>
<b><br>
</b></div>
<div><b>At this step I get the following error:<br>
<br>
Error using transferentropy (line 337)<br>
\nTRENTOOL ERROR: not enough data points left after
embedding<br>
<br>
Error in TEgroup_calculate (line 133)<br>
[TEresult] = transferentropy(cfg,data);</b><br>
</div>
<div><br>
% TE Group Stats<br>
<br>
cfgGSTAT = [];<br>
cfgGSTAT.design(1,1:2*Nsub) = [ones(1,Nsub) 2*ones(1,Nsub)];<br>
cfgGSTAT.design(2,1:2*Nsub) = [1:Nsub 1:Nsub];<br>
<br>
cfgGSTAT.uvar = 1;<br>
cfgGSTAT.ivar = 2;<br>
cfgGSTAT.fileidout = 'test_groupstats';<br>
<br>
TEgroup_stats(cfgGSTAT,
fileCell);<br>
<br>
</div>
<div><b>Given the error above, I am yet to get to this step, but
it does not seem fundamentally different from normal
fieldtrip stats.</b><br clear="all">
</div>
<div>
<div>
<div>
<div><br>
*****<br>
<br>
</div>
<div>In case my notes were not clear or you skipped to the
bottom, <b>my primary concern is whether the error I'm
getting in TEgroup_calculate is a pipeline issue</b>
(I noticed the example pipeline in trentool, the manual,
and published methods articles all seem to have slightly
or significantly different pipeline compositions), <b>or
if the error is</b> due to ACT, ragwitz optimization,
or some other faulty parameterization <b>on my part due
to a lack of understanding of how transfer entropy
works on a more theoretical/mathematical level</b>. If
the latter is the case, is there any relatively
straightforward way to conceptualize this, or is this
something where I'm just going to have to keep reading
and rereading until it eventually makes sense? I've
already done quite a bit of that and it hasn't pierced
my thick skull yet but I'm sure it will eventually!<br>
<br>
</div>
<div>Thank you so much,<br>
<br>
</div>
<div>Max Cantor<br>
</div>
<div><br>
<br>
-- <br>
<div dir="ltr">Max Cantor
<div>Lab Manager</div>
<div>Computational Neurolinguistics Lab</div>
<div>University of Michigan</div>
</div>
</div>
</div>
</div>
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
fieldtrip mailing list
<a class="moz-txt-link-abbreviated" href="mailto:fieldtrip@donders.ru.nl">fieldtrip@donders.ru.nl</a>
<a class="moz-txt-link-freetext" href="http://mailman.science.ru.nl/mailman/listinfo/fieldtrip">http://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a></pre>
</blockquote>
<br>
<div class="moz-signature">-- <br>
<meta http-equiv="content-type" content="text/html;
charset=windows-1252">
<title></title>
<address><font color="#666666"><small><font face="Helvetica,
Arial, sans-serif">------------------------------------------------------------<br>
<br>
</font></small></font></address>
<address><font color="#666666"><small><font face="Helvetica,
Arial, sans-serif">Patricia Wollstadt, PhD Student<br>
<br>
</font></small></font></address>
<address><font color="#666666"><small> </small></font></address>
<address><font color="#666666"><small><font face="Helvetica,
Arial, sans-serif"> MEG Unit, Brain Imaging Center</font></small></font></address>
<address><font color="#666666"><small><font face="Helvetica,
Arial, sans-serif"> Goethe University, Frankfurt, Germany<br>
<br>
</font></small></font></address>
<address><font color="#666666"><small><font face="Helvetica,
Arial, sans-serif">Heinrich Hoffmann Strasse 10, Haus 93 B</font></small></font></address>
<address><font color="#666666"><small><font face="Helvetica,
Arial, sans-serif">D - 60528 Frankfurt am Main</font></small></font></address>
</div>
</body>
</html>