[FieldTrip] Grand mean

Stephen Whitmarsh stephen.whitmarsh at gmail.com
Fri May 15 11:50:59 CEST 2020


Dear Sarah,

Let me add my 2 cents here. Since a simple subtraction should not pose a
problem, its perhaps more a matter of clarifying the pipeline and
datastructures.  I would therefor suggest to simply add or subtract time
courses using MATLAB (first). This will make debugging much more
straightforward, and will also force you to look a bit more into the data
structures, which might clarify things already.

>From the top of my head;
After data = ft_preprocessing, your timecourse data (the voltages over
time) will be in data.trial{:}. In data.time you will find the
corresponding time axes.
After data = ft_timelockanalysis (single subject), you will probably end up
with your timecourse data in data.avg. In data.time you will find the
corresponding time axis of the average.
After data = ft_timelockgrandaverage (over subjects), your timecourse data
will probably be in data.avg.avg.  In data.time you will find the
corresponding time axis of the average.
For all, check data.dimord to see how the dimensions of the data.avg /
data.avg. avg are organized, probably "chan_time_rpt" (channels x time x
trials), or "chan_time" (channels x time).

Now, assuming the length of your data, the number of channels, etc. (i.e.
everything *but* the values in the timecourses), are the same between
conditions, you should be able to simply copy one averaged datastructure,
and replace the averaged time course data with the difference / sum you
calculate 'by hand'. E.g.

data_diff = data_cond1;
data_diff.avg.avg = data_cond2.avg.avg - data_cond1.avg.avg;
or
data_diff = data_cond1;
data_diff.avg.avg = data_cond2.avg.avg ./ data_cond1.avg.avg; % use ./
instead of / to tell MATLAB to just divide datapoint-by-datapoint instead
of dividing the matrices.

Note that you will lose the fieldtrip bookkeeping of the analysis pipeline
etc., but this will do the trick and demystify it a bit, and afterward you
can always replace it with ft_maths.

Hope this helps,
Stephen





Op vr 15 mei 2020 om 10:12 schreef Sarah Kirchler <sarah.kirchler at gmail.com
>:

