MEEG time generalization in a region (in space-time) of interest

This example shows MVPA analyses performed on MEEG data.

The input dataset involved a paradigm where a participant saw images of six object categories.

The code presented here can be adapted for other MEEG analyses, but there please note: * the current examples do not perform baseline corrections or signal normalizations, which may reduce discriminatory power.

Note: running this code requires FieldTrip.

  1. For CoSMoMVPA's copyright information and license terms, #
  2. see the COPYING file distributed with CoSMoMVPA. #

Contents

get timelock data in CoSMoMVPA format

% set configuration
config=cosmo_config();
data_path=fullfile(config.tutorial_data_path,'meg_obj6');

% show dataset information
readme_fn=fullfile(data_path,'README');
cosmo_type(readme_fn);

% reset citation list
cosmo_check_external('-tic');

% load preprocessed data
data_fn=fullfile(data_path,'meg_obj6_s00.mat');
data_tl=load(data_fn);

% convert to cosmomvpa struct and show the dataset
ds=cosmo_meeg_dataset(data_tl);
cosmo_disp(ds);
******************************************************************************
MEG responses to a human participant viewing pictures of six object categories
******************************************************************************

Contents
--------
- meg_obj6_s00.mat
    Preprecessed data from four runs in Matlab / GNU Octave format.
    Data is stored in a FieldTrip structure with the following relevant
    fields:

    + .trial 
        n_samples * n_sensors * n_time array with single trial data
    + .time
        1 * n_time vector of time relative to stimulus onset.
    + .label
        1 * n_sensors cell array with MEG channel labels.
    + .trialinfo
        n_time * 6 matrix with trial information; the columns represent:

        1) stimulus category in the range `(1:6)`, with the order
           being 'body','car','face','flower','insect','scene'. 
        2) stimulus index in the range `(1:48)`.
        3) unused.
        4) cumulative number of catch trials in the current run.
        5) stimulus presentation duration (in miliseconds).
        6) run number.

    In the current release, n_samples=494, n_sensors=295, n_time=301.
      
Version
-------
version 0.1, 26 April 2016

Methods
-------
This dataset contains data from an experiment where a participant 
(32y right-handed male) viewed images of six categories while being measured
with MEG. Over four runs, trials were presented at a rate of 1Hz while the
participant performed a one-back task. Blocks of eight trials where separated
by blink periods to reduce eye movement artefaces. 
Data was preprocessed using the FieldTrip toolbox [OFMS11].
Data was bandpass-filtered between 1Hz and 40Hz, resampled from 1000Hz to
250Hz, and baseline period for the period of -250 to -50 ms relative to (i.e.
before) stimulus onset.
Based on visual inspection, trials and sensors that seemed noisy were removed.
Catch trials (trials were the stimulus was repeated relative to the previous
trial) were also removed.


License
-------
The contents are made available by Nikolaas N. Oosterhof <nikolaas.oosterhof 
|at| unitn.it> under the Creative Commons CC0 1.0 Universal Public Domain 
Dedication ("CC0"). See the LICENSE file for details, or visit 
http://creativecommons.org/publicdomain/zero/1.0/deed.en.


Download
--------
A zip file with all data is available from the CoSMoMVPA_ website [OCH16]:

  http://www.cosmomvpa.org/datadb-meg_obj6.zip

.. _CoSMoMVPA: http://www.cosmomvpa.org


Contact
-------
Nikolaas N. Oosterhof <nikolaas.oosterhof |at| unitn.it>


References
----------
:ref:`Oostenveld, R., Fries, P., Maris, E., and Schoffelen, J.-M. (2011) <OFMS11>` FieldTrip: Open source software for advanced analysis of MEG, EEG, and invasive electrophysiological data.. Computational Intelligence and Neuroscience, 2011:156869.

:ref:`Oosterhof, N. N., Connolly, A. C., and Haxby, J. V. (2016) <OCH16>`. CoSMoMVPA: multi-modal multivariate pattern analysis of neuroimaging data in Matlab / GNU Octave. biorxiv.org, 2016. doi:10.1101/047118.

