# covariance with 'auto' option

**URL:** <https://mne.discourse.group/t/covariance-with-auto-option/1098>\
**Category:** Mailing List Archive (read-only)\
**Tags:** list-archive\
**Created:** [October 18, 2016, 8:21am UTC](https://mne.discourse.group/t/covariance-with-auto-option/1098 "2016-10-18T08:21:49Z")\
**Posts on this page:** 6\
**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:** [October 18, 2016, 8:21am UTC](https://mne.discourse.group/t/covariance-with-auto-option/1098/1 "2016-10-18T08:21:49Z")

</div>

Hello,

I calculated noise covariance matrix on baseline using method=?auto? to  
find an optimal regularization:

cov = mne.compute\_covariance(covepochs, method= ?auto? , tmin=None,  
tmax=None , verbose=True)

The optimal was ?factor analysis?, but it gave me unacceptable solution.

When I look at whitening, it seems that ?shrunk? works better (see the  
figures attached)! What can be the problem?

Elena  
-------------- next part --------------  
An HTML attachment was scrubbed...  
URL: [http://mail.nmr.mgh.harvard.edu/pipermail/mne\_analysis/attachments/20161018/404a633b/attachment-0001.html](http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20161018/404a633b/attachment-0001.html)  
-------------- next part --------------  
A non-text attachment was scrubbed...  
Name: cov\_factoranalysis.png  
Type: image/png  
Size: 89801 bytes  
Desc: not available  
Url : [http://mail.nmr.mgh.harvard.edu/pipermail/mne\_analysis/attachments/20161018/404a633b/attachment-0002.png](http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20161018/404a633b/attachment-0002.png)  
-------------- next part --------------  
A non-text attachment was scrubbed...  
Name: cov\_shrunk.png  
Type: image/png  
Size: 74563 bytes  
Desc: not available  
Url : [http://mail.nmr.mgh.harvard.edu/pipermail/mne\_analysis/attachments/20161018/404a633b/attachment-0003.png](http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20161018/404a633b/attachment-0003.png)

---

<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:** [October 18, 2016, 8:31am UTC](https://mne.discourse.group/t/covariance-with-auto-option/1098/2 "2016-10-18T08:31:09Z")

</div>

Hi Elena,

It looks like you are the entire time window? If you do this because you  
have cropped epochs for the purpose of cov estimation then the idea of this  
plot is to inspect the data segments that were not part of the window used  
for cov estimation.  
The plot further suggest that you are using data processed with SSS which  
are rank deficient. Factor Analysis is not expected to work well. For SSS  
the "shrunk" option should do a good job. I would run it with  
method=('empirical', 'shrunk') and return the estimators (see parameter) to  
compare them. One should always compare the fancier estimators with the  
empirical covariance. In that case you would pass a list of covariance  
objects to the plot\_white method which will then show you one time series  
per covariance.

I hope this helps,  
Denis

---

<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:** [October 18, 2016, 9:09am UTC](https://mne.discourse.group/t/covariance-with-auto-option/1098/3 "2016-10-18T09:09:57Z")

</div>

Thank you Denis, it was helpful!

I tried it with

cov = mne.compute\_covariance(allepochs, method=['empirical', 'shrunk'] ,  
tmin=-0.8, tmax=0.0 , return\_estimators=True, verbose=True)

The best was the ?shrunk?. However, the GFP is lower then 1 for the  
?shrunk? and is close to 1 for ?empirical? (see the figure). Is it OK?

Elena

> Hi Elena,
> 
> It looks like you are the entire time window? If you do this because you  
> have cropped epochs for the purpose of cov estimation then the idea of this  
> plot is to inspect the data segments that were not part of the window used  
> for cov estimation.  
> The plot further suggest that you are using data processed with SSS which  
> are rank deficient. Factor Analysis is not expected to work well. For SSS  
> the "shrunk" option should do a good job. I would run it with  
> method=('empirical', 'shrunk') and return the estimators (see parameter) to  
> compare them. One should always compare the fancier estimators with the  
> empirical covariance. In that case you would pass a list of covariance  
> objects to the plot\_white method which will then show you one time series  
> per covariance.
> 
> I hope this helps,  
> Denis
> 
> > Hello,
> > 
> > I calculated noise covariance matrix on baseline using method=?auto? to  
> > find an optimal regularization:
> > 
> > cov = mne.compute\_covariance(covepochs, method= ?auto? , tmin=None,  
> > tmax=None , verbose=True)
> > 
> > The optimal was ?factor analysis?, but it gave me unacceptable solution.
> > 
> > When I look at whitening, it seems that ?shrunk? works better (see the  
> > figures attached)! What can be the problem?
> > 
> > Elena  
> > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > Mne\_analysis mailing list  
> > Mne\_analysis at nmr.mgh.harvard.edu  
> > [Mne\_analysis Info Page](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  
> > [MyComplianceReport.com: Compliance and Ethics Reporting](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  
> [Mne\_analysis Info Page](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  
> [MyComplianceReport.com: Compliance and Ethics Reporting](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.

-------------- next part --------------  
An HTML attachment was scrubbed...  
URL: [http://mail.nmr.mgh.harvard.edu/pipermail/mne\_analysis/attachments/20161018/49b06f28/attachment-0001.html](http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20161018/49b06f28/attachment-0001.html)  
-------------- next part --------------  
A non-text attachment was scrubbed...  
Name: cov\_shrunk\_and\_empirical.png  
Type: image/png  
Size: 49779 bytes  
Desc: not available  
Url : [http://mail.nmr.mgh.harvard.edu/pipermail/mne\_analysis/attachments/20161018/49b06f28/attachment-0001.png](http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20161018/49b06f28/attachment-0001.png)

---

<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:** [October 18, 2016, 9:44am UTC](https://mne.discourse.group/t/covariance-with-auto-option/1098/4 "2016-10-18T09:44:27Z")

</div>

That looks already much better 🙂  
The whitened butterfly plot on the other hand looks good.  
How does this butterfly plot look like for the empirical covariance?  
It's generally not always easy to understand what is behind such scaling  
issues as this diagnostic plot is very sensitive to subtle model  
violations. That shrunk is selected means that it has for mathematical  
reasons the better properties as an estimator of the covariance of unseen  
data, to be preferred over the plot in case of doubt. For the GFP plot  
subtle differences in rank estimates can also lead to wrong scaling. Is  
your actual number of SSS components 74 as displayed in the plot?

Denis

---

<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:** [October 18, 2016, 11:10am UTC](https://mne.discourse.group/t/covariance-with-auto-option/1098/5 "2016-10-18T11:10:29Z")

</div>

> How does this butterfly plot look like for the empirical covariance?

It looks pretty much the same as the 'shrunk' (attached).

> Is your actual number of SSS components 74 as displayed in the plot?

If I do

rank = raw.estimate\_rank(tstart=0.0, tstop=None, tol=0.0001,  
return\_singular=False, picks=None, scalings='norm')

rank =74

Elena

> That looks already much better 🙂  
> The whitened butterfly plot on the other hand looks good.  
> How does this butterfly plot look like for the empirical covariance?  
> It's generally not always easy to understand what is behind such scaling  
> issues as this diagnostic plot is very sensitive to subtle model  
> violations. That shrunk is selected means that it has for mathematical  
> reasons the better properties as an estimator of the covariance of unseen  
> data, to be preferred over the plot in case of doubt. For the GFP plot  
> subtle differences in rank estimates can also lead to wrong scaling. Is  
> your actual number of SSS components 74 as displayed in the plot?
> 
> Denis
> 
> > Thank you Denis, it was helpful!
> > 
> > I tried it with
> > 
> > cov = mne.compute\_covariance(allepochs, method=['empirical', 'shrunk'] ,  
> > tmin=-0.8, tmax=0.0 , return\_estimators=True, verbose=True)
> > 
> > The best was the ?shrunk?. However, the GFP is lower then 1 for the  
> > ?shrunk? and is close to 1 for ?empirical? (see the figure). Is it OK?
> > 
> > Elena
> > 
> > Hi Elena,
> > 
> > It looks like you are the entire time window? If you do this because you  
> > have cropped epochs for the purpose of cov estimation then the idea of this  
> > plot is to inspect the data segments that were not part of the window used  
> > for cov estimation.  
> > The plot further suggest that you are using data processed with SSS which  
> > are rank deficient. Factor Analysis is not expected to work well. For SSS  
> > the "shrunk" option should do a good job. I would run it with  
> > method=('empirical', 'shrunk') and return the estimators (see parameter) to  
> > compare them. One should always compare the fancier estimators with the  
> > empirical covariance. In that case you would pass a list of covariance  
> > objects to the plot\_white method which will then show you one time series  
> > per covariance.
> > 
> > I hope this helps,  
> > Denis
> > 
> > Hello,
> > 
> > I calculated noise covariance matrix on baseline using method=?auto? to  
> > find an optimal regularization:
> > 
> > cov = mne.compute\_covariance(covepochs, method= ?auto? , tmin=None,  
> > tmax=None , verbose=True)
> > 
> > The optimal was ?factor analysis?, but it gave me unacceptable solution.
> > 
> > When I look at whitening, it seems that ?shrunk? works better (see the  
> > figures attached)! What can be the problem?
> > 
> > Elena  
> > \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
> > Mne\_analysis mailing list  
> > Mne\_analysis at nmr.mgh.harvard.edu  
> > [https://mail.nmr.mgh.harvard.edu/mailman/listinfo/mne\_analysis](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](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](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](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](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](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](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](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.

-------------- next part --------------  
An HTML attachment was scrubbed...  
URL: [http://mail.nmr.mgh.harvard.edu/pipermail/mne\_analysis/attachments/20161018/c3a6f34d/attachment-0001.html](http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20161018/c3a6f34d/attachment-0001.html)  
-------------- next part --------------  
A non-text attachment was scrubbed...  
Name: cov\_empirical.png  
Type: image/png  
Size: 62453 bytes  
Desc: not available  
Url : [http://mail.nmr.mgh.harvard.edu/pipermail/mne\_analysis/attachments/20161018/c3a6f34d/attachment-0001.png](http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20161018/c3a6f34d/attachment-0001.png)

---

<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:** [October 18, 2016, 4:01pm UTC](https://mne.discourse.group/t/covariance-with-auto-option/1098/6 "2016-10-18T16:01:26Z")

</div>

Hum this is interesting. I'm not sure what is making the shrunk cov look  
underfitting here. On the butterfly it looks good on top of that. I would  
need to play with the data to better understand what maybe going on but I  
have little time at this point. It seems anyways that you have good amounts  
of data and the regularized covariance is not so different from the  
empirical one. As long as the butterfly plot looks ok you should be safe  
and trust the result that is based on the negative loglikelihood. Out of  
curiosity, how many trials do you have, what is the sampling frequency and  
did you check with other recordings?

I hope this helps,  
Denis
