introduction to matlab for neuroimaging · introduction to matlab for neuroimaging krisanne litinas...
TRANSCRIPT
Introduction to MATLAB for NeuroimagingKRISANNE LITINASUM FMRI LABORATORY
Module 1: Recap
MATLAB Interface Path concept Variables and operators Scripts Functions Loops Conditional statements
Module 2:Single Pixel Analysis in MATLAB (General Linear Model)KRISANNE LITINASUM FMRI LABORATORY
Concept of a Model: Example
Say we have two variables, x and y. Goal: find out the relationship between x and y Method: come up with estimation and model the data accordingly
Simple Example
y
x
𝑦𝑦: Measurement (DV)
𝑥𝑥: The thing you are measuring against (IV)
Simple Example
y
x
𝑦𝑦: Measurement (DV)
𝑥𝑥: The thing you are measuring against (IV)
Need to model it somehow…
Simple Example: Linear Regression
y
x
𝑦𝑦: Measurement (DV)
𝑥𝑥: The thing you are measuring against (IV)
𝑦𝑦 = 𝑚𝑚𝑥𝑥 + 𝑏𝑏 + 𝑒𝑒
Estimate of the data: a linear relationship
Simple Example: Linear Regression
y
x
𝑦𝑦: Measurement (DV)
𝑥𝑥: The thing you are measuring against (IV)
𝑏𝑏: Intercept (constant)
𝑦𝑦 = 𝑚𝑚𝑥𝑥 + 𝑏𝑏 + 𝑒𝑒
Estimate of the data: a linear relationship
b
Simple Example: Linear Regression
y
x
𝑦𝑦: Measurement (DV)
𝑥𝑥: The thing you are measuring against (IV)
𝑏𝑏: Intercept (constant)
𝑒𝑒: Error term (residual noise after the fitting)
𝑦𝑦 = 𝑚𝑚𝑥𝑥 + 𝑏𝑏 + 𝑒𝑒
Estimate of the data: a linear relationship
b
𝒆𝒆𝒊𝒊
Simple Example: Linear Regression
y
x
𝑦𝑦: Measurement (DV)
𝑥𝑥: The thing you are measuring against (IV)
𝑏𝑏: Intercept (constant)
𝑒𝑒: Error term (residual noise after the fitting)
𝑚𝑚: Slope of the fitted line
𝑦𝑦 = 𝑚𝑚𝑥𝑥 + 𝑏𝑏 + 𝑒𝑒
Estimate of the data: a linear relationship
b
𝒎𝒎 =∆𝒚𝒚∆𝒙𝒙
y
x
Simple Example: Linear Regression
o We can solve for m and b
o If this model fits, we say that x and y are correlated
𝑦𝑦 = 𝑚𝑚𝑥𝑥 + 𝑏𝑏 + 𝑒𝑒
Estimate of the data: a linear relationship
b
𝒎𝒎
Simple Example: Linear Regression
If 𝑚𝑚 is “significant”, then we refer to that model as true.
”Significant”: 𝑚𝑚 is big enough compared to the noise (e)
Bigger Example: Linear Regression
Data composed of: DV: 𝑦𝑦
Multiple IVs: 𝑥𝑥1, 𝑥𝑥2, 𝑥𝑥3 …
A bigger linear model of these data (>1 independent variables):
𝑦𝑦 = 𝑚𝑚1𝑥𝑥1 + 𝑚𝑚2𝑥𝑥2 + 𝑚𝑚3𝑥𝑥3 + ⋯+ 𝑏𝑏 + 𝑒𝑒
Linear Regression in fMRI
𝑦𝑦, 𝑥𝑥1, 𝑥𝑥2, 𝑥𝑥3,… etc. are all time courses In the usual GLM analysis of fMRI data, all the 𝑥𝑥1, 𝑥𝑥2, 𝑥𝑥3,… terms are
usually not measured Instead, we make an ideal model and hope for the best ¯\_(ツ)_/¯
𝑦𝑦 = 𝑚𝑚1𝑥𝑥1 + 𝑚𝑚2𝑥𝑥2 + 𝑚𝑚3𝑥𝑥3 + ⋯+ 𝑏𝑏 + 𝑒𝑒
Expand to Matrix Form
Now with many variables:
𝑦𝑦 = 𝑚𝑚𝑥𝑥 + 𝑏𝑏 + 𝑒𝑒
Y= 𝑋𝑋𝛽𝛽 + 𝜀𝜀𝑌𝑌1𝑌𝑌2⋮𝑌𝑌𝑛𝑛
=
1 𝑋𝑋11 ⋯ 𝑋𝑋1𝑝𝑝1⋮1
𝑋𝑋21⋮𝑋𝑋𝑛𝑛1
⋯
⋯
𝑋𝑋2𝑝𝑝⋮
𝑋𝑋𝑛𝑛𝑝𝑝
𝛽𝛽0𝛽𝛽1⋮𝛽𝛽𝑝𝑝
+𝜀𝜀0𝜀𝜀1⋮𝜀𝜀𝑛𝑛
Design Matrix Observed Data
Model Params.
Error
time
Expand to Matrix Form
Solve for terms, do fancy math with matrices
𝑌𝑌 = 𝑋𝑋𝛽𝛽 + 𝜀𝜀
𝜀𝜀𝑒𝑒𝑒𝑒𝑒𝑒 = 𝑌𝑌 − 𝑋𝑋 ∗ 𝛽𝛽𝑒𝑒𝑒𝑒𝑒𝑒
𝑇𝑇𝑒𝑒𝑠𝑠𝑠𝑠𝑠𝑠𝑒𝑒(𝑛𝑛) =𝛽𝛽𝑒𝑒𝑒𝑒𝑒𝑒
𝑠𝑠𝑠𝑠𝑠𝑠𝑒𝑒𝑠𝑠(𝜀𝜀𝑒𝑒𝑒𝑒𝑒𝑒 𝑛𝑛 )
𝛽𝛽𝑒𝑒𝑒𝑒𝑒𝑒 = (𝑋𝑋)−1∗ 𝑌𝑌
Today’s Exercise
Generate and explore temporal noise for fMRI data (𝜀𝜀) Create a linear model for a BOLD time series using MATLAB (𝑋𝑋) Create a realistic (but fake) BOLD signal (𝑌𝑌) Use regression to test whether the model fits the signal