<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
Hi Sebastian,
<div class=""><br class="">
</div>
<div class="">I would say that for visualization purposes (and for traditional parametric second-level statistics) you are interested in the variance across your units-of-observation. In this case across subjects. This is indeed what ft_timelockgrandaverage
 gives you. If you are into more sophisticated estimates, it smells a bit as if you want to be moving into the direction of mixed-effect models, which are gaining quite a bit of momentum these days. Since I am a bit old-school I have not eaten any cheese from
 that (<a href="http://www.dwotd.nl/2008/02/360-daar-heb-ik-geen-kaas-van-gegeten.html" class="">http://www.dwotd.nl/2008/02/360-daar-heb-ik-geen-kaas-van-gegeten.html</a>), so perhaps somebody else wants to chime in here.</div>
<div class=""><br class="">
</div>
<div class="">Best wishes,</div>
<div class="">Jan-Mathijs</div>
<div class=""><br class="">
</div>
<div class="">
<div><br class="">
<blockquote type="cite" class="">
<div class="">On 26 Sep 2022, at 21:36, Sebastian Neudek via fieldtrip <<a href="mailto:fieldtrip@science.ru.nl" class="">fieldtrip@science.ru.nl</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div id="divtagdefaultwrapper" dir="ltr" style="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; font-size: 12pt; font-family: Calibri, Helvetica, sans-serif;" class="">
<p style="margin-top: 0px; margin-bottom: 0px;" class=""></p>
<div class="">Hi all,<br class="">
<br class="">
I am currently writing my master's thesis using FieldTrip and might need a bit of your expertise for a little hurdle I encountered.<br class="">
<br class="">
First a few words about what I want to do:<br class="">
I have data from a MEG-go/nogo study: There are multiple subjects and multiple trials for each condition. I now want to plot the ERF for each condition averaged across all subjects. But together with the ERF I also want to plot the  standard error or variance
 or confidence interval or standard deviation. Something like this(Figure 3a):<br class="">
<a href="https://urldefense.com/v3/__https://www.researchgate.net/figure/ERP-results-including-P3-amplitudes-a-Grand-average-and-standard-errors-of-ERP_fig2_327651209__;!!HJOPV4FYYWzcc1jazlU!4AKDCxWgDNOVGlWwimPV3Sc-5suVMj59sPhwC-eHwI7h0FQr10-YxE5fzliZsQft3R0I3s5Swpei12UfNPYgMdNHwshEvUe7t8p0Gw$" class="OWAAutoLink" id="LPlnk347301" previewremoved="true">https://www.researchgate.net/figure/ERP-results-including-P3-amplitudes-a-Grand-average-and-standard-errors-of-ERP_fig2_327651209</a><br class="">
Independent which of these measures I finally use, I need to calculate the variance of the ERF at each timepoint.<br class="">
To do this I first used ft_timelockanalysis to calculate the averages of each subject. ft_timelockanalysis returns not only the average, but also the variance of the ERF. Afterwards I use ft_timelockgrandaverage to calculate the group average of the ERF.<br class="">
<br class="">
And this is where my troubles begin. I get how ft_timelockgrandaverage calulates the new average: It averages over the mean values of the subjects (it also accounts for the degrees of freedom). But for the variance it just calculates the variance of the means.
 I thought, it will also account for the variances of each subject.<br class="">
In the extreme case it leads to the following:<br class="">
Imagine you have two subjects and you measure very close averages avg(sub1)=1 and avg(sub2)=1.0001. But their variances are extremly high: var(sub1)=var(sub2)=100. Then the variance calculated by ft_timelockgrandaverage is almost zero, when in reality it should
 be something like 100.<br class="">
Maybe this should be noted in ft_timelockgrandaverage, because it can lead to wrong statistics if the user isn't aware of this effect.<br class="">
<br class="">
Back to my task:</div>
<div class="">This is surely not the variance I want to use for my ERF plots and therefore I searched for a different calculation.<br class="">
I found on wikipedia a formula for so called 'pooled variance' (at the bottom of the page for sample-based statistics):<br class="">
<a href="https://urldefense.com/v3/__https://en.wikipedia.org/wiki/Pooled_variance__;!!HJOPV4FYYWzcc1jazlU!4AKDCxWgDNOVGlWwimPV3Sc-5suVMj59sPhwC-eHwI7h0FQr10-YxE5fzliZsQft3R0I3s5Swpei12UfNPYgMdNHwshEvUeBLHOpZA$" class="OWAAutoLink" id="LPlnk563115" previewremoved="true">https://en.wikipedia.org/wiki/Pooled_variance</a><br class="">
<br class="">
But I am not 100% happy with this pooled variance.<br class="">
First of all the deegrees of freedom is not accounted for. Then there is a different mean calculated than in ft_timelockgrandaverage: The mean is accounting for the number of trials for each subject. I don't know if the different mean is a pro or a con (On
 the one hand, means with a higher precisision because of a higher number of trials are weighted higher than means with a lower trial number. On the other hand, each subject on the group should be weighted same).<br class="">
