# Trying to understand the lambda2 parameter in mne.minimum\_norm.apply\_inverse\_raw

**URL:** <https://mne.discourse.group/t/trying-to-understand-the-lambda2-parameter-in-mne-minimum-norm-apply-inverse-raw/6764>\
**Category:** Support & Discussions\
**Tags:** ﻿source-localization, eeg\
**Created:** [April 20, 2023, 5:49am UTC](https://mne.discourse.group/t/trying-to-understand-the-lambda2-parameter-in-mne-minimum-norm-apply-inverse-raw/6764 "2023-04-20T05:49:31Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![neurothew](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/neurothew/32/682_2.png) [@neurothew](https://mne.discourse.group/u/neurothew)\
**Post date:** [April 20, 2023, 5:49am UTC](https://mne.discourse.group/t/trying-to-understand-the-lambda2-parameter-in-mne-minimum-norm-apply-inverse-raw/6764/1 "2023-04-20T05:49:31Z")

</div>

- MNE version: e.g. 1.3.1
- operating system: e.g. Windows 10

Hi, I am trying to conduct source localization using individual T1 MRI scan. I have done computing the forward operator and inverse operator. As I am following the tutorial [Source localization with MNE, dSPM, sLORETA, and eLORETA — MNE 1.3.1 documentation](https://mne.tools/stable/auto_tutorials/inverse/30_mne_dspm_loreta.html), I have a question on the following snippet:

```python
method = "dSPM"
snr = 3.
lambda2 = 1. / snr ** 2
stc, residual = apply_inverse(evoked, inverse_operator, lambda2,
                              method=method, pick_ori=None,
                              return_residual=True, verbose=True)

```

I am wondering how should we determine the SNR here? For noise covariance, since I am operating on resting-state EEG, I used `make_ad_hoc_cov` with default parameter (std = 0.2 uV for EEG). Is this related to the SNR shown above? If not, how should I determine the SNR, and the corresponding lambda2?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [April 20, 2023, 7:31am UTC](https://mne.discourse.group/t/trying-to-understand-the-lambda2-parameter-in-mne-minimum-norm-apply-inverse-raw/6764/2 "2023-04-20T07:31:47Z")

</div>

Hello! This is a recurring question, and the answer – albeit maybe unsatisfactory to you – is that you should simply assume an SNR of 3 for averaged and 1 for non-averaged data:

> [@Estimating the regularization parameter for HCP MEG resting state source reconstruction](https://mne.discourse.group/t/estimating-the-regularization-parameter-for-hcp-meg-resting-state-source-reconstruction/5177/15):
>
> @Dominik I just asked @agramfort about this while we were fighting with the coffee machine (spoiler: we won! muscle coffee) He said this parameter (SNR of 3 for averaged, 1 for non-averaged data) “was established by Matti Hämäläinen 20 years ago”, and that “no one touches this parameter”. Hence … I would say, case closed. wink Best wishes, Richard

Best wishes,  
Richard

---

<div class="post-metadata">

**Author:** ![neurothew](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/neurothew/32/682_2.png) [@neurothew](https://mne.discourse.group/u/neurothew)\
**Post date:** [April 20, 2023, 9:20am UTC](https://mne.discourse.group/t/trying-to-understand-the-lambda2-parameter-in-mne-minimum-norm-apply-inverse-raw/6764/3 "2023-04-20T09:20:00Z")

</div>

Hi Richard,

Thanks a lot for your prompt reply. I also find from Brainstorm’s documentation that SNR of 3 is a recommendation from Hämäläinen although I am still trying to locate the corresponding paper. I am also trying to look on how this SNR is being calculated, do you know if I can calculate easily by myself with the raw data?

Another problem is, as I used `make_ad_hoc_cov` with default parameter. When I used the `raw.plot(noise_cov=noise_cov, butterfly=True)` to plot the whitened data, I found that the range of amplitude fluctuation of my signal went from 40uV (before whitening) to 600uV (after whitening), I think this should be abnormal? Will you have some ideas on why this happen and what should be the normal behaviour? Thanks a lot !

Best,  
Matthew

---

<div class="post-metadata">

**Author:** ![neurothew](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/neurothew/32/682_2.png) [@neurothew](https://mne.discourse.group/u/neurothew)\
**Post date:** [April 20, 2023, 4:29pm UTC](https://mne.discourse.group/t/trying-to-understand-the-lambda2-parameter-in-mne-minimum-norm-apply-inverse-raw/6764/4 "2023-04-20T16:29:04Z")

</div>

I think I kind of understand what happened. If I am setting the noise covariance to a ad-hoc matrix with 0.2uV std for each channel, essentially the whitening just divide each channel by the std, thus making the amplitude fluctuation much larger.

However, I am unsure if it is considered “normal” behaviour. In this case (resting-state EEG), shouldn’t we just compute the standard deviation of each channel, and use them to construct the noise covariance?

---

<div class="post-metadata">

**Author:** ![drammock](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/drammock/32/4_2.png) [@drammock](https://mne.discourse.group/u/drammock)\
**Post date:** [April 20, 2023, 4:54pm UTC](https://mne.discourse.group/t/trying-to-understand-the-lambda2-parameter-in-mne-minimum-norm-apply-inverse-raw/6764/5 "2023-04-20T16:54:29Z")

</div>

> [@neurothew](#):
>
> shouldn’t we just compute the standard deviation of each channel, and use them to construct the noise covariance?

Try [mne.compute\_raw\_covariance — MNE 1.6.0 documentation](https://mne.tools/stable/generated/mne.compute_raw_covariance.html)

ad-hoc covariance is I think mainly for cases like simulated data.

---

<div class="post-metadata">

**Author:** ![neurothew](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/neurothew/32/682_2.png) [@neurothew](https://mne.discourse.group/u/neurothew)\
**Post date:** [April 20, 2023, 5:01pm UTC](https://mne.discourse.group/t/trying-to-understand-the-lambda2-parameter-in-mne-minimum-norm-apply-inverse-raw/6764/6 "2023-04-20T17:01:21Z")

</div>

@drammock yea I also noticed this function. I think that it is suitable for MEG which can collect empty room data, or for ERP analysis as there is usually a pre-stimulus baseline. Do you think it is suitable for resting-state EEG too?

I am hesitating as I notice that there is a thread [noise covariance matrix in resting state eeg data - 💬 Support & Discussions - MNE Forum](https://mne.discourse.group/t/noise-covariance-matrix-in-resting-state-eeg-data/5788) which the `make_ad_hoc_cov` was recommended.

---

<div class="post-metadata">

**Author:** ![drammock](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/drammock/32/4_2.png) [@drammock](https://mne.discourse.group/u/drammock)\
**Post date:** [April 20, 2023, 5:14pm UTC](https://mne.discourse.group/t/trying-to-understand-the-lambda2-parameter-in-mne-minimum-norm-apply-inverse-raw/6764/7 "2023-04-20T17:14:46Z")

</div>

Ah, OK, I should have read your question more closely. I think your’e right when you say that

> [@neurothew](#):
>
> I think I kind of understand what happened. If I am setting the noise covariance to a ad-hoc matrix with 0.2uV std for each channel, essentially the whitening just divide each channel by the std, thus making the amplitude fluctuation much larger.

I think the question to ask is why do you want/need to whiten the data? If I understand correctly, using an ad-hoc covariance with default settings will not actually do any whitening (because it’s a diagonal matrix with identical values along the diagonal, so it won’t capture any actual covariance between the channels, nor will it account for differences in noise level between channels). So if you actually need the data to be whitened you’ll need to either (1) pick a “baseline” period (might be arbitrary, or maybe there are reasons to prefer early, middle, or late portions of the recording?) or (2) find some way to create an ad-hoc covariance that is at least somewhat better than the default settings (maybe by doing some cross-subject aggregation of data covariances?)

But since I’m not an expert in resting-state I think @larsoner’s comment in the other thread is the best advice:

> [@noise covariance matrix in resting state eeg data](https://mne.discourse.group/t/noise-covariance-matrix-in-resting-state-eeg-data/5788/6):
>
> I’d recommend looking at recent resting-state EEG papers to see what they use as a noise covariance. I’d expect most papers with source localization to have some definition of a noise covariance matrix.

---

<div class="post-metadata">

**Author:** ![richard](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/richard/32/15_2.png) [@richard](https://mne.discourse.group/u/richard)\
**Post date:** [April 20, 2023, 5:19pm UTC](https://mne.discourse.group/t/trying-to-understand-the-lambda2-parameter-in-mne-minimum-norm-apply-inverse-raw/6764/8 "2023-04-20T17:19:23Z")

</div>

I’m quite positive that @Denis added support for ad-hoc covariance to MNE-BIDS-Pipeline specifically to process resting-state EEG data. I’m not familiar with any theoretical underpinnings of this approach, though.

“Raw” covariance is what we use for empty-room data.

Best wishes,  
Richard
