33
From raw MEG to publication: how to perform group analysis with FieldTrip Robert Oostenveld Donders Institute, Radboud University, Nijmegen, NL NatMEG, Karolinska Institute, Stockholm, SE

Group analyses with FieldTrip

Embed Size (px)

Citation preview

Page 1: Group analyses with FieldTrip

From raw MEG to publication: how to perform group analysis with FieldTrip

Robert OostenveldDonders Institute, Radboud University, Nijmegen, NLNatMEG, Karolinska Institute, Stockholm, SE

Page 2: Group analyses with FieldTrip

Presentation outline

FieldTrip background

Strategy for making analysis pipelines

Single subject pipelineHighlight: Reading and converting filesHighlight: Anatomical coregistration

Group analysis pipeline

Page 3: Group analyses with FieldTrip

M/EEG signal characteristics considered during analysis

timecourse of activity -> ERP

spectral characteristics -> power spectrum or TFR

spatial distribution of activity over the head -> source reconstruction

interaction between regions in the brain-> source reconstruction and connectivity

Page 4: Group analyses with FieldTrip

Channels show a superposition of the source activity

Some analyses can be done at the channel levelSome should be done at the source level

analyses

interpretations or hypotheses

require

Page 5: Group analyses with FieldTrip

FieldTrip basics

dataout = functionname(cfg, datain, …)

functionname(cfg, datain, …)

dataout = functionname(cfg)

the “cfg” argument is a configuration structure, e.g.

cfg.channel = {‘C3’, C4’, ‘F3’, ‘F4’} cfg.foilim = [1 70]

Page 6: Group analyses with FieldTrip

Using functions in an analysis protocol

ft_preprocessing

ft_rejectartifact

ft_freqanalysis

ft_multiplotTFR ft_freqstatistics

ft_multiplotTFR

cfg = [ ]cfg.dataset = ‘Subject01.ds’cfg.bpfilter = [0.01 150]...rawdata = ft_preprocessing(cfg)

Page 7: Group analyses with FieldTrip

Using functions in an analysis protocol

ft_preprocessing

ft_rejectartifact

ft_freqanalysis

ft_multiplotTFR ft_freqstatistics

ft_multiplotTFR

cfg = [ ]cfg.method = ‘mtmfft’cfg.foilim = [1 120]...freqdata = ft_freqanalysis(cfg, rawdata)

Page 8: Group analyses with FieldTrip

Event related response

timelockData = avg: [151x900 double] var: [151x900 double] label: {151x1 cell} time: [1x900 double] dimord: 'chan_time’ cfg: [1x1 struct]

Page 9: Group analyses with FieldTrip

Example use in scripts

cfg = []cfg.dataset = ‘Subject01.ds’cfg.bpfilter = [0.01 150]...rawdata = ft_preprocessing(cfg)

cfg = []cfg.method = ‘mtmfft’cfg.foilim = [1 120]...freqdata = ft_freqanalysis(cfg, rawdata)

cfg = []cfg.method = ‘montecarlo’cfg.statistic = ‘indepsamplesT’cfg.design = [1 2 1 2 2 1 2 1 1 2 ... ]...freqstat = ft_freqstatistics(cfg, freqdata)

ft_preprocessing

ft_freqanalysis

ft_freqstatistics

ft_topoplotTFR

Page 10: Group analyses with FieldTrip

Example use in scripts

cfg = []cfg.dataset = ‘Subject01.ds’cfg.bpfilter = [0.01 150]...rawdata = ft_preprocessing(cfg)

cfg = []cfg.method = ‘mtmfft’cfg.foilim = [1 120]...freqdata = ft_freqanalysis(cfg, rawdata)

cfg = []cfg.method = ‘montecarlo’cfg.statistic = ‘indepsamplesT’cfg.design = [1 2 1 2 2 1 2 1 1 2 ... ]...freqstat = ft_freqstatistics(cfg, freqdata)

ft_preprocessing

ft_freqanalysis

ft_freqstatistics

ft_topoplotTFR

Page 11: Group analyses with FieldTrip

Example use in scripts

cfg = []cfg.dataset = ‘Subject01.ds’cfg.bpfilter = [0.01 150]...rawdata = ft_preprocessing(cfg)

cfg = []cfg.method = ‘mtmfft’cfg.foilim = [1 120]...freqdata = ft_freqanalysis(cfg, rawdata)