.samples                                                                                 
  [ -3.42e-12  1.32e-12  6.77e-12  ...   2.91e-12  1.02e-11     1e-12                    
     1.78e-12  1.42e-12 -2.35e-12  ...  -3.67e-12  -5.4e-12     7e-15                    
     7.84e-12  1.71e-13 -6.44e-13  ...  -2.88e-13  2.25e-12   1.2e-13                    
        :         :         :               :          :         :                       
    -2.46e-12 -1.41e-16  2.27e-12  ...  -5.81e-13  -6.2e-12  2.74e-13                    
     -7.9e-12   4.2e-12  4.11e-12  ...  -5.62e-12  7.64e-12  1.98e-13                    
    -2.32e-13 -2.49e-12  7.39e-12  ...   2.08e-12  -8.5e-12  2.42e-13 ]@494x88795        
.fa                                                                                      
  .chan                                                                                  
    [ 1         2         3  ...  293       294       295 ]@1x88795                      
  .time                                                                                  
    [ 1         1         1  ...  301       301       301 ]@1x88795                      
.a                                                                                       
  .fdim                                                                                  
    .labels                                                                              
      { 'chan'                                                                           
        'time' }                                                                         
    .values                                                                              
      { { 'MEG0113'  'MEG0112'  'MEG0123' ... 'MEG2642'  'MEG2643'  'MEG2641'   }@1x295  
        [ -0.296    -0.292    -0.288  ...  0.896       0.9     0.904 ]@1x301            }
  .meeg                                                                                  
    .samples_field                                                                       
      'trial'                                                                            
.sa                                                                                      
  .trialinfo                                                                             
    [ 4        28         0         1       142         1                                
      3        18         0         2       147         1                                
      2        15         0         2       147         1                                
      :         :         :         :        :          :                                
      6        47         0        23       142         4                                
      4        28         0        24       146         4                                
      3        18         0        24       147         4 ]@494x6                        
% set the targets (trial condition)
% Hint: use the first column from ds.sa.trialinfo
% >@@>
ds.sa.targets=ds.sa.trialinfo(:,1); % 6 categories
% <@@<

% set the chunks (independent measurements)
% all trials are here considered to be independent
% >@@>
nsamples=size(ds.samples,1);
ds.sa.chunks=(1:nsamples)';
% <@@<

% in addition give a label to each trial
index2label={'body','car','face','flower','insect','scene'};
ds.sa.labels=cellfun(@(x)index2label(x),num2cell(ds.sa.targets));

% just to check everything is ok
cosmo_check_dataset(ds);

Select subset of sensors and time points

% Select posterior gradiometers
sensor_posterior_planar={'MEG1632', 'MEG1642', 'MEG1732', 'MEG1842', ...
                        'MEG1912', 'MEG1922', 'MEG1942', 'MEG2232', ...
                        'MEG2312', 'MEG2322', 'MEG2342', 'MEG2432', ...
                        'MEG2442', 'MEG2512', 'MEG2532',...
                        'MEG1633', 'MEG1643', 'MEG1733', 'MEG1843', ...
                        'MEG1913', 'MEG1923', 'MEG1943', 'MEG2233', ...
                        'MEG2313', 'MEG2323', 'MEG2343', 'MEG2433', ...
                        'MEG2443', 'MEG2513', 'MEG2533'};

msk=cosmo_dim_match(ds,'chan',sensor_posterior_planar,...
                        'time',@(t)t>=0 & t<=.3);

ds_sel=cosmo_slice(ds,msk,2);
ds_sel=cosmo_dim_prune(ds_sel);

% Reduce the number of chunks to have only two chunks
% Hint: use cosmo_chunkize
% >@@>
ds_sel.sa.chunks=cosmo_chunkize(ds_sel,2);
% <@@<

% Now use cosmo_dim_transpose to make 'time' a sample dimension, and
% assign to ds_tr
% Hint: the third argument to cosmo_dim_transpose must be 1, because
% time now describes the first (sample) dimension in .samples
% >@@>
ds_tr=cosmo_dim_transpose(ds_sel,'time',1);
% <@@<

cosmo_disp(ds_tr);

% Set the measure to be a function handle to
% cosmo_dim_generalization_measure
% >@@>
measure=@cosmo_dim_generalization_measure;
% <@@<


% Set measure arguments
measure_args=struct();

