# Epoch mode covariance estimation

**URL:** <https://mne.discourse.group/t/epoch-mode-covariance-estimation/491>\
**Category:** Mailing List Archive (read-only)\
**Tags:** list-archive\
**Created:** [September 14, 2012, 12:18am UTC](https://mne.discourse.group/t/epoch-mode-covariance-estimation/491 "2012-09-14T00:18:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [September 14, 2012, 12:18am UTC](https://mne.discourse.group/t/epoch-mode-covariance-estimation/491/1 "2012-09-14T00:18:49Z")

</div>

Hi all,  
I wonder if someone could clarify a detail concerning the calculation of  
the covariance matrix in epoch mode when the KEEPSAMPLEMEAN option is  
specified.  
On page 89 of the MNE manual (version 2.7.3) the formulation for the  
covariance matrix is unclear on the limit of the sum of samples (j). My  
question is whether the limit is the number of samples (Nr) in the  
entire epoch, or just the baseline/pre-stimulus period?

Thanks  
Kambiz

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [September 14, 2012, 7:28am UTC](https://mne.discourse.group/t/epoch-mode-covariance-estimation/491/2 "2012-09-14T07:28:10Z")

</div>

hi Kambiz,

you can take a look at the python function for this:

[https://github.com/mne-tools/mne-python/blob/master/mne/cov.py#L240](https://github.com/mne-tools/mne-python/blob/master/mne/cov.py#L240)

it reproduces the C code.

HTH

Alex

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/free1/uploads/mne/original/1X/85cc6bd2b69cb698a166dc6d880fb550510d0144.jpeg) [@system](https://mne.discourse.group/u/system)\
**Post date:** [September 14, 2012, 12:57pm UTC](https://mne.discourse.group/t/epoch-mode-covariance-estimation/491/3 "2012-09-14T12:57:56Z")

</div>

Hi Kambiz,

To clarify on the different parameters..

"tmin" and "tmax" should reflect whatever period of the data you want to  
consider as noise. "bmin" and "bmax" are the period whose DC offset is  
removed from the data. What period you want to consider noise depends on  
what the data and analyses are.

If 'keepsamplemean' is NOT set, the average over trials of each point is  
removed i.e if you were to plot the average over trials as a function of  
time, it would be flat zero between tmin and tmax after the operation..  
Setting the 'keepsamplemean' reflects the assumption that the true sample  
by sample mean in the tmin to tmax period is zero at the population level  
(i.e if you have infinite #trials day) but not forced on the average over  
the finite #trials that you have. So whenever that assumption is not  
good, not setting 'keepsamplemean' will help avoid overestminating the  
covariance. For instance, from the manual: "Subtraction of the means at  
individual samples is useful if it can be expected that the evoked  
response from previous stimulus extends to part of baseline period of the  
next one."

Regards,  
Hari
