How To Do Multivariate Pattern Analysis

How To Do
Multivariate Pattern Analysis
What is MVPA?
Animations from Meyer & Kaplan (in press),
Journal of Visualized Experiments
Not significant
Average
Average
V1 V2 V3 V4 V5 V6
V1 V2 V3 V4 V5 V6
Univariate vs. multivariate analysis of
fMRI data
Individually not significant…but significant when considered
in conjunction!
—
V1 V2 V3 V4 V5 V6
Fusiform face area
Significant?
Univariate analysis:
Multivariate pattern analysis:
The direction in which
the correlation
between the perceptual
Reverse
inference
stimuli and brain activity is mapped does not matter from a
statistical point of view.
Primary visual cortex
Multivariate pattern
analysis:
Predictable?
V1 V2 V3 V 4 V5 V6
Training trials
Stimulus
V1 activity v v
vv
vv
vv
vv
vv
vv
vv
vv
vv
vv
vv
v
v
v
v
v
v
v
v
v
v
v
v
v
v
v
v
v
v
v
vv
v
v
v
v
v
v
v
v
v
v
v
v
v
v
v
pattern
vvv vvv vvv vvv vvv vvv vvv vvv vvv vvv vvv vvv
Stimulus
Performance: 75%
vv
vv
vv
vv
vv
vv
vv
vv
vv
vv
V1 activity
vvv vvv vvv vvv vvv vvv vvv vvv vvv vvv vvv vvv
pattern
vvv vvv vvv vvv vvv vvv vvv vvv vvv vvv vvv vvv
Classifier
vv
vv
Classifier guess
V1 activity
pattern
?
?
?
?
Testing trials
? ? ? ?
?
?
?
?
vv
vv
vv
vv
vv
vv
vv
vv
vv
vv
vv
vv
vvv vvv vvv vvv vvv vvv vvv vvv vvv vvv vvv vvv
vvv vvv vvv vvv vvv vvv vvv vvv vvv vvv vvv vvv
Stimulus
Testing trials
Cross-validation paradigm:
Cross-validation steps
Runs
1
2
3
4
5
6
7
8
1
Performance 1
2
3
4
5
6
7
8
Performance 2
Performance 3
Performance 4
Performance 5
Performance 6
Performance 7
Performance 8
Training run
Testing run
Overall
performance
What do I need to do MVPA?
 An fMRI experiment with an appropriate design
 Almost any modern computer
 PyMVPA software
Experiment design
 As many trials as possible to train the classifier
Experiment design
 As many trials as possible to train the classifier
 Clear BOLD pattern resulting from each trial
TR
TR
TR
TR
TR
TR
TR
TR
TR
TR
TR
TR
TR
TR
TR
TR
TR
TR
TR
TR
TR
Sparse temporal sampling
Video clip
TR
What is the input to the classifier?
TR TR TR TR TR TR TR TR TR TR TR TR
TASK A
 Raw fMRI data
TASK B
What is the input to the classifier?
TR TR TR TR TR TR TR TR TR TR TR TR
TASK A
TASK B
 Raw fMRI data
 Averaged fMRI data
AVG
AVG
What is the input to the classifier?
TR TR TR TR TR TR TR TR TR TR TR TR
TASK A
 Raw fMRI data
 Averaged fMRI data
 beta values from a GLM analysis
TASK B
Data pre-processing
•
•
•
•
Motion-correction
Smoothing (?)
Trend removal / high pass filter
Z-scoring
FSL
PyMVPA
Gathering Your Tools
Why PyMVPA
 Alternative toolbox: Princeton MVPA toolbox
http://code.google.com/p/princeton-mvpa-toolbox/
 PyMVPA is free and open-source, does not require Matlab
 Well-maintained and flexible
 Python is great once you get used to it
 I know how to use it
Python
 An interpreted, modern
programming language
 Produces very clear, easy to read
code
 Object-oriented
 Extensive scientific computing
modules available for python
(scipy, nipy, etc.)
Brief python demo
 Python command line
 Python scripting
 iPython
Gathering Your Tools
 Install PyMVPA: http://www.pymvpa.org
 Version .4x versus .6x
 Linux: Very easy, just type one command
 Windows:
 Mac: Instructions on website will only install .4x. To install .6x
follow my guide:
 http://www.jonaskaplan.com/lab/pymvpainstallation.php
Gather Your Ingredients
Ingredients
 1 4-dimensional functional data file, motion-corrected
 This should be all of your data from one subject. If you did
multiple scans, concatenate them into one single 4D file, all
motion corrected to the same volume
Sample preprocessing script
Ingredients
 1 4-dimensional functional data file, motion-corrected
 This should be all of your data from one subject. If you did
multiple scans, concatenate them into one single 4D file, all
motion corrected to the same volume
 1 text file which contains “attributes”:
 Column 1 labels each volume with a “target” category
 Column 2 labels each volume with a “chunk”, e.g. scan
 1 Mask file in the functional space
Terminology
dog
V
O
X
E
L
S
violin
cow
vase
Terminology
TARGETS
dog
violin
cow
F
E
A
T
U
R
E
S
CHUNK
vase
Sample attributes file
Sparse design
Block design
Getting started with pymvpa
 Start python or ipython
 Import the pymvpa module and explore it
Sample dataset
 Subject saw nine different 5-second video clips: dog, cow,
rooster, violin, piano, bass, vase, chainsaw, coins
 One single volume acquired 7 seconds after the start of the
clip
 Eight scans, each stimulus seen 3 times in each scan (24
times across the experiment)
Getting started with pymvpa
 Read in your attributes
 Create a dataset
Mappers
 Mappers transform data samples
 Dataset automatically maps data from 4D to 2D
 Many mappings are reversible
Data pre-processing steps
 Detrending
 Z-scoring
Partitioners
 Used to split the data into training set and testing set
 HalfPartitioner()
 OddEvenPartitioner()
 NFoldPartitioner()
Choosing a classifier algorithm
• Nearest neighbor
• Support Vector Machine (SVM)
• Linear Discriminant Analysis (LDA)
• Gaussian Naive Bayes (GNB)
• Sparse Multinomial Linear Regression (SMLR)
•...
•...
Choosing a classifier algorithm
Support Vector Machine
 Draws a hyperplane to separate the categories,
maximizing the margin between classes
Support Vector Machine
Support Vector Machine
• Draws a hyperplane to separate the categories,
maximizing the margin between classes
• Works quickly with on large feature sets (lots of voxels)
• Common in fMRI pattern learning literature
• Binary classifier
• Linear version chosen (very little advantage to nonlinear
SVM with lots of features and few stimuli)
Misaki et al, 2010, NeuroImage
Choosing a classifier algorithm
Setting up cross-validation
Go!
Results
Show confusion matrix:
Plot confusion matrix:
Significance testing
• Binomial test
• Permutation testing
• Voxel sensitivity maps
Significance testing
• Binomial test
Significance testing
• Binomial test
Significance testing
• Permutation testing
• Generate a null distribution by randomly permuting pattern labels
http://www.pymvpa.org/examples/permutation_test.html
Searchlight analysis
Searchlight analysis
To study on your own
 Temporal exploration: averaging, temporal searchlights
 Sensitivity maps
 Permutation testing