% Use the measure with the following arugments:
% - measure: @cosmo_crossvalidation_measure
% - classifier: @cosmo_classify_lda
% - dimension: 'time'
% >@@>
measure_args.measure=@cosmo_crossvalidation_measure;
measure_args.classifier=@cosmo_classify_lda;
measure_args.dimension='time';
% <@@<

% Now apply the measure to the dataset, and store the output in a variable
% 'result'
% >@@>
result=measure(ds_tr,measure_args);
% <@@<
.samples                                                                                
  [ -1.63e-12   6.9e-12 -1.98e-12  ...  -2.42e-13 -3.72e-12  3.36e-12                   
     3.74e-12  3.24e-12  -2.4e-12  ...   2.01e-12  4.77e-12  7.19e-12                   
      1.6e-12 -2.46e-12 -3.09e-12  ...   9.16e-14 -1.17e-12 -5.15e-12                   
        :         :         :               :         :         :                       
    -4.46e-13 -4.98e-12  4.24e-13  ...   6.82e-13  1.42e-12  3.83e-13                   
      1.3e-12  -3.1e-12  2.78e-13  ...   4.14e-12 -6.21e-13 -1.52e-13                   
     1.05e-13 -3.31e-12 -4.57e-13  ...  -9.79e-12 -2.09e-12 -2.21e-12 ]@37544x30        
.sa                                                                                     
  .chunks                                                                               
    [ 1                                                                                 
      1                                                                                 
      2                                                                                 
      :                                                                                 
      2                                                                                 
      2                                                                                 
      2 ]@37544x1                                                                       
  .labels                                                                               
    { 'flower'                                                                          
      'face'                                                                            
      'car'                                                                             
         :                                                                              
      'scene'                                                                           
      'flower'                                                                          
      'face'   }@37544x1                                                                
  .targets                                                                              
    [ 4                                                                                 
      3                                                                                 
      2                                                                                 
      :                                                                                 
      6                                                                                 
      4                                                                                 
      3 ]@37544x1                                                                       
  .time                                                                                 
    [  1                                                                                
       1                                                                                
       1                                                                                
       :                                                                                
      76                                                                                
      76                                                                                
      76 ]@37544x1                                                                      
  .trialinfo                                                                            
    [ 4        28         0         1       142         1                               
      3        18         0         2       147         1                               
      2        15         0         2       147         1                               
      :         :         :         :        :          :                               
      6        47         0        23       142         4                               
      4        28         0        24       146         4                               
      3        18         0        24       147         4 ]@37544x6                     
.fa                                                                                     
  .chan                                                                                 
    [ 1         2         3  ...  28        29        30 ]@1x30                         
  .transpose_ids                                                                        
    [ 1         2         3  ...  28        29        30 ]@1x30                         
.a                                                                                      
  .fdim                                                                                 
    .labels                                                                             
      { 'chan' }                                                                        
    .values                                                                             
      { { 'MEG1632'  'MEG1633'  'MEG1643' ... 'MEG2513'  'MEG2533'  'MEG2532'   }@1x30 }
  .meeg                                                                                 
    .samples_field                                                                      
      'trial'                                                                           
  .sdim                                                                                 
    .labels                                                                             
      { 'time' }                                                                        
    .values                                                                             
      { [     0                                                                         
          0.004                                                                         
          0.008                                                                         
            :                                                                           
          0.292                                                                         
          0.296                                                                         
            0.3 ]@76x1 }                                                                
+00:00:27 [####################] -00:00:00  

Visualize results

% Unflatten the dataset using cosmo_unflatten, and assign the result
% to three variables: data, labels and values
% Hint: the second argument to cosmo_unflatten must be 1

% >@@>
[data,labels,values]=cosmo_unflatten(result,1);
% <@@<

% Visualize the data matrix using imagesc
% >@@>
imagesc(data,[0 0.5]);
% <@@<
colorbar();

% Show labels
nticks=5;
ytick=round(linspace(1, numel(values{1}), nticks));
ylabel(strrep(labels{1},'_',' '));
set(gca,'Ytick',ytick,'YTickLabel',values{1}(ytick));

xtick=round(linspace(1, numel(values{2}), nticks));
xlabel(strrep(labels{2},'_',' '));
set(gca,'Xtick',xtick,'XTickLabel',values{2}(xtick));