# threshold\_muscle value when removing muscular artifacts?

**URL:** <https://mne.discourse.group/t/threshold-muscle-value-when-removing-muscular-artifacts/3842>\
**Category:** Support & Discussions\
**Tags:** preprocessing\
**Created:** [October 20, 2021, 9:44pm UTC](https://mne.discourse.group/t/threshold-muscle-value-when-removing-muscular-artifacts/3842 "2021-10-20T21:44:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![PaulF](https://avatars.discourse-cdn.com/v4/letter/p/eb9ed0/32.png) [@PaulF](https://mne.discourse.group/u/PaulF)\
**Post date:** [October 20, 2021, 9:44pm UTC](https://mne.discourse.group/t/threshold-muscle-value-when-removing-muscular-artifacts/3842/1 "2021-10-20T21:44:21Z")

</div>

- MNE-Python version: 0.23
- operating system: Mac OS 11.3.1, Python 3.9

I’ve reproduced the exact graph shown at [Annotate muscle artifacts — MNE 0.21.2 documentation](https://mne.tools/0.21/auto_examples/preprocessing/plot_muscle_detection.html), which depicts z-score as a function of time.

I’m still wondering about the heuristic for setting threshold\_muscle. I computed the mean and standard deviation of `scores_muscle` and the y-value of the red line is approximately the mean plus two standard deviations. Is using the mean plus some multiple of the standard deviation a reasonable approach for setting the threshold?

---

<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:** [October 21, 2021, 7:56am UTC](https://mne.discourse.group/t/threshold-muscle-value-when-removing-muscular-artifacts/3842/2 "2021-10-21T07:56:27Z")

</div>

Hello @PaulF,

I don’t know of a general threshold that would work for **all** datasets. The [documentation](https://mne.tools/stable/auto_examples/preprocessing/muscle_detection.html) suggests:

```python

# The threshold is data dependent, check the optimal threshold by plotting
# ``scores_muscle``.

```

The default threshold is set to 4, which seems to be reasonable for many use cases. But whether it makes sense for **you** or if you need to adjust it can only be decided by actually looking at the data.

Best wishes,  
Richard

---

<div class="post-metadata">

**Author:** ![TijmenWartenberg](https://yyz2.discourse-cdn.com/free1/user_avatar/mne.discourse.group/tijmenwartenberg/32/913_2.png) [@TijmenWartenberg](https://mne.discourse.group/u/TijmenWartenberg)\
**Post date:** [October 28, 2021, 12:59pm UTC](https://mne.discourse.group/t/threshold-muscle-value-when-removing-muscular-artifacts/3842/3 "2021-10-28T12:59:09Z")

</div>

The default threshold is already normalized as a way of z-score (# standard deviations basically).

Putting the Z score criterion too low results in a high number of false positives for clean datasets and a high number of true positives for noisier datasets.  
Putting the Z score criterion too high results in a low\* number of false positives for clean datasets and a low number of true positives for noisier datasets.

So to generalize this value is hard, but I still do this.

My solution is to be quite conservative with the value (Z-score of 4 is fine though), but to put a minimal requirement on the length of the bad segment to rule out spurious false positives.

```python
  for a, annotation in enumerate(annot_muscle):
        if annotation['duration']<0.3:
            remove.append(a)
            
    annot_muscle.delete(remove)

```

---

<div class="post-metadata">

**Author:** ![PaulF](https://avatars.discourse-cdn.com/v4/letter/p/eb9ed0/32.png) [@PaulF](https://mne.discourse.group/u/PaulF)\
**Post date:** [October 28, 2021, 2:17pm UTC](https://mne.discourse.group/t/threshold-muscle-value-when-removing-muscular-artifacts/3842/4 "2021-10-28T14:17:13Z")

</div>

Thanks much. I’ll keep this in mind!
