Applying Inverse to Evoked vs Applying Inverse to Epochs and Averaging

Hi all,

    I tried applying an inverse model to the evoked data and also applying inverse epochs directly to the same epochs that were averaged to make the evoked data and then averaging the data from the list of source space time courses, and these matrices weren't the same. Does anyone have any insight as to why this would be?

Thanks,

Alex
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.nmr.mgh.harvard.edu/pipermail/mne_analysis/attachments/20171103/e08b61dc/attachment-0001.html

Hi Alex,

Would you mind sharing the code you used for this experiment? I have a feeling the answer might be of general relevance, and it might help to be concrete.

/Chris
/Aarhus, DK

Hi Chris,

    Of course, here is the relevant code:

snr=1.0
method='dSPM'
set_log_level("critical")

set_config("SUBJECTS_DIR",fs_dir,set_env=True)

bem = read_bem_solution(os.path.join(fs_dir, data.name, 'bem',
                        '%s-5120-5120-5120-bem-sol.fif' % data.name))
source = read_source_spaces(os.path.join(fs_dir, data.name, 'bem',
                                         '%s-oct-6p-src.fif' % data.name))
coord_trans = read_trans(os.path.join(fs_dir, data.name, 'mri', 'T1-neuromag',
                                      'sets', 'COR-%s-%s.fif' %(data.name,data.task)))

# Source localization parameters.
lambda2 = 1.0 / snr ** 2
pick_ori = 'normal'

value_indices = data._get_indices(event,condition,values,bins)

epochs = data.epochs_current[event]
epochs.set_eeg_reference(None)
info = epochs.info

print('Making forward model...')
fwd = make_forward_solution(epochs.info,coord_trans,source,bem,
                            meg=False,eeg=True,mindist=1.0)

print('Making noise covariance matrices...')
data.epochs_current['baseline'].info['bads'] = epochs.info['bads']
data.epochs_current['baseline'].set_eeg_reference(None)
_,tmin,tmax = data.events['baseline']
noise_cov = compute_covariance(data.epochs_current['baseline'],
                                    tmin=tmin,tmax=tmax,
                                    method="shrunk")

print('Making inverse...')
inv = make_inverse_operator(epochs.info, fwd, noise_cov)
data.invs[event] = (inv,lambda2,method)

bl_epochs = data.epochs_current['baseline'].crop(tmin=tmin,tmax=tmax)
data.stcs['baseline'] = apply_inverse_epochs(bl_epochs,inv,lambda2=lambda2,method=method)
A = sum([ss.data for ss in data.stcs['baseline']])/len(data.stcs['baseline'])

bl_evoked = data.epochs_current['baseline'].crop(tmin=tmin,tmax=tmax).average()
B = apply_inverse(bl_evoked,inv,lambda2=lambda2,method=method).data

np.array_equal(A,B) # False

Hope that helps.

Alex

when you apply inverse operator to epochs you have more noise which
corresponds to the nave attribute in evoked (nave == number of
averaged epochs), which is 1 for single epochs.

also you have the SNR.

the consequence is that the regularization parameter is slightly
different when you apply the inverse to epochs or to evoked.

HTH
Alex

Hi Alex,

    Thank you that makes sense and was along the lines of what I expected.

    I assume then that doing the former (applying the inverse to evoked data) is best practice over doing the later (applying inverse epochs and averaging). Is that your understanding as well?

Thanks,

Alex

Well it depends on what you want to do. Some analysis on single trials
don't allow you to work just with Evoked

Alex