<br class="">
I also found a second formula on stackexchange, which also calculates a variances of variances:<br class="">
<a href="https://urldefense.com/v3/__https://stats.stackexchange.com/questions/300392/calculate-the-variance-from-variances__;!!HJOPV4FYYWzcc1jazlU!4AKDCxWgDNOVGlWwimPV3Sc-5suVMj59sPhwC-eHwI7h0FQr10-YxE5fzliZsQft3R0I3s5Swpei12UfNPYgMdNHwshEvUdcUgTl6A$" class="">https://stats.stackexchange.com/questions/300392/calculate-the-variance-from-variances</a><br class="">
<br class="">
Therefore I am uncertain which formula to use, because as it seems, they differ.<br class="">
<br class="">
<br class="">
I hope somebody of you is a little more experienced in statistics than I am and can help me out finding the correct or best calculation for this variance. Best case would be if it is already implemented in fieldtrip and I only missed it, but I can also implement
 it myself.<span class="Apple-converted-space"> </span><br class="">
<br class="">
Best,<br class="">
Sebastian<br class="">
<br class="">
<br class="">
<br class="">
<br class="">
<br class="">
</div>
<br class="">
<p style="margin-top: 0px; margin-bottom: 0px;" class=""></p>
</div>
<span style="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; float: none; display: inline !important;" class="">_______________________________________________</span><br style="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;" class="">
<span style="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; float: none; display: inline !important;" class="">fieldtrip
 mailing list</span><br style="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;" class="">
<a href="https://mailman.science.ru.nl/mailman/listinfo/fieldtrip" style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">https://mailman.science.ru.nl/mailman/listinfo/fieldtrip</a><br style="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;" class="">
<a href="https://urldefense.com/v3/__https://doi.org/10.1371/journal.pcbi.1002202__;!!HJOPV4FYYWzcc1jazlU!4AKDCxWgDNOVGlWwimPV3Sc-5suVMj59sPhwC-eHwI7h0FQr10-YxE5fzliZsQft3R0I3s5Swpei12UfNPYgMdNHwshEvUdau-41SA$" style="font-family: Helvetica; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">https://urldefense.com/v3/__https://doi.org/10.1371/journal.pcbi.1002202__;!!HJOPV4FYYWzcc1jazlU!4AKDCxWgDNOVGlWwimPV3Sc-5suVMj59sPhwC-eHwI7h0FQr10-YxE5fzliZsQft3R0I3s5Swpei12UfNPYgMdNHwshEvUdau-41SA$</a><span style="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; float: none; display: inline !important;" class=""><span class="Apple-converted-space"> </span> </span></div>
</blockquote>
</div>
<br class="">
</div>
</body>
</html>