|
Sample fMRI Event-Related Design Analysis using SPM |
Background
This tutorial describes how to analyze a simple fMRI dataset using SPM8. To complete this tutorial you will need:
- MATLAB installed on your computer.
- SPM8 installed on your computer.
- Download and extract the sample dataset that includes the fMRI data (in NIfTI format), an anatomical scan (e.g. T1-weighted image) and text files that describe the timing.
About the sample dataset
This was a simple finger tapping task. The screen rapidly flashed with an arrow (< or >). When the arrow pointed right (>) they were intstructed to tap their right index finger, and when it pointed left (<) they were requested to push their left index finger. These events repeated for the whole scanning session (302 T2*-weighted volumes, about 10 minutes). The MRI scanner actually recorded 304 volumes, but automatically discarded the first two (as these have T1 effects), with all event onset times referring to the start of the first stored volume. The onsets of the tasks are recorded in the text files (LEVent.tab,REvent.tab). The image below shows the three event types (left, right arrow) as marks at the top of the image (with red and green indicating the changes in hemodynamic responses to left/right movement, and the blue showing hemodynamic increases to periods of rest). The colored lines show the expected HRF response.

Analyzing the dataset
- First, start Matlab
- from the Matlab command prompt, change to the directory where your data is, e.g. 'cd c:\tutorial' or 'cd "\my documents\tutorial"'
- from the Matlab command prompt, launch SPM8 by typing "spm fmri". If SPM does not launch, make sure you have downloaded SPM and it is in your Matlab path.
- Setting the origin: SPM's normalization does a great job of aligning brains from different people, but it is pretty sensitive to the origin used as an initial alignment between the image and the template. By default, scanners set the origin to be the center of the scanner, whereas SPM expects this to be the anterior commissure. It is often helpful to set your origin before processing. If you are not familiar with the anterior commissure, see my web page
- Lets set the origin. From SPM's menu window, press the "Display" button and select your highest resolution image (in the tutorial, T1s005 is our high resolution T1-weighted image).
- Images of this image are shown, you can click on the image to change the crosshair position.
- Press the thin white button under "Crosshair Position" (magenta in image below) to move the cursor to the origin (the "mm" field will be set to 0 0 0).
- Click on the MRI scan until the crosshairs are over the anterior commissure. Note that the mm away from the origin are shown in the mm location (red, green and blue correspond to the left-right, anterior-posterior and foot-head directions). Here the difference is 3.1, 42.6, -9.0mm from the initial origin. To compensate, lets put the negative of these values into the right(mm), forward (mm) and up (mm) boxes - in the example note this is -3.1mm (red), -42.6mm (green) and +9mm (blue).
- Choose the "reorient images" button and apply these translations to all our raw images. If we only shift the T1 image, it will now be out of alignment with the others. As long as you have not processed any images, only the raw images are in our folder, so it is easy to select all the images. The right hand column shows the images in your folder. As you select each image, it appears in the bottom column. Select all the images: DTI30s001, Fieldmaps006, Fieldmaps007, T1s005, fmriblocks009, fmrievents008. Note that several of these images are 4D (e.g. each fMRI file contains 302 timepoints, and the DTI data has 31 directions). Therefore, it is important to apply these transforms to ALL the images in the 4D dataset. Therefore, when the file select dialog box opens, put 0:999 in the lower filter panel and press return - you should now be able to select all the timepoints. Select all of the images and apply. The image below shows how this can be done with SPM: the upper filter box (red) allows us to filter by file name (in this example '^fmrie.*' finds all the fmrievents image files), while the lower filter (set to 1:999) allows us to select the first 999 time points for 4D files (and since our data only has 302 time points, this will highlight all our volumes). Once you select images, they appear in the lower box (cyan). When you have selected all the images, you press the 'Done' button.
- FMRI scans usually have spatial distortions that can be minimized by using a field map to measure field inhomogeneities and then djusting the fMRI data. The tutorial data includes fieldmaps data if you want to do this, but that is beyond the scope of this tutorial. If you want to do this, take a look at my fieldmap web page. For our fMRI data, the readout time was 16.96ms (echo spacing = 0.54ms, 32 lines [interpolated to 64 using GRAPPA r=2]), and the fieldmaps used echo times of 4.92 and 7.38ms.
- From the main SPM menu window, press the "Batch" button
- A new window appears showing the Batch editor. We will use this for a while...
- Choose the menu item SPM/Spatial/Realign/Realign:Estimate & Reslice from the Batch window. A new set of items appear to refine our motion correction:
- Click on the "Data" node and choose "new session"
- Click on "Session" and press the "Select Files" button. We want to select all 302 images from our 4D fMRI data named "fmrievents008.nii". An easy way to do this is to set the text filter (the edit box near "Filt") to read "^fmriev*.*" and then set the text in the line below that to read "1:999". Press return and you should be able to select all 302 images in the right column (order is important - click the first volume and then shift-click the 302nd). Once selected the image appear in the lower panel. Press done to select these files. Make sure you have selected 302 images.
- Reslice Options, Resliced Images: "Mean Image only" - motion transforms stored in file "rp_fmrievents008.mat" which lists translations and rotations. Therefore, not saving indvidual images is faster, uses less disk space and includes one less interpolation.
- Press green Go button and wait for SPM to complete.
- Click on the item "Realign" in the Module List and choose Edit/DeleteModule.
- Let's do do slice timing correction (as this is an event-related design). In the Batch Editor window, select SPM/Temporal/SliceTiming.
- Click on the "Data" node and choose "new session"
- Click on "Session" and press the "Select Files" button. We want to select all 302 images from our 4D fMRI data named "fmrievents008.nii". An easy way to do this is to set the text filter (the edit box near "Filt") to read "^fmribl*.*" and then set the text in the line below that to read "1:999". Press return and you should be able to select all 302 images in the right column (order is important - click the first volume and then shift-click the 302nd). Once selected the image appear in the lower panel. Press done to select these files. Make sure you have selected 302 images.
- Click on 'Number of slices', press the 'Edit value' and set this to 36, as each of our 3D fMRI volumes has 36 slices.
- Click on 'TR' and press 'edit value' and set this to 1.92, as each 3D fMRI volume occurs 1.92 seconds after the previous.
- Click on 'TA' and press edit value - set this to 1.87. In general, the acquisition time is as fast as possible, so this is TR*(nslices-1)/(nslices). However, be careful if you have a sparse imaging design.
- Click on 'Slice order' and set this to "[1:1:36]". This will set the order for the 36 ascending slices. If you had a different slice order,see the help for this option.
- Click on 'Refrence slice' and set this to 1 - lets adjust all the slices to appear as if they were acquired at the instant we collected the first slice.
- Press green Go button and wait for SPM to complete.
- Click on the item "Realign" in the Module List and choose Edit/DeleteModule.
- There are two options for normalization: either to estimate this directly from our EPI-based fMRI data or to use a high resolution T1 scan. In the next step I describe the latter option. However, the block design web page describes how to normalize the fMRI data directly.
- Lets normalize our data. From the Batch window, select SPM/Spatial/Segment. Note that we will use the Unifed Normalization Segment function rather than the Normalization function. In general this produces better results, as long as you have a T1 scan with good tissue contrasts.
- Click on 'Data' and then press 'Select Files' - select the T1 scan ('T1s005').
- Press green Go button and wait for SPM to complete.
- Click on the item "Segment" in the Module List and choose Edit/DeleteModule.
- I would suggest looking at the resulting looking at the resulting gray matter segmentation map ('c1T1s005' with SPM's display function or MRIcron) to ensure that the gray matter has been identified accurately. If not, you should consider checking the origin (first step of this tutorial) or use the 'normalize' function instead of 'segment'.
- Lets now apply the normalization parameters to our fMRI data. From the Batch window, select SPM/Spatial/Normalize:Write.
- Click on the "Data" node and choose "new subject"
- Click on 'Parameter file' and then press 'Select Files' - select the spatial normalization matrix file (T1s005_seg_sn.mat).
- Click on "Session" and press the "Select Files" button. We want to select all 302 images from our 4D fMRI data named "afmrievents008.nii" (note the 'a' prefix signifies it has been slice time corrected). An easy way to do this is to set the text filter (the edit box near "Filt") to read "^afmrie*.*" and then set the text in the line below that to read "1:999". Press return and you should be able to select all 302 images in the right column (order is important - click the first volume and then shift-click the 302nd). Once selected the image appear in the lower panel. Press done to select these files. Make sure you have selected 302 images.
- Click 'voxel sizes' and then choose edit value to set this to '3 3 3'. This will reslice our data to an isotropic 3mm.
- Press green Go button and wait for SPM to complete. - this will create 'w'arped images ('wafmrievents008.nii').
- Click on the item "Normalise:Write" in the Module List and choose Edit/DeleteModule.
- Lets now apply the normalization parameters to our T1 scan. This is useful for checking the quality of our normalization and creating a group mean anatomical scan. From the Batch window, select SPM/Spatial/Normalize:Write.
- Click on the "Data" node and choose "new subject"
- Click on 'Parameter file' and then press 'Select Files' - select the spatial normalization matrix file (T1s005_seg_sn.mat).
- Click on "Session" and press the "Select Files" button. .
- Click 'voxel sizes' and then choose edit value to set this to '1 1 1'. This will reslice our data to an isotropic 1mm.
- Press green Go button and wait for SPM to complete. - this will create 'w'arped images ('wafmrievents008.nii').
- Click on the item "Normalise:Write" in the Module List and choose Edit/DeleteModule.
- Now we blur our data with a gaussian. From the Batch window, select SPM/Spatial/Smooth
- Select "Images to smooth" and press select files, set the filter to "^wafmriev*.*" (note 'wa' prefix, as we want the images 'w'arped by normalization and temporally 'a'ligned by slice time correction) and set the line below to "1:999" to allow us to select all 302 images.
- Note we will keep the default 8mm full width half-maximum smooth.
- Press green Go button and wait for SPM to complete.
- Click on the item "Smooth" in the Module List and choose Edit/DeleteModule.
- Now we are ready to set up our statistics. From SPM's main window, press the "Specify 1st-level"
-
Click on "Directory" and press "Select Files", choose ".\" in the right column and press Done. This selects the current directory. If you have data from multiple subjects, the images should either be stored in separate folders, or if all the data is in a single folder you should create a separate statistics folder for each individual.
- Lets set Timing Parameters
- Units for design: Seconds
- InterscanInterval: Choose Edit value and enter your repeat time (TR) in seconds: 1.92
- Lets describe the Data & Design
- Press "New Subject/Session"
- In the new Subject/Session node that is created select "Scans" and press "Select Files". Set the filter to "^swfmrieve*.*" (note 'swa' prefix, as we want the smoothed warped aligned images) and the line below should be set to 1:999. Make sure to select all 302 volumes.
- We need to specify our conditions. On some trials the participant briefly pressed their left hands, on others the right hand was moved.
- Select "Conditions" and press "New: Condition" twice.
- For the first "Condition" node:
- Name: set to "LeftMotor"
- Select Onsets and press "Edit value" and enter the times when left hand movements started: "3 4.047 5.094 7.203 8.25 11.39 12.453 13.5 17.687 19.797 22.953 26.094 27.156 28.203 29.25 30.312 31.344 32.39 33.453 34.5 35.547 39.75 41.844 43.953 50.25 52.359 53.39 55.5 56.547 57.594 59.687 60.734 67.031 72.297 73.359 75.437 76.484 77.547 78.594 79.656 80.703 81.75 85.953 89.109 106.937 108 109.047 110.094 111.156 112.187 113.234 114.297 115.344 116.39 117.453 122.687 127.937 151.047 153.14 156.281 157.344 161.531 162.594 163.64 164.687 169.953 172.031 173.094 174.14 177.297 178.328 184.656 185.687 186.734 192 195.14 210.89 213 216.14 217.187 218.234 219.297 221.39 223.484 230.828 233.984 236.094 237.14 238.187 241.344 242.39 243.453 244.484 247.64 248.687 252.89 261.281 266.531 269.687 280.187 281.234 282.281 283.328 284.39 285.437 286.484 287.547 288.578 289.625 290.687 305.39 307.469 308.547 310.625 311.687 312.734 313.781 327.437 328.469 334.781 335.828 336.89 337.937 349.484 352.64 353.687 354.734 356.828 357.89 358.922 359.984 372.578 373.625 374.687 376.781 377.828 378.875 379.937 380.984 383.094 384.125 385.172 393.578 405.14 412.484 430.328 431.375 432.437 433.484 434.531 440.812 441.89 449.234 451.328 453.437 454.484 455.531 456.594 458.672 460.781 461.828 462.89 463.937 464.969 467.078 470.234 481.781 482.828 484.937 485.984 491.234 493.328 508.031 529.015 541.625 542.656 545.797 554.203 558.437 571.031 572.078 575.234 580.484 581.531 583.609"
- Durations: press Edit value and enter 1. We will model each hand movement as a 1 second long impulse
- For the first "Condition" node:
- Name: set to "RightMotor"
- Select Onsets and press "Edit value" and enter the times when right hand movements started: "6.156 9.297 25.047 37.64 38.687 42.906 46.047 47.094 48.14 49.203 61.797 62.844 66 74.406 84.89 91.187 97.484 98.547 99.594 100.64 101.703 102.75 103.797 104.844 105.89 118.5 119.531 123.75 124.797 125.859 126.89 128.984 138.453 141.594 142.64 143.687 144.75 145.797 146.844 147.906 148.937 149.984 152.094 166.797 176.25 180.437 181.484 182.547 183.594 198.297 199.328 200.39 201.437 202.484 203.547 205.64 206.703 207.734 208.781 209.844 214.047 215.078 222.437 224.531 227.687 228.734 229.781 231.89 232.922 240.297 246.594 250.797 254.984 257.094 258.14 259.187 260.234 262.344 263.39 265.484 274.937 275.984 302.25 303.281 304.328 309.594 314.844 315.89 316.937 317.984 320.078 322.187 323.234 324.297 325.328 326.375 332.672 338.984 340.031 341.078 342.125 343.187 344.234 345.297 346.344 347.375 348.437 350.531 351.594 355.781 366.281 367.344 368.39 369.422 370.484 371.531 389.39 391.484 395.687 397.797 399.875 400.937 401.984 403.031 404.094 406.172 410.39 413.531 415.625 418.781 421.922 422.984 424.031 426.14 427.187 428.219 429.281 437.672 438.734 450.281 476.531 479.672 480.719 483.875 488.078 495.422 499.609 500.687 501.719 502.765 503.828 504.875 505.937 506.984 509.078 510.125 513.281 522.734 523.781 524.828 525.875 526.922 527.984 530.078 531.14 532.172 533.219 535.328 546.875 547.922 548.969 550.031 551.062 552.094 555.265 556.328 557.375 564.734 568.906 569.969 573.125 574.187 576.265 578.375 582.547"
- Durations: press Edit value and enter 1. We will model each hand movement as a 1 second long impulse
- Since this is an event-related design, keep the high-pass filter at 128s.
- Press green Go button and wait for SPM to complete.
- SPM will graphically show our model. Here there are four columns, corresponding to when the individual moved their left hand (and its temporal derivative) and right hand movement (and its temporal derivative). The 302 images are shown as the vertical axis, with time starting at the top. The white bands show periods where we expect brain regions involved with that task will be especially bright. Our statistics will see which brain areas fit these predictions.
- Now we can look at our results. From SPM's main window, press the "Results"
- You will be asked to select a design, choose the "SPM.mat" we just created and press Done.
- A new window called contrast manager appears. We will want to specify 5 contrasts
- Press "Define new contrast"
- Set Name to "L>R"
- Set type to "t-contrast"
- Set contrast to 1 0 -1 0 (The coumns are LeftMotor, LeftMotor'sTemporalDerivative, RightMotor, and RightMotor'sTemporalDerivative
- press OK
- Press "Define new contrast"
- Set Name to "R>L"
- Set type to "t-contrast"
- Set contrast to -1 0 1 0
- press OK
- Press "Define new contrast"
- Set Name to "L>"
- Set type to "t-contrast"
- Set contrast to 1 0 0 0
- press OK
- Press "Define new contrast"
- Set Name to "R>"
- Set type to "t-contrast"
- Set contrast to 0 0 1 0
- press OK
- Press "Define new contrast"
- Set Name to "L+R>Rest"
- Set type to "t-contrast"
- Set contrast to 1 0 1 0
- press OK
- There are now 5 contrasts available in our contrast manager. Select the one you are interested in (e.g. "L>R") and press "Done"
- You will be asked if you want to mask the image. Click "none"
- You will be asked for a title, the default is your contrast name "L>R" select this and press enter
- You will be asked for the method to control for multiple comparisons. Click "FWE" (familywise error correction).
- You will be asked for a threshold, the suggested p <0.05 is fine
- You will be asked for a extent as a cluster threshold, the default of 0 is fine.
- A glass brain of your results now appears in the graphics screen. You can right click on the image and select functions - lets try the "go to global maximum"
- The lower left has a lot of options to control the display. Lets explore our data.
- In the "Display" column, select the "overlays..." pulldown menu and choose sections
- You will be asked to select an image, lets choose the first volume of our normalized high resolution anatomical image wT1s005.nii
- A new set of views appears. Click to inspect different regions.
- In the "p-values" column, select the "whole brain" button
- A table of active areas appears.
- Clicking on the mm column of each row highlights that cluster's location in the glass brain.
- Right click and choose "print text table" - the table appears in the Matlab command line so you can copy it to your manuscripts.