> Hi Jan-Mathijs,
>
> thank you for your answer, I do my best to explain your questions.
> The Problem is, that I don't have datastructures that I can combine (but I
> would like to have them). So that's the primary question.
>
> These are the steps I already did:
> I measured, as mentioned before, with an EEG the visual stimulation via
> two frequencies (SSVEP).
> I preprocessed my data with ft_preprocessing (cuttet it in segments, did
> filtering, concenated the cfg-Matrix with the trialinfo of my clean
> preprocessed data and then, with a loop, I made the SSVEP-analysis for all
> my subjects (ft_timelockanalysis and ft_frequencyanalysis).
> I made the timelockanalysis for the two frequencies separately and for the
> control-target (which in this case is something like a baseline-condition
> for measuring the average activation of the subject-brains, so I can differ
> the target-activation from it. Now  I added the Grand Mean:
>
> gm_1 = ft_timelockgrandaverage(cfggm, tl1); gm_2 =
> ft_timelockgrandaverage(cfggm, tl2);)
>
> separately for the two frequencies.
> I am now failing when trying to make the grand mean for the difference and
> the sum of the two frequencies. I tried to make something like this for the
> sum:
>
> gm_3 =ft_timelockgrandaverage(cfggm, tl1, tl2)
>
> but I don't think it's correct.
> So I tried to make the difference like that:
>
> cfg = [];
> cfg.parameter = 'avg';
> cfg.operation = 'x1-x2';
> difftopo12 = ft_math(cfg, gm_1, gm_2);
> figure
> cfg=[];
> cfg.xlim = [0.1:0.05:0.5];
> cfg.zlim = [-2 2];
> cfg.layout = '63equidistant_lay.mat';
> ft_topoplotER(cfg, difftopo12);
>
> But for this procedure I need datastructures for x1 and x2, which I don't
> have.
> (Fieldtrip: In the specification of the mathematical operation, x1 is the
> parameter obtained
>
> from the first input data structure, x2 from the second, etc.)
>
> So I have a way that would work but not the datastructures.
>
> I tried to make the datastructures like this:
>
> tl1{vpn} = ft_timelockanalysis(cfg,data)       (vpn is the name I gave the
> subjects when looping them for the timelock- and frequencyanalysis. --> for
> for vpn = 1:length(cleannames)...)
>
> and then to make the grand mean like this:
>
> gm_1 = ft_timelockgrandaverage(cfg, tl1{:});
>
> but it doesn't work.
>
>
> I would be really thankfull if you yould give me some help to find the
> error,
>
> Sarah
>
>
>
> Am Do., 14. Mai 2020 um 19:12 Uhr schrieb Schoffelen, J.M. (Jan Mathijs) <
> jan.schoffelen at donders.ru.nl>:
>
>> Dear Sarah,
>>
>> Thanks for clarifying your question. Now, could you provide the
>> readership with some additional information about how you constructed these
>> data structures, and how you tried to combine them, otherwise we (i.e. the
>> people who’d want to think along with you to fix your problem) don’t know
>> where to start.
>>
>> Jan-Mathijs
>>
>>
>> On 14 May 2020, at 09:32, Sarah Kirchler <sarah.kirchler at gmail.com>
>> wrote:
>>
>> Dear Jan-Mathijs,
>>
>> thank you for your answer. I see, i expressed myself not very clear.
>> I'd like to make the Grand mean for the difference and the sum between
>> two specific frequencies I measured visually wih a SSVEP.
>> I'd like to do this because I'm interested in how the frequencies are
>> processed in the brain regarding each other and a control measurement.
>> I'm not sure if I can make the difference already when I make the GM or
>> later, when I plot the topography.
>> I tried to make this by building a datastructure that contains the GM of
>> the one and the other frequency and then usw ft_math to compare them. But
>> this doesn't work for me.
>> Maybe thats enough information for you to understand the problem better,
>> I'm a beginner so I often explain my problems a little bit confusing, sorry
>> for that.
>>
>> Best,
>>
>> Sarah
>>
>> Am Mi., 13. Mai 2020 um 15:30 Uhr schrieb Schoffelen, J.M. (Jan Mathijs) <
>> jan.schoffelen at donders.ru.nl>:
>>
>>> Dear Sarah,
>>>
>>> It is not clear what error message you get, nor why you think you should
>>> ft_timelockanalysis/ft_timelockgrandaverage/ft_topoplotER.
>>>
>>> Some pointers:
>>> -For a mathematical operation to be applied to numeric data that resides
>>> within a fieldtrip-style data structure you’d use ft_math.
>>> -What you want to do (i.e. adding or subtracting estimates of frequency
>>> specific power estimated for different frequency bins) probably requires
>>> some manual intervention with the data, because FT will likely prevent you
>>> to do so, since it checks whether the frequency bins for the to-be-combined
>>> data structures match. I could type some recipe now, but since you are not
>>> too clear on the details so I’d rather not spend time on that now. Also,
>>> I’d like to give other people the opportunity to chime in here :).
>>>
>>> Best wishes,
>>> Jan-Mathijs
>>>
>>> On 11 May 2020, at 16:43, sarah.kirchler at gmail.com wrote:
>>>
>>> Dear Fieldtrip Users,
>>>
>>> thank you for all the help you’ve given me already.
>>> Now I am trying to make the sum and the difference of the Grand mean
>>> from/between two frequencies I measured with an EEG.
>>> I read that it is possible to make a datastructure using {} within
>>> ft_timelockbaseline and then use the option cfg.operation(x1-x2 and so on)
>>> as a operation of function ft_topoplotER to make this sum/these differences.
>>>
>>> Now my Problem is that I don’t need to make the baselinecorrection via
>>> ft_timelockbaseline because I don’t have the baseline in the datasegment
>>> I’m interested in. So I tried to build the datastructure for cfg.operation
>>> within ft_timelockanalysis but Fieldtrip doesn’t allow this and I get an
>>> error message.
>>>
>>> My questions are now:
>>> 1. Can I make the difference also within the ft_timelockgrandavverage
>>> function or do I have to make the difference lawer in ft_topoplotER?
>>> 2. If so, how can I or form a datastructure I can use in cfg.operation
>>> or make the difference differently with some other function?
>>>
>>> I hope you understand me,
>>> to all you extraordinary brains: thank you in advance,
>>>
>>> Sarah
>>>
>>> _______________________________________________
>>> 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
>>>
>> _______________________________________________
>> 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
>>
> _______________________________________________
> 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/20200515/fd7660ce/attachment.htm>


More information about the fieldtrip mailing list