# single trial dSPM plots

**URL:** <https://mne.discourse.group/t/single-trial-dspm-plots/715>\
**Category:** Mailing List Archive (read-only)\
**Tags:** list-archive\
**Created:** [April 21, 2014, 7:08pm UTC](https://mne.discourse.group/t/single-trial-dspm-plots/715 "2014-04-21T19:08:20Z")\
**Posts on this page:** 10\
**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:** [April 21, 2014, 7:08pm UTC](https://mne.discourse.group/t/single-trial-dspm-plots/715/1 "2014-04-21T19:08:20Z")

</div>

How should I scale single trial dspm timecourses (from a label) so they can  
be plotted together with the average across trials? Currently, my average  
across trials looks good, but the single trials don't seem to match the  
average, so I assume I am scaling the single trials wrong. Here's the  
plotting code snippet:

...  
#left/right tones  
stcs\_RL = apply\_inverse\_epochs(epochs\_ica['RL'], inverse\_operator, lambda2,  
method,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pick\_ori="normal")

#[https://gist.github.com/dengemann/9470121](https://gist.github.com/dengemann/9470121)  
times = epochs\_ica.times \* 1e3  
def xfun(x, times):  
&nbsp;&nbsp;&nbsp;&nbsp;x = np.abs(x).mean(0)  
&nbsp;&nbsp;&nbsp;&nbsp;baseline = times \< 0  
&nbsp;&nbsp;&nbsp;&nbsp;x -= x[baseline].mean(0)[None]  
&nbsp;&nbsp;&nbsp;&nbsp;x /= x[baseline].std(0)[None]  
&nbsp;&nbsp;&nbsp;&nbsp;return x

mean\_stc2 = sum(stcs\_LR[:])  
mean\_stc2.\_data /= len(stcs\_LR[:])

for i in range(np.shape(stcs\_LR)[0]):  
&nbsp;&nbsp;&nbsp;&nbsp;time\_course2 = xfun(stcs\_LR[i].in\_label(label).data, times)  
&nbsp;&nbsp;&nbsp;&nbsp;plt.plot(times, time\_course2)  
&nbsp;&nbsp;&nbsp;&nbsp;plt.xlabel('Time (ms)')

mean\_timecourse = xfun(mean\_stc2.in\_label(label).data, times)  
plt.plot(times,mean\_timecourse.T,linewidth=5)

\<[http://imgur.com/sJHzdIb](http://imgur.com/sJHzdIb)\>  
Here's a image of the single trials under the average across  
trials.\<[http://imgur.com/sJHzdIb](http://imgur.com/sJHzdIb)\>They don't seem to match up but the  
average is what I would expect.

If there was a gist around somewhere that shows how to plot single trials  
from a label and the average together correctly, that'd be great.

thanks,  
Matt  
-------------- next part --------------  
An HTML attachment was scrubbed...  
URL: [http://mail.nmr.mgh.harvard.edu/pipermail/mne\_analysis/attachments/20140421/f92cae25/attachment.html](http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20140421/f92cae25/attachment.html)

---

<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:** [April 21, 2014, 7:21pm UTC](https://mne.discourse.group/t/single-trial-dspm-plots/715/2 "2014-04-21T19:21:09Z")

</div>

Hi Matt,

I am unsure if this is a scaling problem. Remember the dSPM is  
essentially an F test against the noise. The brain is very busy all  
the time, so your SNR is pretty low, because you are only interested  
in the activity relative to your task, while all that other brain  
activity is going on in the single trial data. Averaging dramatically  
improves the SNR.

Short version: If you are use the dSPM, I expect the single trial to  
look very poor (especially if you are using prestimulus data for the  
noise covariance matrix). It may make more sense to look at single  
trial data using the MNE. And if you really must use single trial data  
with a dSPM, I recommend using emptyroom data (if this is MEG) instead  
of prestimulus data for your noise covariance matrix.

I don't think it would be a problem for a figure to show the average  
dSPM and the single trial MNE (with two y axes: the left with the dSPM  
score and the right with the MNE amplitudes for the single trial  
data).

HTH  
D

---

<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:** [April 21, 2014, 10:53pm UTC](https://mne.discourse.group/t/single-trial-dspm-plots/715/3 "2014-04-21T22:53:58Z")

</div>

Will give empty room a try. For ncov, I'm currently using:

noise\_cov = mne.compute\_covariance(epochs\_ica.crop(None, 0, copy=True))

noise\_cov = mne.cov.regularize(noise\_cov, epochs\_ica.info,mag=0.05,  
grad=0.05,eeg=0.1, proj=True)

thanks,

Matt

---

<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:** [April 22, 2014, 9:26am UTC](https://mne.discourse.group/t/single-trial-dspm-plots/715/4 "2014-04-22T09:26:55Z")

</div>

hi Matt,

the problem is that you z-score at the single trial level.  
You should apply the same z-score scaling based on  
pooled variance from all trials

makes sense?

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:** [April 23, 2014, 6:30pm UTC](https://mne.discourse.group/t/single-trial-dspm-plots/715/5 "2014-04-23T18:30:06Z")

</div>

I feel like the recommendation to use MNE instead of dSPM in single-trial  
source solutions has come up on the mailing list more than once, I think,  
but the example code distributed with MNE Python still uses dSPM:

[http://martinos.org/mne/stable/auto\_examples/inverse/plot\_compute\_mne\_inverse\_epochs\_in\_label.html](http://martinos.org/mne/stable/auto_examples/inverse/plot_compute_mne_inverse_epochs_in_label.html)

---

<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:** [April 23, 2014, 7:11pm UTC](https://mne.discourse.group/t/single-trial-dspm-plots/715/6 "2014-04-23T19:11:33Z")

</div>

It would be great to get a inverse epochs example that reflects the current  
thinking in single trial localization, especially one that shows the best  
way organize, scale, and display the single trials. Ultimately, I just want  
to do some stats between conditions for single subjects or to plot sem  
around an average condition waveform for a subject, so including that kind  
of thing would be even better.

---

<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:** [April 23, 2014, 7:17pm UTC](https://mne.discourse.group/t/single-trial-dspm-plots/715/7 "2014-04-23T19:17:34Z")

</div>

Great point. I'll move this to github and put in a new issue about this example.

D

---

<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:** [April 23, 2014, 9:33pm UTC](https://mne.discourse.group/t/single-trial-dspm-plots/715/8 "2014-04-23T21:33:00Z")

</div>

Hi Matt,  
&nbsp;&nbsp;&nbsp;Please have a try with this:  
[https://gist.github.com/haribharadwaj/11232865](https://gist.github.com/haribharadwaj/11232865)

Here, the single trial dSPM and the evoked dSPM are shown from the same  
label (pooled across vertices of the label).. I have used the same inverse  
operator for the two (i.e., scaled the noise-cov identically).. Not sure  
if this is representative of "current thinking" but nonetheless something  
I look at for exploratory purposes when I want to view single trials..

Hari

---

<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:** [April 24, 2014, 11:34pm UTC](https://mne.discourse.group/t/single-trial-dspm-plots/715/9 "2014-04-24T23:34:43Z")

</div>

Great example! It's working now for my data.

---

<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:** [April 26, 2014, 1:35pm UTC](https://mne.discourse.group/t/single-trial-dspm-plots/715/10 "2014-04-26T13:35:41Z")

</div>

New example will show up on the dev website tomorrow

thanks Hari

Alex

cf : [https://github.com/mne-tools/mne-python/pull/1237](https://github.com/mne-tools/mne-python/pull/1237)
