Skip to content

Compare evokeds confidence intervals for grads  #4730

Closed

Description

@ktavabi

Still not clear to me if there is a bug in how confidence intervals for gradiometers in plot_compare_evokeds are computed? Using simulation example to illustrate...

screen shot 2017-11-04 at 8 57 31 pm

import numpy as np
import matplotlib.pyplot as plt

import mne
from mne.datasets import sample
from mne.time_frequency import fit_iir_model_raw
from mne.viz import plot_sparse_source_estimates
from mne.simulation import simulate_sparse_stc, simulate_evoked
data_path = sample.data_path()

raw = mne.io.read_raw_fif(data_path + '/MEG/sample/sample_audvis_raw.fif')
proj = mne.read_proj(data_path + '/MEG/sample/sample_audvis_ecg-proj.fif')
raw.info['projs'] += proj

fwd = mne.read_forward_solution(data_path + 
                                '/MEG/sample/sample_audvis-meg-eeg-oct-6-fwd.fif')
fwd = mne.pick_types_forward(fwd, meg=True, eeg=True, exclude=[])
cov = mne.read_cov(data_path + 
                   '/MEG/sample/sample_audvis-cov.fif')
info = mne.io.read_info(data_path + 
                        '/MEG/sample/sample_audvis-no-filter-ave.fif')

label_names = ['Aud-lh', 'Aud-rh']
labels = [mne.read_label(data_path + '/MEG/sample/labels/%s.label' % ln)
          for ln in label_names]
times = np.arange(300, dtype=np.float) / raw.info['sfreq'] - 0.1
picks = mne.pick_types(raw.info, meg=True, exclude='bads')
iir_filter = fit_iir_model_raw(raw, order=5, picks=picks, tmin=60, tmax=180)[1]
nave = 100  # simulate average of 100 epoc
rng = np.random.RandomState(42)


def data_fun(times):
    """Function to generate random source time courses"""
    return (50e-9 * np.sin(30. * times) *
            np.exp(- (times - 0.15 + 0.05 * rng.randn(1)) ** 2 / 0.01))

evokeds = list()
for i in range(10):
    stc = simulate_sparse_stc(fwd['src'], n_dipoles=2, times=times,
                              random_state=42, labels=labels, data_fun=data_fun)
    evokeds.append(simulate_evoked(fwd, stc, info, cov, nave=nave, use_cps=True,
                                   iir_filter=iir_filter))
picks = [raw.ch_names.index(j) for j in ['MEG 1811',
                                          'MEG 1812',
                                          'MEG 1813']]
mne.viz.plot_compare_evokeds(evokeds=[evokeds], picks=picks,
                             ci=.95)

Activity

  1. agramfort commented on Nov 7, 2017

    @agramfort
    SponsorMember
  2. jona-sassenhagen commented on Nov 8, 2017

    @jona-sassenhagen
    Contributor
  3. ktavabi commented on Nov 8, 2017

    @ktavabi
    ContributorAuthor

    I think I got the CI estimation for grads headed in the right direction with

    ...
    if ch_type == 'grad':
        data = [(_merge_grad_data(evoked_.data[picks, :])).
                      mean(0) for evoked_ in evokeds[condition]]
        data = np.asarray(data)
    else:
        data = np.asarray([evoked_.data[picks, :].mean(0)
                                        for evoked_ in evokeds[condition]])
    ci_array[condition] = _ci_fun(data) * scaling
    ...
    

    But I am still unable to plot them correctly, almost like CI's are scaled differently, and it's got me stumped.
    screen shot 2017-11-08 at 12 09 01 am

    Not sure if this is an inconvenience to anyone WRT #4526 convo, but I am curious to know if I am headed in the right direction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions