fmri data analysis matlab

Post on 16-Apr-2015

65 views 11 download

description

this document used to analysis fmri data with matlab

Transcript of fmri data analysis matlab

fMRI data analysis usingMATLAB

Psych 258Russ Poldrack

Issues for fMRI analysis

• Data file formats– Reading and writing data

• Data interrogation• Statistical analysis• Design optimization

What is an MRI image?

• Matrix of intensity valuesin a slice through the brain– Generally either 8-bit or 16-

bit– In-plane dimensions

generally 64x64 to 256x256– # of slices from 16-128– Generally represented as

3D image (X, Y, & Zdimensions) or 4D (X/Y/Z+ time) timeseries

Data file formats

• There are a number of common file 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

*.mnc/*.nii*.img/.hdrArbitrarilynamed

Files

Extensive/integrated

Minimal/separate

Extensive/integrated

Header

arbitrary3D/4D2DDimension

MINC/Nifti

ANALYZEDICOM

Interrogating data in MATLAB

• SPM provides functions for readingANALYZE and MINC files into MATLAB

>> v=spm_vol('mask.img')

v =

fname: 'mask.img' dim: [53 63 46 2] mat: [4x4 double] pinfo: [3x1 double] descrip: 'spm_spm:resultant analysis mask'

>> d=spm_read_vols(v);>> size(d)

ans =

53 63 46

Converting DICOM files

• DICOM files are generally converted toANALYZE 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 files

>> 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 condition2: convolve with canonical HRF3: estimate GLM using resulting regressor

Canonical HRFs:-gamma function-sum of gammas

Statistical modeling of data1) create a matrix of onset

times for each trial2) Create a “stick

function” with ones ateach onset

3) Convolve the stick-function with the HRF

4) Combine convolvedSF with column ofzeros tocreate 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 onplot(predicted,'r')

Estimation and efficiencyY = Xβ + ε - GLMβest = (XTX)-1XTY - ML estimate for β (assuming IID)E = ((β - βest )2)-1 - efficiency of estimator

1E = ------------------- - efficiency depends only

trace((XTX)-1) 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: Contrast: [ 1 1 ]

Contrast: [ 1 -1 ]

For tasks vs. baseline,efficiency increaseswith variance andcorrelation

For comparisonbetween tasks,efficiency increaseswith variance butdecreases withcorrelation