You are on page 1of 18

fMRI data analysis using MATLAB

Psych 258 Russ Poldrack

Issues for fMRI analysis


Data le formats
Reading and writing data

Data interrogation Statistical analysis Design optimization

What is an MRI image?


Matrix of intensity values in a slice through the brain
Generally either 8-bit or 16bit In-plane dimensions generally 64x64 to 256x256 # of slices from 16-128 Generally represented as 3D image (X, Y, & Z dimensions) or 4D (X/Y/Z + time) timeseries

Data le formats
There are a number of common le formats
DICOM
Standard for data straight from scanner

ANALYZE
Common standard for analysis programs 3D vs. 4D

MINC
Extension of NetCDF

Nifti
Newest standard, developed by consensus committee

Format comparisons
DICOM Dimension 2D Header Files Extensive/ integrated ANALYZE MINC/ Nifti 3D/4D arbitrary Minimal/ separate Extensive/ integrated *.mnc/*.nii

Arbitrarily *.img/.hdr named

Interrogating data in MATLAB


SPM provides functions for reading ANALYZE and MINC les into MATLAB
>> v=spm_vol('mask.img') v= ans = fname: 'mask.img' dim: [53 63 46 2] mat: [4x4 double] pinfo: [3x1 double] descrip: 'spm_spm:resultant analysis mask' 53 63 46 >> d=spm_read_vols(v); >> size(d)

Converting DICOM les


DICOM les are generally converted to ANALYZE before analysis
SPM requires 3D analyze FSL requires 4D analyze

Tools for DICOM conversion


SPM2 - DICOM toolbox Xmedcon - free conversion software Debabeler - free conversion software from LONI

>> imagesc(d(:,:,24)) >> colormap gray

>> hist(reshape(d(:,:,24),1,53*63),100)

Loading a set of les


>> files=spm_get(Inf,'*.img','choose a set of images'); >> v=spm_vol(files); >> d=spm_read_vols(v); >> whos Name Size Bytes Class d 4-D 154009600 double array files 188x74 27824 char array v 188x1 146812 struct array >> size(d) Ans = 64

64

25

188

Plotting timeseries data


>> plot(squeeze(d(32,32,20,:)))

Basic analysis of event-related data: 1: create stick function for each condition 2: convolve with canonical HRF 3: estimate GLM using resulting regressor

Canonical HRFs: -gamma function -sum of gammas

Statistical modeling of data


1) create a matrix of onset times for each trial 2) Create a stick function with ones at each onset 3) Convolve the stickfunction with the HRF 4) Combine convolved SF with column of zeros to create design matrix >> onsets=[]; >> sf=zeros(1,100) >> sf(onsets)=1; >> hrf=spm_hrf(TR); >> conv_sf=conv(sf,hrf); >> conv_sf=conv_sf(1:100); >> X=[conv_sf ones(100,1)];

FIR design matrix

FIR estimates

Y=Xb + N(0,1), b=[2 4 1000]

onsets=randperm(100); TR=2; sf=zeros(1,100); sf(onsets(1:10))=1; hrf=spm_hrf(TR); conv_sf=conv(sf,hrf); conv_sf=conv_sf(1:100); X=[conv_sf' ones(100,1)]; b=[5 100]; data=X*b' + randn(100,1)*0.5; b_hat=X\data; predicted=X*b_hat; plot(data) hold on plot(predicted,'r')

Estimation and efciency


Y = X + est = (XTX)-1XTY E = (( - est )2)-1 E= 1 ------------------trace((XTX)-1) - GLM - ML estimate for (assuming IID) - efciency of estimator

- efciency depends only upon the covariance of the design matrix

TR=2; nruns=5000; efficiency=zeros(1,nruns); for x=1:nruns onsets=randperm(100); sf=zeros(1,100); sf(onsets(1:10))=1; hrf=spm_hrf(TR); conv_sf=conv(sf,hrf); conv_sf=conv_sf(1:100); X=[conv_sf' ones(100,1)]; efficiency(x)=1/trace(inv(X'*X)); end; hist(efficiency);

Design matrix w/ 2 conditions: For tasks vs. baseline, efciency increases with variance and correlation

Contrast: [ 1 1 ]

Contrast: [ 1 -1 ] For comparison between tasks, efciency increases with variance but decreases with correlation

You might also like