<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body><p><span style="padding: 3px 10px; border-radius: 5px; color: #ffffff; font-weight: bold; display: inline-block; background-color: #ff0000;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;External Email - Use Caution&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p><p></p>
    <p>RMS is indeed the same as SD *when* the mean is zero. But I'm not
      sure that's always the case in EEG, depending on which `picks` you
      have and what the reference is.</p>
    <p>There is also one more bit of fine print: the denominator for RMS
      is pretty clear, but the denominator for SD may have a degrees of
      freedom correction. So even if the case of zero mean, computing
      the RMS by hand vs. calling a library function for SD may yield
      different results depending on the library defaults for df. If I
      recall correctly, scipy.stats actually uses a different default
      than numpy....<br>
    </p>
    <p><br>
    </p>
    <p>On a related topic: the R function scale() has a big note on this
      in its documentation, because it allows for centering (subtracting
      the mean) and/or scaling (RMS) and the combination of these two
      flags creates straight centering, RMS, SD, or the identity
      transform.<br>
    </p>
    <p>Phillip<br>
    </p>
    <div class="moz-cite-prefix">On 23/7/20 12:17 pm, José C. García
      Alanis wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CAGU6uCxe07nf5+eYEeENBh18bASYYW9Fx0BU6cZ6jjw6gY6_Qg@mail.gmail.com">
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <p><span style="padding: 3px 10px; border-radius: 5px; color:
          #ffffff; font-weight: bold; display: inline-block;
          background-color: #ff0000;">        External Email - Use
          Caution        </span></p>
      <div dir="ltr">
        <div>Hey everybody, hey Christoph,</div>
        <div><br>
        </div>
        <div>I believe, in this case the result of the standard
          deviation (SD) and root mean square (RMS) approach should be
          roughly the same (if not the same).</div>
        <div>You are right, that the RMS computation makes no
          subtraction of the mean across channels as it would be the
          case for the standard deviation. However, if the mean is zero,
          then the difference of a value to the mean it's just the value
          itself (the mean of the signal evoked.data should be pretty
          close to zero). Thus, the results of the calculations should
          be equivalent. But I'm open for discussion if this assumption
          is wrong.<br>
        </div>
        <div><br>
        </div>
        <div>A quick snipped to test this assumption:<br>
        </div>
        <div><br>
        </div>
        <div>D = np.random.normal(0, 1, 1000)</div>
        <div>D.std()<br>
        </div>
        <div>0.9586524583070871</div>
        <div><br>
        </div>
        <div>np.sqrt((D * D).mean())<br>
          0.9586667427413401</div>
        <div><br>
        </div>
        <div>Roughly the same. The results should vary if you assume a
          mean != 0.</div>
        <div><br>
        </div>
        <div>Best,</div>
        <div>José<br>
        </div>
        <div><br>
        </div>
      </div>
      <div dir="ltr">
        <div dir="ltr"><br>
        </div>
        <br>
        <div class="gmail_quote">
          <div dir="ltr" class="gmail_attr">Am Do., 23. Juli 2020 um
            10:53 Uhr schrieb Christoph Huber-Huber &lt;<a
              href="mailto:christoph@huber-huber.at" target="_blank"
              moz-do-not-send="true">christoph@huber-huber.at</a>&gt;:<br>
          </div>
          <blockquote class="gmail_quote" style="margin:0px 0px 0px
            0.8ex;border-left:1px solid
            rgb(204,204,204);padding-left:1ex">
            <div>
              <p><span style="padding:3px
10px;border-radius:5px;color:rgb(255,255,255);font-weight:bold;display:inline-block;background-color:rgb(255,0,0)">        External
                  Email - Use Caution        </span></p>
              Hi list,
              <div><br>
              </div>
              <div>I recently came across that mne python uses 3
                different formulas for calculating global field power
                (GFP). I’m wondering why.</div>
              <div>They are:</div>
              <div><br>
              </div>
              <div>- The spatial standard deviation</div>
              <div>line 1492 of /mne/viz/utils.py</div>
              <div>gfp = evoked.data.std(axis=0)</div>
              <div>This is the original version as e.g. in Lehmann &amp;
                Skrandies (1980) <a
                  href="http://dx.doi.org/10.1016/0013-4694(80)90419-8"
                  target="_blank" moz-do-not-send="true">dx.doi.org/10.1016/0013-4694(80)90419-8</a></div>
              <div>Note that the fieldtrip folks write about global
                field power “The naming implies a squared measure but
                this is not the case.” (see help text of the
                FT_GLOBALMEANFIELD function of the fieldtrip toolbox).</div>
              <div><br>
              </div>
              <div>- Root mean square</div>
              <div>line 2988 of /mne/viz/utils.py</div>
              <div>combine_dict['gfp'] = lambda data: np.sqrt((data **
                2).mean(axis=1))</div>
              <div>There is no subtraction of the mean across channels
                as would be the case for standard deviation.</div>
              <div><br>
              </div>
              <div>- Again, root mean square</div>
              <div>line 466 of /mne/viz/evoked.py</div>
              <div>this_gfp = np.sqrt((D * D).mean(axis=0))<br>
                <br>
                - Sum of squares</div>
              <div>line 131 of
                /examples/time_frequency/plot_time_frequency_global_field_power.py</div>
              <div>gfp = np.sum(average.data ** 2, axis=0)<br>
                Here, we’re dealing with power values of a
                time-frequency decomposition, so that’s perhaps the
                reason for the missing mean and sqrt?</div>
              <div><br>
              </div>
              <div>The mne python glossary at /doc/glossary.rst
                describes GFP as “the standard deviation of the sensor
                values at each time point”, consistent with Lehmann
                &amp; Skrandies. That seems to be correct only for the
                first formula mentioned here.</div>
              <div><br>
              </div>
              <div>Any suggestions for the reasons of when to use which
                version and educated guesses of whether these
                differences matter in practice are highly welcome.</div>
              <div><br>
              </div>
              <div>Thank you very much,</div>
              <div>Christoph</div>
            </div>
            _______________________________________________<br>
            Mne_analysis mailing list<br>
            <a href="mailto:Mne_analysis@nmr.mgh.harvard.edu"
              target="_blank" moz-do-not-send="true">Mne_analysis@nmr.mgh.harvard.edu</a><br>
            <a
              href="https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis"
              rel="noreferrer" target="_blank" moz-do-not-send="true">https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis</a></blockquote>
        </div>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <pre class="moz-quote-pre" wrap="">_______________________________________________
Mne_analysis mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Mne_analysis@nmr.mgh.harvard.edu">Mne_analysis@nmr.mgh.harvard.edu</a>
<a class="moz-txt-link-freetext" href="https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis">https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis</a></pre>
    </blockquote>
  </body>
</html>