cfg = []cfg.method = ‘montecarlo’cfg.statistic = ‘indepsamplesT’cfg.design = [1 2 1 2 2 1 2 1 1 2 ... ]...freqstat = ft_freqstatistics(cfg, freqdata)

ft_preprocessing

ft_freqanalysis

ft_freqstatistics

ft_topoplotTFR

Page 12: Group analyses with FieldTrip

Example use in scripts

cfg = []cfg.dataset = ‘Subject01.ds’cfg.bpfilter = [0.01 150]...rawdata = ft_preprocessing(cfg)

cfg = []cfg.method = ‘mtmfft’cfg.foilim = [1 120]...freqdata = ft_freqanalysis(cfg, rawdata)

cfg = []cfg.method = ‘montecarlo’cfg.statistic = ‘indepsamplesT’cfg.design = [1 2 1 2 2 1 2 1 1 2 ... ]...freqstat = ft_freqstatistics(cfg, freqdata)

ft_preprocessing

ft_freqanalysis

ft_freqstatistics

ft_topoplotTFR

Page 13: Group analyses with FieldTrip

Example use in scripts

cfg = []cfg.dataset = ‘Subject01.ds’cfg.bpfilter = [0.01 150]...rawdata = ft_preprocessing(cfg)

cfg = []cfg.method = ‘mtmfft’cfg.foilim = [1 120]...freqdata = ft_freqanalysis(cfg, rawdata)

cfg = []cfg.method = ‘montecarlo’cfg.statistic = ‘indepsamplesT’cfg.design = [1 2 1 2 2 1 2 1 1 2 ... ]...freqstat = ft_freqstatistics(cfg, freqdata)

ft_preprocessing

ft_freqanalysis

ft_freqstatistics

ft_topoplotTFR

Page 14: Group analyses with FieldTrip

Example use in scripts

subj = {‘S01.ds’, ‘S02.ds’, …}trig = [1 3 7 9]

for s=1:nsubjfor c=1:ncond

cfg = [] cfg.dataset = subj{s} cfg.trigger = trig(c) rawdata{s,c} = ft_preprocessing(cfg)

cfg = [] cfg.method = ‘mtmfft’ cfg.foilim = [1 120] freqdata{s,c} = ft_freqanalysis(cfg, rawdata{s,c})

endend

Page 15: Group analyses with FieldTrip

Example use in scripts

subj = {‘S01.ds’, ‘S02.ds’, …}trig = [1 3 7 9]

for s=1:nsubjfor c=1:ncond

cfg = [] cfg.dataset = subj{s} cfg.trigger = trig(c) rawdata = ft_preprocessing(cfg)

filename = sprintf(‘raw%s_%d.mat’, subj{s}, trig(c)); save(filename, ‘rawdata’)

endend

Page 16: Group analyses with FieldTrip

Example use in scripts

subj = {‘S01.ds’, ‘S02.ds’, …}trig = [1 3 7 9]

for s=1:nsubjfor c=1:ncond

cfg = [] cfg.dataset = subj{s} cfg.trigger = trig(c) cfg.outputfile = sprintf(‘raw%s_%d.mat’, subj{s}, trig(c)); rawdata = ft_preprocessing(cfg)

endend

Page 17: Group analyses with FieldTrip

Example use in distributed computing

subj = {‘S01.ds’, ‘S02.ds’, …}trig = [1 3 7 9]

for s=1:nsubjfor c=1:ncond

cfgA{s,c} = [] cfgA{s,c}.dataset = subj{s} cfgA{s,c}.trigger = trig(c) cfgA{s,c}.outputfile = sprintf(‘raw%s_%d.mat’, subj{s}, trig(c))

cfgB{s,c} = [] cfgB{s,c}.dataset = subj{s} cfgB{s,c}.trigger = trig(c) cfgB{s,c}.inputfile = sprintf(‘raw%s_%d.mat’, subj{s}, trig(c)); cfgB{s,c}.outputfile = sprintf(‘freq%s_%d.mat’, subj{s}, trig(c));

endend

dfeval(@ft_preprocessing, cfgA)dfeval(@ft_freqanalysis, cfgB)

MATLAB distributed computing

Page 18: Group analyses with FieldTrip

Example use in distributed computing

subj = {‘S01.ds’, ‘S02.ds’, …}trig = [1 3 7 9]

for s=1:nsubjfor c=1:ncond

