# Analysis of MEG Data in SPM5

Many of us here use SPM for EEG and/or MEG analysis. The main reason is that SPM is freeware (requiring only Matlab), and thus modifiable and relatively easily to understand (Matlab is a relatively "high-level" language, which is easy to learn if you have any experience in procedural computer programming). Several of us are actively extending SPM for our own purposes, particularly in relation to the Neuromag type of MEG data.

SPM also offers some unique features (ie, not yet available in other packages):

**Multiple Sparse Priors (MSP)**: A new distributed (L2-norm-like) approach to the MEG/EEG inverse problem, in which several hundred patches of cortex are treated as spatial priors within a Parametric Empirical Bayesian (hierarchical linear Gaussian model) framework (Friston et al, 2008; PDF below).**Fusion**(simultaneous inversion) of MEG and EEG data: This obviates the need for arbitrary weightings between magnetometer and gradiometer data, or between magneto/gradiometer and concurrent EEG data (Henson et al, 2009b).**Group inversion**: the pooling over subjects in order to optimise the mutliple spatial priors (MSP) before inverting any one subject (Litvak & Friston, 2008).The use of Bayesian

**model-evidence**to compare models: because EM-like algorithm maximises the free-energy bound on the model-evidence, different forward models (eg mesh sizes, BEMs) and source priors (MSP vs standard Minimum Norm) can be compared (Henson et al, 2009a; PDF below)The use of a

**canonical**(inverse-normalised)**cortical mesh**, obviating the need for complex manual creation of individual cortical meshes from an MRI (Mattout et al, 2007), and providing a one-to-one mapping with a template (MNI) space, which allows statistics across subjects based on 3D images (just like with fMRI/PET data)The use of

**fMRI**clusters as separate spatial**priors**, whose contribution can be up or down-weigthed as a function of their relevance to the specific timewindow being localised (given temporal insensitivity of fMRI) (Henson et al, in press).The creation of

**"space-time" images**in sensor space, in order to localise condition effects in space and time using standard mass univariate statistical parametric maps (SPMs) and principled methods for multiple comparisons across space and time (using Random Field Theory) (eg Henson et al, 2008, Neuroimage).Finally, the opportunity to test effective connectivity at the millisecond scale between brain regions, or

**Dynamic Causal Modelling (DCM)**. Importantly, this is based on an explicit network models (which can be compared using model evidence), thus going beyond simple measures of correlation, coherence, phase-locking or granger "causality" (i.e, beyond functional connectivity).*More on DCM will follow here soon.*

Note that SPM5 does not do ECD solutions for MEG or offer optimised graphics (e.g, for browsing raw data) (though SPM8 will; see section on code below). SPM is also really designed for group-level, image-based statistics; if you want a more accurate source space (cortical mesh) and forward model for single-subject inversions (with better and faster graphics), you could consider MNE+Freesurfer instead.

## Demos

For specific demo using data from our Neuromag MEG machine, see SpmDemo

For a fuller demo of other EEG/MEG analysis in SPM5 (though from a different MEG machine), including more general features (e.g, time-freq analysis, 3D statistical maps), with proper step-by-step instructions via the GUI, see: http://www.fil.ion.ucl.ac.uk/spm/data/mmfaces.html

For a more theoretical introduction to source localisation in SPM5, see these slides: SPM5-MEEG_Dec08.ppt

## Further Help

This page provides basic information on computing, Matlab, Linux etc.

This page outlines a basic pipeline for EEG/MEG analysis: BasicMeegPipelineSpm5

This page describes the procedure for creating a 3D SensorSpm (topography x time)

This page lists some CBU-specific SPM notes (eg EEG montages): CbuSpmParameters

This page has some notes about meshing MRIs and forward models: SpmForwardModels

This page explains how to reposition structural MRIs close to MNI origin: http://imaging.mrc-cbu.cam.ac.uk/meg/RepositioningMRIs

You can display source estimation results in FreeSurfer

## Some relevant papers

Review of Parametric Empirical Bayesian approach, including MEG+EEG fusion, fMRI priors and group optimisation: HensonEtAl_FiN_11_PEB_MEEG_review.pdf

Summary of localisation approach using ReML for evoked and induced responses (mathematical; cites earlier development papers too): FristonEtAl_hbm_06.pdf

Basic considerations for Group Analyses (though using individual meshes): HensonEtAl_NI_07.pdf

Use of inverse-normalised ("canonical") cortical meshes: MattoutEtAl_JCIN_07.pdf

Choice of forward models for MEG (e.g, single-sphere vs BEM), including further validation of canonical meshes: HensonEtAl_Neuroimage_09_MEG_Forward_Models.pdf

**New method of Multiple Sparse Priors (MSP): FristonEtAl_NI_08_MSP.pdf****Simultaneous inversion (fusion) of magnetometers, gradiometers and EEG: HensonEtAl_Neuroimage_09_MEEG_fusion.pdf****Use of fMRI clusters as spatial priors: HensonEtAl_HBM_10_fMRIPriors_EMEG.pdf**

## The code

SPM has been developed at the FIL (in London), with input from people round the world. Here is its home: http://www.fil.ion.ucl.ac.uk/spm/

At the moment, we are using "SPM5" (with any latest updates automatically pulled from the FIL). At the CBU, SPM5 is installed here:

`/imaging/local/spm/spm5`

We have edited/refined some of these functions. These modifications are stored here:

`/imaging/local/spm/spm5/cbu_updates`

If you start SPM5 from Linux using Rhodri's wrappers, both these directories will be added to your Matlab path, with the cbu_updates directory higher in the path (so you will be using local CBU versions of any functions duplicated across these directories).

The functions in cbu_updates may be periodically updated, which will be preceded by an email to CBU imagers. More recent changes are under subversion control (SVN): If you are an external collaborator (outside the CBU network), or want access to the most recent changes (at your own risk), consult MeegCodeCbuSvn.

In the future, we will move to "SPM8". One exciting reason for this is that SPM8 will share the same data format with Field-Trip and EEGLAB (which are also Matlab packages for analysing EEG+MEG data). This will allow us to take the best features of each (e.g, source localisation and dynamic causal modelling in SPM8; time-frequency analysis and beam-formers in Field-Trip; Independent Component Analysis in EEGLAB). This is another advantage of Matlab-based academic-community-based freeware.

Basic preprocessing and source localisation in SPM8 will not differ much from SPM5. The main improvements concern Dynamic Causal Modelling (DCM) for EEG/MEG (together with better graphics and GUI). The reason that we are sticking with SPM5 for the moment is that the data format and forward modelling for Neuromag data is not quite finalised in Field-Trip/SPM8.

SPM5 can read raw and averaged FIF files, though you will probably first want to run your raw data through the Maxfilter utility, particularly if you 1) used Active Shielding during acquisition, 2) if you want to apply (temporal) SSS to remove noise, 3) if you used continuous HPI and/or 4) if you want to transform all subjects to a common (device) space. Max Filter can also downsample (eg from 1000Hz to 200Hz) and convert the data into different datatypes (e.g, short), which will help reduce filesize and processing time.

SPM5 uses Brainstorm (another freeware Matlab package) for creating forward models. You do not need to know how to use Brainstorm, but if you are interested, here is a link: http://neuroimage.usc.edu/brainstorm/