[Mne_analysis] [Freesurfer] question about how to calculate COV for MNE

Alexandre Gramfort alexandre.gramfort at telecom-paristech.fr
Tue Apr 8 04:25:26 EDT 2014
Search archives:

hi Joe,

> 1) Given how whitening is conducted, the reference choice would be critical.
> I want to make sure that when my software writes out the COV information to
> the -cov.fif file, that it is doing it correctly.  How is referencing being
> handled?  For example, is the COV info always average referenced even if the
> data accompanying it has not been average referenced yet?  Or is it always
> in the current referencing scheme with the reference info sent along
> separately so it can be taken into account later?  Or what?

MNE works only with averaged reference EEG. The average ref can be
computed with a PCA/SSP proj so it's transparent in the MNE pipeline.

I'll let somebody else answer for the rest or try to find some time later.

Alex

> 2) I also see part of what was confusing me.  It sounded as though 4.17 was
> for when one is averaging data together whereas 6.3 is for when one is
> subtracting or summing.  So when combining subject averages together into a
> grand average, one would use the 4.17 procedure, which quite rightly made no
> sense to me.  Instead, 4.17 is intended for the situation where ideally only
> noise is present and the goal is to just weight the estimates of noise
> according to their quality (the number of observations used to generate
> them) when combining them, which in the case of two perfect COV estimates of
> noise will not change when combined together (still perfect).
>
> So I understand 4.17 now.  I am still wrestling with how 6.3 is to be
> applied.  My understanding is that when one adds or subtracts two epochs
> with nothing but random noise, the noise level does not change.  If anything
> the noise level (variance over the epoch) increases as I just demonstrated
> to myself with an Excel spreadsheet.  The noise level improvement only
> occurs when one takes the average of the epochs and is well known in the EEG
> field to occur following a square root of the number of observations
> involved.
>
> So what situation is 6.3 intended for?  It seems to indicate that if one
> takes a difference wave (say ERP to incongruent word minus congruent word)
> then one should calculate Leff as described and then obtain the new COV by
> dividing the original COV (C-zero) by Leff.  Given the previous paragraph,
> this procedure doesn't make sense to me since the noise level (as measured
> by COV) should not be decreasing.  So I'm clearly still missing something.
>
> From a practical perspective, I'm asking because I want to make sure my
> software generates the correct COV for difference waves.
>
> Respectfully,
>
> Joe
>
>
>
> On Apr 7, 2014, at 10:01 AM, Hari Bharadwaj <hari at nmr.mgh.harvard.edu>
> wrote:
>
> Hi Joe,
>     Thought I'll mention a couple of things that might help understand the
> scaling etc.
>
> (1) the noise cov that is computed and stored in the -cov.fif files
> corresponds to the covariance of the measurement noise in the *raw* data and
> hence when using it to localize multitrial *averaged* evoked responses, it
> is scaled by the number of trials in the average (based on the assumption
> that noise is independent from trial to trial and hence scales that way)..
> Look for the "nave" input when generating "stc" files.
>
> (2) whether you add or subtract two *average* evoked responses, the
> resulting noise distribution is the same (i.e., still mean zero and variance
> depending on the numbers of trials in each condition).. More generally when
> you take an arbitrary linear combination of two or more averaged responses,
> the mean is still zero for the noise and the variance scales depending of
> the weights for each condition and numbers of trials that went into the
> corresponding averages.
>
> (3) based on (2), considering the common special case of a difference
> response of two (separately averaged) conditions, if the number of trials in
> each of the two conditions that went in were not the same and are instead L1
> and L2 respectively, then the effective scaling of the noise (from raw to
> the difference waveform) variance is what is calculated as Leff.
>
> HTH,
> Hari
>
>
> Hari Bharadwaj
> PhD Candidate, Biomedical Engineering,
> Auditory Neuroscience Laboratory
> Boston University, Boston, MA 02215
>
> Martinos Center for Biomedical Imaging,
> Massachusetts General Hospital
> Charlestown, MA 02129
>
> hari at nmr.mgh.harvard.edu
> Ph: 734-883-5954
>
> On Apr 6, 2014, at 11:40 PM, Joseph Dien <jdien07 at mac.com> wrote:
>
> I should say Python, not C++...
>
> On Apr 6, 2014, at 11:31 PM, Joseph Dien <jdien07 at mac.com> wrote:
>
> Fair enough!  Just trying to understand what Section 6.3 is trying to
> communicate.  So let me try another possible interpretation:
>
> Compute the COV for the two conditions.  When subtracting the two
> conditions, the accompanying COV matrix (same for both conditions since they
> were pooled when computing it) is divided by Leff.  Likewise the
> accompanying degrees of freedom (used if it is subsequently averaged
> together with another COV matrix per Section 4.17) is set equal to Leff.
>
> Not saying this is a procedure that makes sense to me either, just asking
> what the intent is of the MNE developers.  Based on your response, this is
> currently my best guess, although it doesn't make sense to me either since
> dividing the COV matrix by a single scalar (however computed) shouldn't
> affect computations about relative noise levels in the channels.  Basically,
> I'm not sure what is being done with COV so it's hard for me to judge what
> is a reasonable interpretation of Section 6.3.
>
> I appreciate the link to the code, but since I'm a Matlab programmer not a
> C++ programmer, it's very hard for me to parse the code.  If someone could
> just tell me what is to be done according to 6.3 when computing a difference
> wave rather than just what not to do, this would be greatly appreciated.
> I'm trying to add support for FIFF file format to my Matlab EEG software
> analysis suite (http://sourceforge.net/projects/erppcatoolkit/) and want to
> make sure I'm doing it in a manner that would be acceptable to the MNE
> developers, for the benefit of the users of my package.
>
> Thanks for taking the time to read my question!
>
> Joe
>
>
>
> On Apr 5, 2014, at 5:51 AM, Alexandre Gramfort
> <alexandre.gramfort at telecom-paristech.fr> wrote:
>
> hi joe,
>
>   I have a question about how to calculate the COV for the MNE software.
> As I understand it from Section 4.17 of the 2.7.3 MNE manual, if one is
> averaging together COV matrices, one weights them by the number of
> observations going into each one.  I also see from Section 4.17.2 that these
> are technically not covariance matrices so much as sum-of-squares matrices
> where the epochs going into each variable has been baseline corrected.
>
>   Assuming my understanding so far is correct, my question is about how to
> proceed when making linear combinations of COV matrices, as in a difference
> wave, as discussed in Section 6.3.  Would the following be the correct
> procedure?
>
>   Compute the COV separately for the two conditions (say standard and rare
> oddballs).  Subtract the two COV matrices to obtain C0.
>
>
> Subtracting two COV matrices is a bad idea. You can make the new cov
> non positive.
>
> basically the noise cov is just to estimate the noise so any sample you use
> to get a better estimate the better. There is no condition or contrast
> at this stage.
>
> for source reconstruction you should use the same noise cov for the two
> conditions to have the same inverse operator.
>
> you can look at this file to know more about the internals:
>
> https://github.com/mne-tools/mne-python/blob/master/mne/cov.py
>
> HTH
> Alex
>
>
> Then calculate C by
> dividing by Leff, which in turn is calculated as Leff= (L1*L2)/(L1+L2) where
> L1 is the number of observations in the first COV matrix and L2 is for the
> second.
>
>   But if done in this way, the two COV matrices would not be weighted by
> their relative sample sizes.  So would I also weight them by L1 and L2
> during the subtraction, as done for averaging per 4.17?  But then what is
> the purpose of the Leff calculation? Or is the idea that one would calculate
> a single COV based on both conditions and then one would modify COV by Leff
> to reflect that the signal-to-noise ratio has been reduced by combining two
> averages with differing sample sizes?  But in the case where both samples
> equal, say, 10, Leff would end up equalling 100/20=5.  Dividing C by 5 seems
> like too much.  Anyway, very confused.  Any guidance would be appreciated.
>
> Respectfully,
>
> Joe
>
>
>
>
> --------------------------------------------------------------------------------
>
> Joseph Dien,
> Senior Research Scientist
> Maryland Neuroimaging Center
> University of Maryland
>
> E-mail: jdien07 at mac.com
> Phone: 202-297-8117
> http://joedien.com
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> _______________________________________________
> Freesurfer mailing list
> Freesurfer at nmr.mgh.harvard.edu
> https://mail.nmr.mgh.harvard.edu/mailman/listinfo/freesurfer
>
>
> The information in this e-mail is intended only for the person to whom it is
> addressed. If you believe this e-mail was sent to you in error and the
> e-mail
> contains patient information, please contact the Partners Compliance
> HelpLine at
> http://www.partners.org/complianceline . If the e-mail was sent to you in
> error
> but does not contain patient information, please contact the sender and
> properly
> dispose of the e-mail.
>
> _______________________________________________
> Mne_analysis mailing list
> Mne_analysis at nmr.mgh.harvard.edu
> https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis
>
>
>
> --------------------------------------------------------------------------------
>
> Joseph Dien,
> Senior Research Scientist
> Maryland Neuroimaging Center
> University of Maryland
>
> E-mail: jdien07 at mac.com
> Phone: 202-297-8117
> http://joedien.com
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> --------------------------------------------------------------------------------
>
> Joseph Dien,
> Senior Research Scientist
> Maryland Neuroimaging Center
> University of Maryland
>
> E-mail: jdien07 at mac.com
> Phone: 202-297-8117
> http://joedien.com
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> _______________________________________________
> Mne_analysis mailing list
> Mne_analysis at nmr.mgh.harvard.edu
> https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis
>
>
>
> --------------------------------------------------------------------------------
>
> Joseph Dien,
> Senior Research Scientist
> Maryland Neuroimaging Center
> University of Maryland
>
> E-mail: jdien07 at mac.com
> Phone: 202-297-8117
> http://joedien.com
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> _______________________________________________
> Mne_analysis mailing list
> Mne_analysis at nmr.mgh.harvard.edu
> https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne_analysis
>
>
> The information in this e-mail is intended only for the person to whom it is
> addressed. If you believe this e-mail was sent to you in error and the
> e-mail
> contains patient information, please contact the Partners Compliance
> HelpLine at
> http://www.partners.org/complianceline . If the e-mail was sent to you in
> error
> but does not contain patient information, please contact the sender and
> properly
> dispose of the e-mail.
>



More information about the Mne_analysis mailing list