cfgA{s,c} = [] cfgA{s,c}.dataset = subj{s} cfgA{s,c}.trigger = trig(c) cfgA{s,c}.outputfile = sprintf(‘raw%s_%d.mat’, subj{s}, trig(c))

cfgB{s,c} = [] cfgB{s,c}.dataset = subj{s} cfgB{s,c}.trigger = trig(c) cfgB{s,c}.inputfile = sprintf(‘raw%s_%d.mat’, subj{s}, trig(c)); cfgB{s,c}.outputfile = sprintf(‘freq%s_%d.mat’, subj{s}, trig(c));

endend

qsubcellfun(@ft_preprocessing, cfgA)qsubcellfun(@ft_freqanalysis, cfgB)

FieldTrip distributed computing

Page 19: Group analyses with FieldTrip

FieldTrip is a toolbox

the data and the separate functions are all in your hands

you write a script or set of scripts that represents the analysis pipeline

scripts correspond to analysis protocolsscripts can be reviewed by supervisorsscripts are often reused and shared with colleaguesscripts can be published/released

Page 20: Group analyses with FieldTrip

File importing with FieldTriphighlight 1

Page 21: Group analyses with FieldTrip

FieldTrip private functions(low-level)

FieldTrip main functions

end-user perspective

FieldTrip toolbox structure - at a glance

Page 22: Group analyses with FieldTrip

FieldTrip toolbox structure - a closer look

fileio forward preproc private

FieldTrip main functions

end-user perspective

utilities

Page 23: Group analyses with FieldTrip

externalEEGLAB

externalSPMpreproc

FieldTrip toolbox structure - a closer look

fileio forward private

end-user perspective

ft_read_data(…) ft_compute_leadfield(…)ft_preproc_bandpassfilter(…)

utilitiesFieldTrip main functions

Page 24: Group analyses with FieldTrip

SPM under the hood

preprocfileio forward

end-user perspective

ft_read_data(…) ft_compute_leadfield(…)ft_preproc_bandpassfilter(…)

fieldtrip

SPM

… private

Page 25: Group analyses with FieldTrip

EEGLAB under the hood

fileio forward

end-user perspective

ft_read_data(…) ft_compute_leadfield(…)

fieldtrip

EEGLAB

… private

Page 26: Group analyses with FieldTrip

The fileio (input/output) mini toolbox

In FieldTrip primarily ft_definetrial(cfg)ft_preprocessing(cfg)ft_read_mri

Provides a consistent interface (API) to datasets from 7 MEG systems and >30 EEG systems

ft_read_event

ft_read_header

ft_read_data

ft_read_xxx(filename, …)

Page 27: Group analyses with FieldTrip

highlight 2

Coregistration between MEG/EEG and anatomy

1) anatomical landmarks (lpa, rpa, nas)2) HPI/HCL coil locations3) scalp surface points

Page 28: Group analyses with FieldTrip

Lab specific conventions for landmarks and markers

Landmarks: anatomically recognizeable points on a head

Markers (or fiducials): points that are visible in multiple modalities, e.g. HPI coils or vitamin E capsules

Page 29: Group analyses with FieldTrip

Sharing anonymous imaging data

Facial details have been removed, e.g. using ft_defacevolume or ft_defacemesh.

Nasion is missing, the outline of the nose is missing, sometimes also the ears.

Page 30: Group analyses with FieldTrip

Coregistration

1. Redo the coregistration using limited data2. Trust the coregistration that was provided

FieldTrip BrainStorm

Page 31: Group analyses with FieldTrip

Presentation outline

FieldTrip background

Strategy for making analysis pipelines

Single subject pipelineHighlight: Reading and converting filesHighlight: Anatomical coregistration

Group analysis pipeline

Page 32: Group analyses with FieldTrip

Making a group analysis pipeline

Start with version control> git init

Write the pipeline for a single subject> git commit

Manage subject differences> git commit

Run for all subjects> git commit

Do group analysis> git commit

Share your pipeline along with paper and data> git push

Page 33: Group analyses with FieldTrip

Wrap up and topics for discussion

Managing and sharing pipelines- version control, provenance, consistency,

reproducibility

Preventing “data dredging”, “double dipping” and biassed analyses

Sharing data for (re)analysis- BIDS: Brain Imaging Data Structure now also for

MEG (see poster Mo-P012)- Provide sufficient detail, but not all

http://datacolada.orghttps://aspredicted.org