single trial dSPM plots

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,
                            pick_ori="normal")

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

mean_stc2 = sum(stcs_LR[:])
mean_stc2._data /= len(stcs_LR[:])

for i in range(np.shape(stcs_LR)[0]):
    time_course2 = xfun(stcs_LR[i].in_label(label).data, times)
    plt.plot(times, time_course2)
    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>
Here's a image of the single trials under the average across
trials.<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

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

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

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

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

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.

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

D

Hi Matt,
   Please have a try with this:
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

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

New example will show up on the dev website tomorrow

thanks Hari

Alex

cf : https://github.com/mne-tools/mne-python/pull/1237