Differences between revisions 1 and 31 (spanning 30 versions)
Revision 1 as of 2004-07-22 16:35:04
Size: 967
Editor: DavidTuch
Comment:
Revision 31 as of 2007-06-18 17:40:03
Size: 35539
Editor: icebox
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
'''Index'''
[[Navigation(children)]]
#pragma section-numbers off

[wiki:Self:FreeSurferWiki top] | [wiki:Self:Tutorials previous]

This tutorial steps you through the analysis of an fMRI data set with
the FreeSurfer Functional Analysis Stream (FSFAST), from organizing
the data to group analysis.
Line 4: Line 10:
== Download the sample subject’s data ==
== Get to know the Sessions Format ==
== Make a directory for your Study ==
== Make paradigm files for your experiment ==
== Motion correct the data using “mc-sess” ==
== Normalize signal intensity using “inorm-sess” ==
== Set up session-level analysis using “mkanalysis-sessnew” ==
== Average session-level data by condition using “selxavg-sess” ==
== Define an omnibus contrast using “mkcontrast-sess” ==
== Compute statistical maps of the omnibus contrast using “stxgrinder-sess” ==
== Run functional/structural registration using “autoreg-sess” ==
== Interfacing with FreeSurfer ==
== Functional/Anatomical Registration ==
== Visualization ==
=== Visualization: slice-based using “sliceview-sess” ===
=== Viewing Bert’s hemodynamic responses ===
=== Visualization: surface-based using “paint-sess” and “surf-sess” ===

---------------------------------------------------------------------
---------------------------------------------------------------------
= Tutorial Data Description =

The data being analyzed is part of the fBIRN Phase I data set. There
are 5 subjects, each scanned twice at each of 10 sites. The data in
the tutorial is the data collected at the MGH site. The task is a
simple sensory motor blocked design experiment. During each task block
the subject was shown a flashing checkerboard and presented with an
auditory tone. During this time, the subject was asked to press
bottons with both hands. The task blocks alternated with fixation
blocks during which the subject stared at a fixation cross but
performed no other task. Each block type was 15 sec long. Each run
started with a fixation block followed by 8 pairs of task and fixation
blocks (and so ends with a fixation block) for a total run duration of
255 sec. The TR was 3 sec, so there were 85 time points. This task was
performed 4 times in each visit.Anatomicals were also collected and
analyzed in FreeSurfer for each of these subjects.

[FsFastTutorial]

---------------------------------------------------------------------
---------------------------------------------------------------------
= Getting and Organizing the Tutorial =

The tutorial requires about 10G of space. Find a location for this
data, download or copy the tarfile from XXX. Untar it with:

tar xvfz fsfast-tutorial.tar.gz

This will create a directory called fsfast-tutorial. You can now
delete the tar file. cd fsfast-tutorial. It will be assumed that you
are in this directory (or subdirectory there of) throughout the
tutorial. This directory will have five folders:

 * fb1-raw - raw fMRI data
 * fb1-raw-study - raw data origanized as an FSFAST study but unanalyzed
 * fb1-preproc-study - The same data preprocessed.
 * fb1-analysis-study - The same data analyzed
 * subjects - FreeSurfer reconstruction of anatomical data (plus the fsaverage subject).

If you look (ls) in fb1-raw, you will see that there are 20 NIFTI data
sets with names like f.mgh-10X.1-rYYY.nii. These are the 20 fMRI runs
mentioned above. X indicates the subjects number (1, 3, 4, 5, 6), and
YYY indicates the run number. The sensory-motor task happend to be
runs 3, 5, 7, and 10.

---------------------------------------------------------------------
---------------------------------------------------------------------
= Quick Visualization Tutorial (tkmedit/tksurfer) =

The purpose of this tutorial is to familarize you with how to use
FreeSurfer volume viewer (tkmedit) and surface viewer (tksurfer) in
the context of viewing functional data.You should already know how to
use tkmedit and tksurfer otherwise. See the pages below for a more
detailed handling of tkmedit and tksurfer.

== tkmedit ==
 * [wiki:Self:TkMeditGuide_2fTkMeditGeneralUsage_2fTkMeditInterface Interface] [[BR]]
 * [wiki:Self:FsTutorial/TkmeditGeneralUsage General usage] [[BR]]
 * [wiki:Self:FsTutorial/TkmeditWorkingWithData Working with data] [[BR]]
 * [wiki:Self:FsTutorial/TkmeditReference Quick reference] [[BR]]

== tksufer ==

 * [wiki:Self:TkSurferGuide_2fTkSurferGeneralUsage_2fTkSurferInterface Interface] [[BR]]
 * [wiki:Self:FsTutorial/TksurferGeneralUsage General usage] [[BR]]
 * [wiki:Self:FsTutorial/TksurferWorkingWithData Working with data] [[BR]]
 * [wiki:Self:FsTutorial/TksurferReference Quick reference] [[BR]]

== Viewing a single functional overlay in the volume ==

cd into the study with all the analyzed data:
{{{
cd fb1-analysis-study
}}}
Run tkmedit-sess (this is an FSFAST wrapper for tkmedit):
{{{
tkmedit-sess -s mgh-101.v1 -a sm-gamma-fwhm5 -c odd-v-0 -aparc+aseg
}}}
Don't worry about what all the arguments mean, this part is only about visualization.This command will bring up two windows, one with a brain image the other a control panel.

attachment:tkm-101-gam-cor.2-4.gif
attachment:tkm-101-toolswindow.gif

The brain image is the FreeSurfer anatomical for this subject. The
slightly pale colors on the anatomical indicate the FreeSurfer
automatic segmentation. The bright red/yellow/blue are super-threshold
voxels in the functional overlay. As you click on different points,
you will see the "Functional value" field in the Tools window change
as well as the "Sgmtn label".Note that areas that are not above
threshold will still have non-zero functional values. The
interpretation of the value depepends on what is being viewed. This is
a significance map, so the value is -log10(pvalue)*sign (ie, for a
pvalue = .01, the functional value will be +2). The sign is a
functional direction. The red/yellow are postive, and the blue are
negative. As a functional value gets more positive, its color will
change from red to yellow. As it gets more negative, it will change
from blue to cyan.[[BR]]

Toggle the functional overlay on and off by hitting the button with
the red/yellow blob in the Tools window (it's in the top row - if you
mouse over it, you'll see a "Show Overlay" tooltip.)[[BR]]

Configure the functional overlay by clicking on "View..." in the Tools
window, then "Configure->Functional Overlay...". You should see the
following interface:

attachment:tkm-101-config-funcoverlay.gif

The thresholds are currently set at 2 (Min) and 4 (max). The Min
threshold is the minimum absolute value needed for a voxel to show an
overlay color. The maximum is the value beyond which the voxel will
stop changing color. Try changing these values, then hit the Apply
button to see their effect.[[BR]]

So, what's all that activation OUTSIDE of the brain. Can't have that!
Try hitting View->Mask Functional Overlay to Aux button. There, now
isn't that better? And why is it so blockly? There are big voxels in
functional data, but if you'd like to pretend otherwise, try hitting
the "Trilinear" button on the Configure Functional Overlay window.

== Viewing multiple functional overlays and time courses in the volume ==
Run tkmedit-sess (this is an FSFAST wrapper for tkmedit):
{{{
tkmedit-sess -s mgh-101.v1 -a sm-fir-fwhm5 -c 1v0 -aparc+aseg
}}}

This will bring up the two windows as you saw before (the brain image
window will have a different overlay). It will also bring up a window
called "Time Course". Click anywhere in the volume, and you will see a
time course associated with that voxel similar to the one below.

attachment:tkm-101-fir.gif

The meaning of the time course depends upon the nature of the time
course loaded. In this case it is the hemodynamic response to the task
block averaged over all blocks over all runs (this is an "FIR"
model). The horizontal axis is time (0 means the onset of the
block). You can visualize the values of any multi-frame data set in
this way (it does not have to be a "time" course).[[BR]]

Notice that there is not much activation in the functional
overlay. This is good! You are looking at an overlay that corresponds
3 seconds prior to stimulus onset, so there should be no
activation. To see the other time points, bring up the functional
overlay configuration window (View->Configure->Functional
Overlay). Notice that the "Time Point" field now has a range of 0-8
indiating the 9 time points in the Time Course window. If you hit the
+ button next to "Time Point" then hit Apply, you will see the overlay
change. You will also see a vertical dashed line in the Time Course
window. You are now looking the map associated with the time between 0
and 3 sec after stimulus onset. Keep hitting the +/Apply buttons to
see different time points. You can hit the "|>" button to start a
movie of the activation (then "[]" to stop it).

== Viewing a single functional overlay on the surface ==

To view the same data on the surface run:

{{{
tksurfer-sess -s mgh-101.1 -a sm-gamma-fwhm5 -c odd-v-0 -hemi lh
}}}

Again you will see two windows, "Tksurfer Tools" and a surface image window.

= Assembling the Data in the FSFAST Hiearchy =

== The Project (or Study) Directory ==
== Create a Session ==
== Create a Stimulus Schedule (Paradigm File) ==
== Link to the FreeSurfer Anatomical Recontruction ==
== Create a SessionID File ==

= Preprocessing of fMRI Data (preproc-sess) =
== What preprocessing stages do you want to run? ==

There are up to seven types of preprocessing that are run on fMRI
data: 1. brain masking, 2. motion correction (MC), 3. slice-timing
correction (STC), 4. B0 distortion correction, 5. spatial smoothing,
6. resampling to common space, and 7. intensity normalization. Not all
packages run all of these seven, and they are not always run in the
same order, and some stages are sometimes run as post-processing. In
FSFAST, we can run 1. MC, 2. STC (optional), 3. smoothing, and
4. intensity normalization. We create a brain mask, but we do not mask
the functional data.

---------------------------------------------------------------------
---------------------------------------------------------------------
== Run preprocessing ==

To run MC and spatial smoothing by 5 mm FWHM along with brain mask creation on one session run:

{{{
cd fb1-raw-study
preproc-sess -s mgh-101.1 -fwhm 5
}}}

Note that this has already been done with all subjects in the
fb1-preproc-study directory. To preprocess all of the session, you
would run "preproc-sess -sf sessid -fwhm 5". Also note that if
preprocessing as already been performed on a session, it will
automatically skip it and move on to the next (unless you add -force
to the command-line).

== Examine additions to hierachy ==

{{{
ls mgh-101.1/bold/003
ls mgh-101.1/bold/masks
}}}

You will see f.nii (the raw data), fmc.nii (motion corrected), and
fmcsm5.nii (motion corrected and smoothed). In addition you will see
fmc.mcdat; this is a text file with the motion correctionwill
parameters (translations and rotations) as created by AFNI. You will
also see mcextreg.bhdr. This is a binary file with the orthogonalized
motion correction parameters which can later be used as nuisance
regressors when analyzing the data. These files will exist in each of
the runs (ie, 005, 007, 010). You will see a brain.nii volume in the
masks folder. This is a binary mask of the brain as found by FSL's BET
program. The functional data themselves are not masked.[[BR]]

To view the translation components, run
{{{
plot-twf-sess -s mgh-101.1 -mc
}}}
This will bring up a plot with the translations for each of the runs.

---------------------------------------------------------------------
---------------------------------------------------------------------
= Function-Structure Registration =

In order to render the functional results on the anatomical background
as well as to map the functional results into a common space for group
analysis, it is necessary to register/align the functional volume with
a structral volume. In FSFAST, we first register to the same-subject
FreeSurfer anatomical with a 6 DOF registration. We then map the
functional to Talairach/MNI305/fsaverage space by concatenating the
within-subject function/structure registration with the Talairach
registration (talariach.xfm) created when the subject was
reconstructed. For mapping to surface-based space, we concatenate the
within-subject function/structure registration with the surface-based
registration. Since we are only dealing with the functional analysis
here, we will just consider the within-subject function/structure
registration.

== View unregistered (tkregister-sess) ==

Run the following command to see how the functional and structrual are
aligned prior to performing any automatic registration.

{{{
cd fb1-preproc-sess
tkregister-sess -s mgh-101.1 -regheader
}}}
Hit the compare button.

== Run automatic registration (fslregister-sess) ==
{{{
cd fb1-preproc-sess
fslregister-sess -s mgh-101.1
}}}
When this command is complete, you will see a register.dat file in
mgh-101.1/bold. This is the only change. The functional data are not
resampled!

== Check automatic registration (tkregister-sess) ==
{{{
cd fb1-preproc-sess
tkregister-sess -s mgh-101.1 -regheader
}}}
Hit the compare button.

== Check talairach registration ==
{{{
tkregister2 --s fbph1-101 --fstal --surf
}}}

---------------------------------------------------------------------
---------------------------------------------------------------------
= First-Level Analysis =

The First-Level Analysis (FLA) consists of setting up models of the
task-related and nuisance components. The FLA is done in two
stages. In the first stage, the FLA is configured (with
mkanalysis-sess). This is done once regardless of how many data sets
you have (you do not even need to have any data to run the
configuration). In the second stage, you actualy perform the analysis
with selxavg3-sess by passing it the configuration and the session
that you want to analyze. selxavg3-sess customizes the analysis for
that session based on what it finds in the hierarchy, builds the
design matrix, and performs the analysis. Breaking the FLA up into
these two stages assures that all sessions are analyzed in the same
way.

== Configure Analysis and Contrasts I: Gamma HRF Model ==

Configuring the FLA is performed with mkanalysis-sess. When you run:
{{{
cd fb1-preproc-study
mkanalysis-sess -gui
}}}

You will see the following window:
attachment:mkana-startup.gif

You will use this window to specify the input of the analysis, the
hemodynamic response model, contrasts, and nuisance regressors. The
red fields are field that you must enter before you can save the
analysis. There is a lot going on with this GUI, so we'll break it
down. Note that many of the components have "tooltips" that will show
when you pause the mouse pointer over them.

In the upper left corner is a panel called "FS-FAST Hiearchy". The
"Func Stem" is the input to the analysis. You should specify the
output from the preprocessing. For this excercise, we are going to use
the motion corrected and 5mm smoothed data. This functional volume is
called fmcsm5.nii in the hiearchy which makes its stem "fmcsm5" (ie,
just strip off the nii). Enter "fmcsm5" into the field. When you hit
return, it changes from red to white. Next, enter the TR (sec). For
this experiment it was 3 sec. This will be checked against the TR
found in the input nifti file. Leave INorm checked.

Turn your attention to the "Noise and Nuisance Variables" panel. Low
frequency noise so prevelant in fMRI is compensated for in a
combination of three ways. Drift components are modeled with
polynomial regressors. The order can be adjusted, but leave it at 2
for now. The motion correction parameters can be used as regressors by
checking the "MC Regressors" box (do so now). Finally, the remaining noise is
modeled as time-invariant linear AR1 process when the "Temporal
Whitening" box is checked (leave it so). There is one additionaly way
to compensate for noise through the use of a "Time Point Exlucde
File", but we will not consider that here.

You will specify the model of the task-related signal in the "Event
Related/Block Design" panel (leave that box checked). Choose the
number of conditions by clicking on the "NConditions" slider. This is
the number of TASK conditions (do not include the Null/Fixation
condition). In this example, we have two conditions (Odd and Even), so
adjust this to 2. To the right of this is the "Paradigm File". Enter
"sensory-motor.par". Note that the number of task conditions in the
paradigm file must match that specified with "NConditions". Below, you
will specify the Hemodynamic Response Model. There are three choices:
Gamma, SPM HRF, and FIR. Choose Gamma for now. If you hit the "Plot"
button it will show the Gamma and SPM HRF. As you change the Gamma
paraters (Delay, Dispersion (Tau), and Exponent (Alpha)), the Gamma
plot will change. Make sure that they are at Delay=2.25, Tau=1.25, and
Alpha=2.

At this point, you have specified the model of the BOLD signal
including HRF, nuisance, and noise. The GUI should look like the image
below:

attachment:mkana-gamma-precon.gif

Now you are ready to specify contrasts. A contrast is an instantiation
of a hypothesis and is represented by a contrast matrix (ie, a linear
summation of the regression coefficients). Contrasts are managed
through a separate GUI accessed through the "Contrast" list box. When
you click on "Add Contrast", you will see the following screen:

attachment:mkcon-gam-startup.gif

There are several things going on here, but the most important is the
list of condtitions in the middle of the GUI (ie, "Condition 1",
"Condition 2") will green, red, and black radio buttons. Green
indicates an "active" condition; red means a "control" condition, and
black means to ignore the condition in the contrast. Active conditions
are given a weight of +1; controls are given -1; ignores get 0. The
weight is given to the right of the buttons. All contrasts are
implicitly computed against the Null or Fixation condition. If you
want to test the null hypothesis that Condition 1 is no different than
the Null condition, then you would make Condition 1 active and ignore
the rest. To test the null hypothesis that Condition 1 is no different
than Condition 2, then you would make Condition 1 active and Condition
2 control.

For this exercise, we are going to test four NULL hypotheses:

 * Odd == Fixation (odd-v-0)
 * Even == Fixation (even-v-0)
 * Odd == Even (odd-v-even)
 * Odd+Even == Fixation (odd-+even)

The last one tests whether the average of the responses to odd and
even are different than fixation. Remember that, according to the
Paradigm File, Condition 1 is Odd, and Condition 2 is Even. When "Add
Contrast" is clicked, "Condition 1" will be active and Condition 2
will be ignored. This corresponds to our first contrast, so there is
nothing we need to do except give the contrast a name. You should give
your contrasts meaningful but terse names. Specify "odd-v-0" for this
contrast. Hit the "Done/Save" button. You will now see "odd-v-0"
appear in the Contrast list box in the mkanalyiss GUI.

Click on "Add Contrast" again to bring up the contrast GUI
again. This time, click on the green button next to Condition 2 (see
its weight change from 0 to 1). Then click on the black button next
to Condition 1 (see weight change from 1 to 0). Change the name to
"even-v-0", then click Done/Save. "even-v-0" will appear in the list
box.

Click on "Add Contrast" again, and click the red button next to
Condition 2 (see its weight change from 0 to -1). Change the name to
"odd-v-even", then click Done/Save.

Click on "Add Contrast" one more time, and click the green button next to
Condition 2 (see its weight change from 0 to +1). Change the name to
"odd+even", then click Done/Save.

You can go back and view and/or edit an contrast by clicking on it in
the list box.

The last thing you have to do is to give your analysis a name. Like
the contrasts, it should be terse but descriptive (it cannot have any
spaces or blanks). Specify "sm-gamma-fwhm5" (sm = sensory-motor, gamma
= Gamma HRF, and fwhm5 for the input). The interface should now look
like:

attachment:mkana-gamma-done.gif

Hit the "Save" button, then "Quit".

After you hit Quit, control will be returned to the shell that you ran
mkanalysis-sess from. If you type "ls", you will see a new folder
called "sm-gamma-fwhm5". If you "ls sm-gamma-fwhm5", you will see
analysis.info, analysis.cfg, odd-v-0.mat, even-v-0.mat,
odd-v-even.mat, odd+even.mat. Your configuration is stored in these
files. You can browse/edit your configuration by running:

{{{
mkanalysis-sess -gui -analysis sm-gamma-fwhm5
}}}

== Configure Analysis and Contrasts II: FIR HRF Model ==

Now we are going to use a Finit Impulse Response (FIR) to model the
hemodynamic response. The FIR does not make any assumptions about the
shape of the HRF but is also less interpretable. Again, run

{{{
cd fb1-preproc-study
mkanalysis-sess -gui
}}}

Set the Func Stem, TR, NConditions, and Paradigm File as above, but
now click on the "FIR" checkbox. This will enable the "Total Time
Window", "PreStim", and "TER" entry boxes. The Time Window is the
window within which we will estimate the HRF. Given that the task is
15 sec long and the rest is 15 sec, let's choose 27 sec. The PreStim
is the amount of time before stimulus onset to start estimating the
HRF. A non-zero PreStim gives us an idea of what the baseline is at
stimulus onset. Set it to 6.

Setup the same contrasts as you did above, then name the analysis
"sm-fir-fwhm5", hit Save, then Quit.

== Analyze First Level (selxavg3-sess) ==

You are now ready to analyze some data! Note that the fully analyzed
data (along with correctly configured analyses) can be found in
fb1-analysis-study. To analyze the data for session mgh-101.1 with the
sm-gamma-fwhm5 analysis, run:

{{{
cd fb1-preproc-study
selxavg3-sess -s mgh-101.1 -analysis sm-gamma-fwhm5
}}}

Note that if you want to analyze all the sessions, you can run
"selxavg3-sess -sf sessid -analysis sm-gamma-fwhm5".

To analyze the data for session mgh-101.1 with the sm-fir-fwhm5
analysis, run:
{{{
cd fb1-preproc-study
selxavg3-sess -s mgh-101.1 -analysis sm-fir-fwhm5
}}}

== Examine additions to the hierarchy ==

{{{
ls mgh-101.1/bold
ls mgh-101.1/bold/sm-gamma-fwhm5
ls mgh-101.1/bold/sm-gamma-fwhm5/odd-v-0
}}}

== Visualize ==

=== Volume-based visualization (tkmedit-sess) ===

View the result of the Gamma HRF analysis on the FreeSurfer anatomical
volume for mgh-101.1 with:
{{{
cd fb1-analysis-study
tkmedit-sess -s mgh-101.1 -aparc+aseg -analysis sm-gamma-fwhm5 \
  -c odd-v-0 -c even-v-0 -c odd+even -c odd-v-even
}}}
When you configure the functional overlay with
View->Configure->Functional Overlay, you will see that there are 4
"Time Points". Each point is different contrast (ie, 0 is odd-v-0, 1
is even-v-0, etc). Scroll through each one.

View the result of the HRF HRF analysis for mgh-101.1 with:
{{{
cd fb1-analysis-study
tkmedit-sess -s mgh-101.1 -aparc+aseg -analysis sm-fir-fwhm5 -c odd-v-0
}}}
Here we view only one contrast at a time because each contrast has
multiple time points for each point in the time window. Note that
there is less activation than the Gamma HRF. When you click on a
point, you will see the HRF for both Condition 1 (Odd) and Condition 2
(Even) blocks.

Finally, view the overlay maps from the Gamma with the HRF from the FIR:
{{{
cd fb1-analysis-study
tkmedit-sess -s mgh-101.1 -aparc+aseg -analysis sm-fir-fwhm5 \
  -mapanalysis sm-gamma-fwhm5 -c odd-v-0 -c even-v-0 -c odd+even -c odd-v-even
}}}
When you configure the overlay, you will see that there are 4 "Time
Points" -- these correspond to the 4 contrasts from the Gamma analysis.

=== Surface-based visualization (tksurfer-sess) ===
View the result of the Gamma HRF analysis on the FreeSurfer anatomical
surface for mgh-101.1 with:
{{{
cd fb1-analysis-study
tksurfer-sess -hemi lh -aparc -s mgh-101.1 -analysis sm-gamma-fwhm5 \
  -c odd-v-0 -c even-v-0 -c odd+even -c odd-v-even
}}}
Note that the command-line is nearly identical to that of tkmedit
above. The difference is that the hemisphere is specified ("-hemi
lh"), and "-aparc+aseg" is replaced with "-aparc" to load the
surface-based segmentation.

---------------------------------------------------------------------
---------------------------------------------------------------------

= Higher-Level (Group) Analysis =

Higher-Level is where you make inferences about the population that
your subjects are drawn from. It is a bit confusing at times because
both use GLMs, so at both levels you are constructing design matrices,
contrasts, etc. Traditionally, fMRI group analysis has been done in a
standard volume space (ie, Talairach/MNI152/MNI305). With FreeSurfer,
we also have the option to analyze group data in the surface
space. Volume-based analyses are done in MNI305 space (which is the
same as the fsaverage subject).

== Assemble the Data (isxconcat-sess) ==

The first step in the group analysis is to "assemble" the data. This
means creating a single 4D file with where the 4th "time" dimension is
actual all the subjects concatenated together in a common space. There is a
different command, depending upon whether the common space is volume-
or surface-based.

For the next exercises, we will work in the fb1-analysis-study directory
{{{
cd fb1-analysis-study
}}}
All the first level analyses have been done here. The group-level
analyses have been done in the group-analysis-tut directory.

=== Volume-based (MNI305/fsaverage) ===

To run the volume-based concatenation, run the command below. Note
that the data from this command already exist in the
group-analysis-tut directory.

{{{
isxconcat-sess -sf sessid -analysis sm-gamma-fwhm5 -c odd-v-0 -o group-analysis
}}}

This command will go through each session in the sessid file, find the
odd-v-0 contrast in the sm-gamma-fwhm5 analysis, use the register.dat
for that session to resample to MNI305/fsaverage space. These are all
concatenated together and saved in
group-analysis/sm-gamma-fwhm5/odd-v-0/tal.ces.nii file. You can run
other contrasts by adding -c arguments. In addition to this output,
several other files are created. To see them,

{{{
ls group-analysis-tut/sm-gamma-fwhm5
cat group-analysis-tut/sm-gamma-fwhm5/sessid
cat group-analysis-tut/sm-gamma-fwhm5/ffxdof.dat
}}}

In the output directory, you will see a series of files that start
with "tal". tal.meanfunc.nii is a stack where each "time point" is the
mean functional image of each subject sampled in the MNI305 space.
tal.masks.nii are the binary masks for all the subjects, and
tal.fsnr.nii are the functional SNR maps from each
subject. tal.mask.nii is a single binary mask made from the
intersection of the individuals. ffxdof.dat is the fixed-effects DOF
across all subjects. sessid.txt is the list of sessions, the
corresponding freesurfer subject name, and the DOF contributed by each
subject.

You will also see some files that being with "lh". These are the same
thing in the surface-based space.

Now look in the directory for odd-v-0 the contrast
{{{
ls group-analysis/sm-gamma-fwhm5/odd-v-0
}}}

You will see tal.ces.nii. These are the contrast maps for eaah of the
subjects, and tal.cesvar.nii are the variance of the contrast for each
subject (ie, the square of the standard error). This variance is
needed for fixed-effects and weighted random-effects analysis. You'll
also see a bunch of directories with "osgm". Ignore those for a
moment.

==== Quality Assurance ====

There are three important quality assurance steps that can be perfomed
here. First, view the mean funcitonals to make sure that all are
registered together properly. To do this run,

{{{
tkregister2 --s fsaverage --surf --regheader --check-reg \
  --mov group-analysis-tut/sm-gamma-fwhm5/tal.meanfunc.nii \
}}}
The image window will show the MNI305 brain. Hit the "Compare" button
to show the average functional of the first session. Click in the
image window, then hit the 'a' key. Each time you hit the 'a' key, it
will advance to the next subject.

The next QA step is to check the individual masks. This can be done
with:
{{{
tkmedit fsaverage orig.mgz \
  -overlay group-analysis-tut/sm-gamma-fwhm5/tal.masks.nii -fthresh 0.5
}}}
The threshold of 0.5 is appropriate because these masks are binary
(ie 0-1). When you View->Configure->Functional Overlay, you will see
that there are 5 "Time Points" (0-4) corresponding to the 5 subjects.
Advance through each one to assure that the masks are in the proper place.

The final step is to look at the functional SNR maps with
{{{
tkmedit fsaverage orig.mgz \
  -overlay group-analysis-tut/sm-gamma-fwhm5/tal.fsnr.nii \
  -timecourse group-analysis-tut/sm-gamma-fwhm5/tal.fsnr.nii \
  -fthresh 50 -fmax 250
}}}
Again, when you View->Configure->Functional Overlay, you will see
that there are 5 "Time Points" (0-4) corresponding to the 5 subjects.
Advance through each one to assure that the SNR maps are
"consistent". When you click on a voxel, you will see the SNR for each
subject plotted in the "Time Course" window. The actual value of the
FSNR will vary depending upon how much smoothing you've done and the
details of the acquisition. You are looking for outliers here.

==== Group GLM Analysis ====
When you perform a group analysis, you are looking for effects of the
task across the population. In this example, we only going to test
whether the mean effect of Odd vs Fixation (odd-v-0) is different than
0. This is known as a one-sample-group-mean (OSGM) and corresponds to
a group design matrix that is simply a column of 1s. One can perform
considerably more elaborate tests (eg, differences in groups). Now, cd
to where the data are:

{{{
cd group-analysis-tut/sm-gamma-fwhm5/odd-v-0
}}}

===== Random Effects (RFx, OLS) =====
Random effects is a test of whether the mean of the population that
the subjects were drawn from is 0. It is done with mri_glmfit:

{{{
mri_glmfit --y tal.ces.nii --osgm --mask ../tal.mask.nii --glmdir tal.rfx.osgm --nii
}}}

tal.ces.nii are the inputs for this contrast for all subjects. --osgm
tells it to create the simple OSGM design matrix and to create a group
contrast to test the group mean against 0. The mask is used to exclude
extra-brain voxels. The results will be stored in tal.rfx.osgm:

{{{
ls tal.rfx.osgm
ls tal.rfx.osgm/osgm
}}}

You will see several files in the output. beta.nii is the map of
regression coefficients. There is also an "osgm" folder with
sig.nii. This is a map of the significances of the test. We will view
it below.

===== Weighted Random Effects (WRFx, WLS) =====
In a real experiment, some subjects are noisier than others, and it is
a good idea to take this into account since we have information about
how noisy a subject is through the lower-level analysis. In weighted
least squares (WLS), this is handled by weighting each subject by the
inverse of their noise (ie, noiser subjects get lower weight). To do
this with mri_glmfit, run:

{{{
mri_glmfit --y tal.ces.nii --osgm --glmdir tal.wrfx.osgm --nii --mask ../tal.mask.nii \
    --wls tal.cesvar.nii
}}}

The command-line is almost the same as the RFx except that the
first-level noise variances (tal.cesvar.nii) are passed with the --wls
option. The results are saved in tal.wrfx.osgm and have the same
naming convension as the RFx.

===== Fixed Effects (FFx) =====
A fixed effects analysis tests whether an effect exists within the
given subject pool (as opposed to the population that the subjects
were pulled from). It is like doing one big fist-level analysis. The
big difference with RFx or WRFx is that the variance is computed from
the lower level analysis variance. This is done in mri_glmfit with:

{{{
mri_glmfit --y tal.ces.nii --osgm --glmdir tal.ffx.osgm --nii --mask ../tal.mask.nii \
   --yffxvar tal.cesvar.nii --ffxdofdat ../ffxdof.dat
}}}

Again, the command-line is similar to above, except that the lower
level variances are passed with --yffxvar, and the total lower level
DOFs are passed with --ffxdofdat.

===== Output and visualization =====
To visualize these three analyses, we will first concatenate them into
one file to make it easier to view in tkmedit:

{{{
mri_concat tal.rfx.osgm/osgm/sig.nii \
           tal.wrfx.osgm/osgm/sig.nii \
           tal.ffx.osgm/osgm/sig.nii \
        --o all.sig.nii)
tkmedit fsaverage orig.mgz -aux brain.mgz -bc-main-fsavg \
     -overlay all.sig.nii -fthresh 2 -fmax 4
}}}
Configure the overlay with View->Configure->Functional Overlay. Scroll
through the "time" points to see the differences in the analyses.

===== Correction for Multiple Comparisons/Cluster Analysis =====

With so many voxels in fMRI maps, it is very likely that many voxels
will appear to be active purely by random chance (ie, a false
positive). The is known as the "Problem of Multiple Comparions". One
way around this is to do a cluster analysis in which active voxels are
eliminated unless they appear in a cluster, the idea being that false
positives will not appear next to each other. To do this in FSFAST,
run the following command on the RFx analysis:

{{{
mri_volcluster --in tal.rfx.osgm/osgm/sig.nii --thmin 2 \
   --fwhmdat tal.rfx.osgm/fwhm.dat --cwpvalthresh 0.1 \
   --mask tal.rfx.osgm/mask.nii --fsaverage \
   --sum tal.rfx.osgm/osgm/cluster.sum \
   --cwsig tal.rfx.osgm/osgm/cwsig.cluster.nii \
   --out tal.rfx.osgm/osgm/sig.cluster.nii \
   --ocn tal.rfx.osgm/osgm/ocn.cluster.nii
}}}

In this command we use the signifiance map as input thresholded at 2,
where 2 is -log10(p), so p < .01. The --fwhmdat option tells
mri_volcluster to use the spatial smoothness estimate from GLM
analysis (saved in tal.rfx.osgm/fwhm.dat). The "--cwpvalthresh 0.1"
tells it to ignore clusters unless their p-value is less than 0.1 (you
can threshold more stringently later on).

One of the outputs is a cluster table (cluster.sum). This is a text
file with the list of clusters. View it with:

{{{ more tal.rfx.osgm/osgm/cluster.sum }}} You can also see it here:
FsFastTutorial/ClusterSummary. The table shows the size of each
cluster in voxels and mm^3, the Talairach coordinate, the maximum
significance in the cluster, and the clusterwise p-value (CWP). Some
of them are 0, meaning that the p-value was so low that it could not
be computed (remember, this is a good thing!).

The other outputs are volumes. cwsig.cluster.nii is a map of the
clusters with the voxel value equal to the -log10(pvalue) of the
cluster that the voxel is associated with. sig.cluster.nii is the
original sig map with non-cluster voxels removed. ocn.cluster.nii is a
map where the value at each voxel is replaced by the number of the
cluster that the voxel is associated with. View the clusterwise
significance:

}}}
tkmedit fsaverage orig.mgz -aux brain.mgz -bc-main-fsavg \
     -overlay tal.rfx.osgm/osgm/cwsig.cluster.nii -fthresh 2 -fmax 4
}}}

=== Surface-based ===

TBD


= FsFast Tutorial SlideShow =

[[Navigation(slideshow)]]

 * ["/000 Frontmatter"]
 * ["/300 Download data"]
 * ["/400 Get familiar with sessions format"]
 * ["/500 Make a directory for your study"]
 * ["/600 Make paradigm files for your experiment"]
 * ["/700 Motion correct the data"]
 * ["/800 Normalize signal intensity"]
 * ["/900 Set up session-level analysis"]
 * ["/905 Average session-level data by condition"]
 * ["/910 Define an omnibus contrast"]
 * ["/920 Compute statistical maps of the omnibus contrast"]
 * ["/930 Run functional and structural registration"]
 * ["/940 Visualization"]

[wiki:FreeSurferWiki top] | [wiki:Tutorials previous]

This tutorial steps you through the analysis of an fMRI data set with the FreeSurfer Functional Analysis Stream (FSFAST), from organizing the data to group analysis.

TableOfContents



Tutorial Data Description

The data being analyzed is part of the fBIRN Phase I data set. There are 5 subjects, each scanned twice at each of 10 sites. The data in the tutorial is the data collected at the MGH site. The task is a simple sensory motor blocked design experiment. During each task block the subject was shown a flashing checkerboard and presented with an auditory tone. During this time, the subject was asked to press bottons with both hands. The task blocks alternated with fixation blocks during which the subject stared at a fixation cross but performed no other task. Each block type was 15 sec long. Each run started with a fixation block followed by 8 pairs of task and fixation blocks (and so ends with a fixation block) for a total run duration of 255 sec. The TR was 3 sec, so there were 85 time points. This task was performed 4 times in each visit.Anatomicals were also collected and analyzed in FreeSurfer for each of these subjects.

[FsFastTutorial]



Getting and Organizing the Tutorial

The tutorial requires about 10G of space. Find a location for this data, download or copy the tarfile from XXX. Untar it with:

tar xvfz fsfast-tutorial.tar.gz

This will create a directory called fsfast-tutorial. You can now delete the tar file. cd fsfast-tutorial. It will be assumed that you are in this directory (or subdirectory there of) throughout the tutorial. This directory will have five folders:

  • fb1-raw - raw fMRI data
  • fb1-raw-study - raw data origanized as an FSFAST study but unanalyzed
  • fb1-preproc-study - The same data preprocessed.
  • fb1-analysis-study - The same data analyzed
  • subjects - FreeSurfer reconstruction of anatomical data (plus the fsaverage subject).

If you look (ls) in fb1-raw, you will see that there are 20 NIFTI data sets with names like f.mgh-10X.1-rYYY.nii. These are the 20 fMRI runs mentioned above. X indicates the subjects number (1, 3, 4, 5, 6), and YYY indicates the run number. The sensory-motor task happend to be runs 3, 5, 7, and 10.



Quick Visualization Tutorial (tkmedit/tksurfer)

The purpose of this tutorial is to familarize you with how to use FreeSurfer volume viewer (tkmedit) and surface viewer (tksurfer) in the context of viewing functional data.You should already know how to use tkmedit and tksurfer otherwise. See the pages below for a more detailed handling of tkmedit and tksurfer.

tkmedit

tksufer

Viewing a single functional overlay in the volume

cd into the study with all the analyzed data:

cd fb1-analysis-study

Run tkmedit-sess (this is an FSFAST wrapper for tkmedit):

tkmedit-sess -s mgh-101.v1 -a sm-gamma-fwhm5 -c odd-v-0 -aparc+aseg

Don't worry about what all the arguments mean, this part is only about visualization.This command will bring up two windows, one with a brain image the other a control panel.

attachment:tkm-101-gam-cor.2-4.gif attachment:tkm-101-toolswindow.gif

The brain image is the FreeSurfer anatomical for this subject. The slightly pale colors on the anatomical indicate the FreeSurfer automatic segmentation. The bright red/yellow/blue are super-threshold voxels in the functional overlay. As you click on different points, you will see the "Functional value" field in the Tools window change as well as the "Sgmtn label".Note that areas that are not above threshold will still have non-zero functional values. The interpretation of the value depepends on what is being viewed. This is a significance map, so the value is -log10(pvalue)*sign (ie, for a pvalue = .01, the functional value will be +2). The sign is a functional direction. The red/yellow are postive, and the blue are negative. As a functional value gets more positive, its color will change from red to yellow. As it gets more negative, it will change from blue to cyan.BR

Toggle the functional overlay on and off by hitting the button with the red/yellow blob in the Tools window (it's in the top row - if you mouse over it, you'll see a "Show Overlay" tooltip.)BR

Configure the functional overlay by clicking on "View..." in the Tools window, then "Configure->Functional Overlay...". You should see the following interface:

attachment:tkm-101-config-funcoverlay.gif

The thresholds are currently set at 2 (Min) and 4 (max). The Min threshold is the minimum absolute value needed for a voxel to show an overlay color. The maximum is the value beyond which the voxel will stop changing color. Try changing these values, then hit the Apply button to see their effect.BR

So, what's all that activation OUTSIDE of the brain. Can't have that! Try hitting View->Mask Functional Overlay to Aux button. There, now isn't that better? And why is it so blockly? There are big voxels in functional data, but if you'd like to pretend otherwise, try hitting the "Trilinear" button on the Configure Functional Overlay window.

Viewing multiple functional overlays and time courses in the volume

Run tkmedit-sess (this is an FSFAST wrapper for tkmedit):

tkmedit-sess -s mgh-101.v1 -a sm-fir-fwhm5 -c 1v0 -aparc+aseg

This will bring up the two windows as you saw before (the brain image window will have a different overlay). It will also bring up a window called "Time Course". Click anywhere in the volume, and you will see a time course associated with that voxel similar to the one below.

attachment:tkm-101-fir.gif

The meaning of the time course depends upon the nature of the time course loaded. In this case it is the hemodynamic response to the task block averaged over all blocks over all runs (this is an "FIR" model). The horizontal axis is time (0 means the onset of the block). You can visualize the values of any multi-frame data set in this way (it does not have to be a "time" course).BR

Notice that there is not much activation in the functional overlay. This is good! You are looking at an overlay that corresponds 3 seconds prior to stimulus onset, so there should be no activation. To see the other time points, bring up the functional overlay configuration window (View->Configure->Functional Overlay). Notice that the "Time Point" field now has a range of 0-8 indiating the 9 time points in the Time Course window. If you hit the + button next to "Time Point" then hit Apply, you will see the overlay change. You will also see a vertical dashed line in the Time Course window. You are now looking the map associated with the time between 0 and 3 sec after stimulus onset. Keep hitting the +/Apply buttons to see different time points. You can hit the "|>" button to start a movie of the activation (then "[]" to stop it).

Viewing a single functional overlay on the surface

To view the same data on the surface run:

tksurfer-sess -s mgh-101.1 -a sm-gamma-fwhm5 -c odd-v-0 -hemi lh

Again you will see two windows, "Tksurfer Tools" and a surface image window.

Assembling the Data in the FSFAST Hiearchy

The Project (or Study) Directory

Create a Session

Create a Stimulus Schedule (Paradigm File)

Create a SessionID File

Preprocessing of fMRI Data (preproc-sess)

What preprocessing stages do you want to run?

There are up to seven types of preprocessing that are run on fMRI data: 1. brain masking, 2. motion correction (MC), 3. slice-timing correction (STC), 4. B0 distortion correction, 5. spatial smoothing, 6. resampling to common space, and 7. intensity normalization. Not all packages run all of these seven, and they are not always run in the same order, and some stages are sometimes run as post-processing. In FSFAST, we can run 1. MC, 2. STC (optional), 3. smoothing, and 4. intensity normalization. We create a brain mask, but we do not mask the functional data.



Run preprocessing

To run MC and spatial smoothing by 5 mm FWHM along with brain mask creation on one session run:

cd fb1-raw-study
preproc-sess -s mgh-101.1 -fwhm 5

Note that this has already been done with all subjects in the fb1-preproc-study directory. To preprocess all of the session, you would run "preproc-sess -sf sessid -fwhm 5". Also note that if preprocessing as already been performed on a session, it will automatically skip it and move on to the next (unless you add -force to the command-line).

Examine additions to hierachy

ls mgh-101.1/bold/003
ls mgh-101.1/bold/masks

You will see f.nii (the raw data), fmc.nii (motion corrected), and fmcsm5.nii (motion corrected and smoothed). In addition you will see fmc.mcdat; this is a text file with the motion correctionwill parameters (translations and rotations) as created by AFNI. You will also see mcextreg.bhdr. This is a binary file with the orthogonalized motion correction parameters which can later be used as nuisance regressors when analyzing the data. These files will exist in each of the runs (ie, 005, 007, 010). You will see a brain.nii volume in the masks folder. This is a binary mask of the brain as found by FSL's BET program. The functional data themselves are not masked.BR

To view the translation components, run

plot-twf-sess -s mgh-101.1 -mc

This will bring up a plot with the translations for each of the runs.



Function-Structure Registration

In order to render the functional results on the anatomical background as well as to map the functional results into a common space for group analysis, it is necessary to register/align the functional volume with a structral volume. In FSFAST, we first register to the same-subject FreeSurfer anatomical with a 6 DOF registration. We then map the functional to Talairach/MNI305/fsaverage space by concatenating the within-subject function/structure registration with the Talairach registration (talariach.xfm) created when the subject was reconstructed. For mapping to surface-based space, we concatenate the within-subject function/structure registration with the surface-based registration. Since we are only dealing with the functional analysis here, we will just consider the within-subject function/structure registration.

View unregistered (tkregister-sess)

Run the following command to see how the functional and structrual are aligned prior to performing any automatic registration.

cd fb1-preproc-sess
tkregister-sess -s mgh-101.1 -regheader

Hit the compare button.

Run automatic registration (fslregister-sess)

cd fb1-preproc-sess
fslregister-sess -s mgh-101.1

When this command is complete, you will see a register.dat file in mgh-101.1/bold. This is the only change. The functional data are not resampled!

Check automatic registration (tkregister-sess)

cd fb1-preproc-sess
tkregister-sess -s mgh-101.1 -regheader

Hit the compare button.

Check talairach registration

tkregister2 --s fbph1-101 --fstal --surf



First-Level Analysis

The First-Level Analysis (FLA) consists of setting up models of the task-related and nuisance components. The FLA is done in two stages. In the first stage, the FLA is configured (with mkanalysis-sess). This is done once regardless of how many data sets you have (you do not even need to have any data to run the configuration). In the second stage, you actualy perform the analysis with selxavg3-sess by passing it the configuration and the session that you want to analyze. selxavg3-sess customizes the analysis for that session based on what it finds in the hierarchy, builds the design matrix, and performs the analysis. Breaking the FLA up into these two stages assures that all sessions are analyzed in the same way.

Configure Analysis and Contrasts I: Gamma HRF Model

Configuring the FLA is performed with mkanalysis-sess. When you run:

cd fb1-preproc-study
mkanalysis-sess -gui

You will see the following window: attachment:mkana-startup.gif

You will use this window to specify the input of the analysis, the hemodynamic response model, contrasts, and nuisance regressors. The red fields are field that you must enter before you can save the analysis. There is a lot going on with this GUI, so we'll break it down. Note that many of the components have "tooltips" that will show when you pause the mouse pointer over them.

In the upper left corner is a panel called "FS-FAST Hiearchy". The "Func Stem" is the input to the analysis. You should specify the output from the preprocessing. For this excercise, we are going to use the motion corrected and 5mm smoothed data. This functional volume is called fmcsm5.nii in the hiearchy which makes its stem "fmcsm5" (ie, just strip off the nii). Enter "fmcsm5" into the field. When you hit return, it changes from red to white. Next, enter the TR (sec). For this experiment it was 3 sec. This will be checked against the TR found in the input nifti file. Leave INorm checked.

Turn your attention to the "Noise and Nuisance Variables" panel. Low frequency noise so prevelant in fMRI is compensated for in a combination of three ways. Drift components are modeled with polynomial regressors. The order can be adjusted, but leave it at 2 for now. The motion correction parameters can be used as regressors by checking the "MC Regressors" box (do so now). Finally, the remaining noise is modeled as time-invariant linear AR1 process when the "Temporal Whitening" box is checked (leave it so). There is one additionaly way to compensate for noise through the use of a "Time Point Exlucde File", but we will not consider that here.

You will specify the model of the task-related signal in the "Event Related/Block Design" panel (leave that box checked). Choose the number of conditions by clicking on the "NConditions" slider. This is the number of TASK conditions (do not include the Null/Fixation condition). In this example, we have two conditions (Odd and Even), so adjust this to 2. To the right of this is the "Paradigm File". Enter "sensory-motor.par". Note that the number of task conditions in the paradigm file must match that specified with "NConditions". Below, you will specify the Hemodynamic Response Model. There are three choices: Gamma, SPM HRF, and FIR. Choose Gamma for now. If you hit the "Plot" button it will show the Gamma and SPM HRF. As you change the Gamma paraters (Delay, Dispersion (Tau), and Exponent (Alpha)), the Gamma plot will change. Make sure that they are at Delay=2.25, Tau=1.25, and Alpha=2.

At this point, you have specified the model of the BOLD signal including HRF, nuisance, and noise. The GUI should look like the image below:

attachment:mkana-gamma-precon.gif

Now you are ready to specify contrasts. A contrast is an instantiation of a hypothesis and is represented by a contrast matrix (ie, a linear summation of the regression coefficients). Contrasts are managed through a separate GUI accessed through the "Contrast" list box. When you click on "Add Contrast", you will see the following screen:

attachment:mkcon-gam-startup.gif

There are several things going on here, but the most important is the list of condtitions in the middle of the GUI (ie, "Condition 1", "Condition 2") will green, red, and black radio buttons. Green indicates an "active" condition; red means a "control" condition, and black means to ignore the condition in the contrast. Active conditions are given a weight of +1; controls are given -1; ignores get 0. The weight is given to the right of the buttons. All contrasts are implicitly computed against the Null or Fixation condition. If you want to test the null hypothesis that Condition 1 is no different than the Null condition, then you would make Condition 1 active and ignore the rest. To test the null hypothesis that Condition 1 is no different than Condition 2, then you would make Condition 1 active and Condition 2 control.

For this exercise, we are going to test four NULL hypotheses:

  • Odd == Fixation (odd-v-0)
  • Even == Fixation (even-v-0)
  • Odd == Even (odd-v-even)
  • Odd+Even == Fixation (odd-+even)

The last one tests whether the average of the responses to odd and even are different than fixation. Remember that, according to the Paradigm File, Condition 1 is Odd, and Condition 2 is Even. When "Add Contrast" is clicked, "Condition 1" will be active and Condition 2 will be ignored. This corresponds to our first contrast, so there is nothing we need to do except give the contrast a name. You should give your contrasts meaningful but terse names. Specify "odd-v-0" for this contrast. Hit the "Done/Save" button. You will now see "odd-v-0" appear in the Contrast list box in the mkanalyiss GUI.

Click on "Add Contrast" again to bring up the contrast GUI again. This time, click on the green button next to Condition 2 (see its weight change from 0 to 1). Then click on the black button next to Condition 1 (see weight change from 1 to 0). Change the name to "even-v-0", then click Done/Save. "even-v-0" will appear in the list box.

Click on "Add Contrast" again, and click the red button next to Condition 2 (see its weight change from 0 to -1). Change the name to "odd-v-even", then click Done/Save.

Click on "Add Contrast" one more time, and click the green button next to Condition 2 (see its weight change from 0 to +1). Change the name to "odd+even", then click Done/Save.

You can go back and view and/or edit an contrast by clicking on it in the list box.

The last thing you have to do is to give your analysis a name. Like the contrasts, it should be terse but descriptive (it cannot have any spaces or blanks). Specify "sm-gamma-fwhm5" (sm = sensory-motor, gamma = Gamma HRF, and fwhm5 for the input). The interface should now look like:

attachment:mkana-gamma-done.gif

Hit the "Save" button, then "Quit".

After you hit Quit, control will be returned to the shell that you ran mkanalysis-sess from. If you type "ls", you will see a new folder called "sm-gamma-fwhm5". If you "ls sm-gamma-fwhm5", you will see analysis.info, analysis.cfg, odd-v-0.mat, even-v-0.mat, odd-v-even.mat, odd+even.mat. Your configuration is stored in these files. You can browse/edit your configuration by running:

mkanalysis-sess -gui -analysis sm-gamma-fwhm5

Configure Analysis and Contrasts II: FIR HRF Model

Now we are going to use a Finit Impulse Response (FIR) to model the hemodynamic response. The FIR does not make any assumptions about the shape of the HRF but is also less interpretable. Again, run

cd fb1-preproc-study
mkanalysis-sess -gui

Set the Func Stem, TR, NConditions, and Paradigm File as above, but now click on the "FIR" checkbox. This will enable the "Total Time Window", "PreStim", and "TER" entry boxes. The Time Window is the window within which we will estimate the HRF. Given that the task is 15 sec long and the rest is 15 sec, let's choose 27 sec. The PreStim is the amount of time before stimulus onset to start estimating the HRF. A non-zero PreStim gives us an idea of what the baseline is at stimulus onset. Set it to 6.

Setup the same contrasts as you did above, then name the analysis "sm-fir-fwhm5", hit Save, then Quit.

Analyze First Level (selxavg3-sess)

You are now ready to analyze some data! Note that the fully analyzed data (along with correctly configured analyses) can be found in fb1-analysis-study. To analyze the data for session mgh-101.1 with the sm-gamma-fwhm5 analysis, run:

cd fb1-preproc-study
selxavg3-sess -s mgh-101.1 -analysis sm-gamma-fwhm5

Note that if you want to analyze all the sessions, you can run "selxavg3-sess -sf sessid -analysis sm-gamma-fwhm5".

To analyze the data for session mgh-101.1 with the sm-fir-fwhm5 analysis, run:

cd fb1-preproc-study
selxavg3-sess -s mgh-101.1 -analysis sm-fir-fwhm5

Examine additions to the hierarchy

ls mgh-101.1/bold
ls mgh-101.1/bold/sm-gamma-fwhm5
ls mgh-101.1/bold/sm-gamma-fwhm5/odd-v-0

Visualize

Volume-based visualization (tkmedit-sess)

View the result of the Gamma HRF analysis on the FreeSurfer anatomical volume for mgh-101.1 with:

cd fb1-analysis-study
tkmedit-sess -s mgh-101.1 -aparc+aseg -analysis sm-gamma-fwhm5 \
  -c odd-v-0 -c even-v-0 -c odd+even -c odd-v-even 

When you configure the functional overlay with View->Configure->Functional Overlay, you will see that there are 4 "Time Points". Each point is different contrast (ie, 0 is odd-v-0, 1 is even-v-0, etc). Scroll through each one.

View the result of the HRF HRF analysis for mgh-101.1 with:

cd fb1-analysis-study
tkmedit-sess -s mgh-101.1 -aparc+aseg -analysis sm-fir-fwhm5 -c odd-v-0 

Here we view only one contrast at a time because each contrast has multiple time points for each point in the time window. Note that there is less activation than the Gamma HRF. When you click on a point, you will see the HRF for both Condition 1 (Odd) and Condition 2 (Even) blocks.

Finally, view the overlay maps from the Gamma with the HRF from the FIR:

cd fb1-analysis-study
tkmedit-sess -s mgh-101.1 -aparc+aseg -analysis sm-fir-fwhm5 \
  -mapanalysis sm-gamma-fwhm5 -c odd-v-0 -c even-v-0 -c odd+even -c odd-v-even 

When you configure the overlay, you will see that there are 4 "Time Points" -- these correspond to the 4 contrasts from the Gamma analysis.

Surface-based visualization (tksurfer-sess)

View the result of the Gamma HRF analysis on the FreeSurfer anatomical surface for mgh-101.1 with:

cd fb1-analysis-study
tksurfer-sess -hemi lh -aparc -s mgh-101.1 -analysis sm-gamma-fwhm5 \
  -c odd-v-0 -c even-v-0 -c odd+even -c odd-v-even

Note that the command-line is nearly identical to that of tkmedit above. The difference is that the hemisphere is specified ("-hemi lh"), and "-aparc+aseg" is replaced with "-aparc" to load the surface-based segmentation.



Higher-Level (Group) Analysis

Higher-Level is where you make inferences about the population that your subjects are drawn from. It is a bit confusing at times because both use GLMs, so at both levels you are constructing design matrices, contrasts, etc. Traditionally, fMRI group analysis has been done in a standard volume space (ie, Talairach/MNI152/MNI305). With FreeSurfer, we also have the option to analyze group data in the surface space. Volume-based analyses are done in MNI305 space (which is the same as the fsaverage subject).

Assemble the Data (isxconcat-sess)

The first step in the group analysis is to "assemble" the data. This means creating a single 4D file with where the 4th "time" dimension is actual all the subjects concatenated together in a common space. There is a different command, depending upon whether the common space is volume- or surface-based.

For the next exercises, we will work in the fb1-analysis-study directory

cd fb1-analysis-study

All the first level analyses have been done here. The group-level analyses have been done in the group-analysis-tut directory.

Volume-based (MNI305/fsaverage)

To run the volume-based concatenation, run the command below. Note that the data from this command already exist in the group-analysis-tut directory.

isxconcat-sess -sf sessid -analysis sm-gamma-fwhm5 -c odd-v-0 -o group-analysis

This command will go through each session in the sessid file, find the odd-v-0 contrast in the sm-gamma-fwhm5 analysis, use the register.dat for that session to resample to MNI305/fsaverage space. These are all concatenated together and saved in group-analysis/sm-gamma-fwhm5/odd-v-0/tal.ces.nii file. You can run other contrasts by adding -c arguments. In addition to this output, several other files are created. To see them,

ls group-analysis-tut/sm-gamma-fwhm5
cat group-analysis-tut/sm-gamma-fwhm5/sessid
cat group-analysis-tut/sm-gamma-fwhm5/ffxdof.dat

In the output directory, you will see a series of files that start with "tal". tal.meanfunc.nii is a stack where each "time point" is the mean functional image of each subject sampled in the MNI305 space. tal.masks.nii are the binary masks for all the subjects, and tal.fsnr.nii are the functional SNR maps from each subject. tal.mask.nii is a single binary mask made from the intersection of the individuals. ffxdof.dat is the fixed-effects DOF across all subjects. sessid.txt is the list of sessions, the corresponding freesurfer subject name, and the DOF contributed by each subject.

You will also see some files that being with "lh". These are the same thing in the surface-based space.

Now look in the directory for odd-v-0 the contrast

ls group-analysis/sm-gamma-fwhm5/odd-v-0

You will see tal.ces.nii. These are the contrast maps for eaah of the subjects, and tal.cesvar.nii are the variance of the contrast for each subject (ie, the square of the standard error). This variance is needed for fixed-effects and weighted random-effects analysis. You'll also see a bunch of directories with "osgm". Ignore those for a moment.

Quality Assurance

There are three important quality assurance steps that can be perfomed here. First, view the mean funcitonals to make sure that all are registered together properly. To do this run,

tkregister2 --s fsaverage --surf --regheader --check-reg \
  --mov group-analysis-tut/sm-gamma-fwhm5/tal.meanfunc.nii \

The image window will show the MNI305 brain. Hit the "Compare" button to show the average functional of the first session. Click in the image window, then hit the 'a' key. Each time you hit the 'a' key, it will advance to the next subject.

The next QA step is to check the individual masks. This can be done with:

tkmedit fsaverage orig.mgz \
  -overlay group-analysis-tut/sm-gamma-fwhm5/tal.masks.nii -fthresh 0.5

The threshold of 0.5 is appropriate because these masks are binary (ie 0-1). When you View->Configure->Functional Overlay, you will see that there are 5 "Time Points" (0-4) corresponding to the 5 subjects. Advance through each one to assure that the masks are in the proper place.

The final step is to look at the functional SNR maps with

tkmedit fsaverage orig.mgz \
  -overlay group-analysis-tut/sm-gamma-fwhm5/tal.fsnr.nii \
  -timecourse group-analysis-tut/sm-gamma-fwhm5/tal.fsnr.nii \
  -fthresh 50 -fmax 250

Again, when you View->Configure->Functional Overlay, you will see that there are 5 "Time Points" (0-4) corresponding to the 5 subjects. Advance through each one to assure that the SNR maps are "consistent". When you click on a voxel, you will see the SNR for each subject plotted in the "Time Course" window. The actual value of the FSNR will vary depending upon how much smoothing you've done and the details of the acquisition. You are looking for outliers here.

Group GLM Analysis

When you perform a group analysis, you are looking for effects of the task across the population. In this example, we only going to test whether the mean effect of Odd vs Fixation (odd-v-0) is different than 0. This is known as a one-sample-group-mean (OSGM) and corresponds to a group design matrix that is simply a column of 1s. One can perform considerably more elaborate tests (eg, differences in groups). Now, cd to where the data are:

cd group-analysis-tut/sm-gamma-fwhm5/odd-v-0

Random Effects (RFx, OLS)

Random effects is a test of whether the mean of the population that the subjects were drawn from is 0. It is done with mri_glmfit:

mri_glmfit --y tal.ces.nii --osgm --mask ../tal.mask.nii --glmdir tal.rfx.osgm --nii 

tal.ces.nii are the inputs for this contrast for all subjects. --osgm tells it to create the simple OSGM design matrix and to create a group contrast to test the group mean against 0. The mask is used to exclude extra-brain voxels. The results will be stored in tal.rfx.osgm:

ls tal.rfx.osgm
ls tal.rfx.osgm/osgm

You will see several files in the output. beta.nii is the map of regression coefficients. There is also an "osgm" folder with sig.nii. This is a map of the significances of the test. We will view it below.

Weighted Random Effects (WRFx, WLS)

In a real experiment, some subjects are noisier than others, and it is a good idea to take this into account since we have information about how noisy a subject is through the lower-level analysis. In weighted least squares (WLS), this is handled by weighting each subject by the inverse of their noise (ie, noiser subjects get lower weight). To do this with mri_glmfit, run:

mri_glmfit --y tal.ces.nii --osgm --glmdir tal.wrfx.osgm --nii --mask ../tal.mask.nii \
    --wls tal.cesvar.nii

The command-line is almost the same as the RFx except that the first-level noise variances (tal.cesvar.nii) are passed with the --wls option. The results are saved in tal.wrfx.osgm and have the same naming convension as the RFx.

Fixed Effects (FFx)

A fixed effects analysis tests whether an effect exists within the given subject pool (as opposed to the population that the subjects were pulled from). It is like doing one big fist-level analysis. The big difference with RFx or WRFx is that the variance is computed from the lower level analysis variance. This is done in mri_glmfit with:

mri_glmfit --y tal.ces.nii --osgm --glmdir tal.ffx.osgm --nii --mask ../tal.mask.nii \
   --yffxvar tal.cesvar.nii --ffxdofdat ../ffxdof.dat

Again, the command-line is similar to above, except that the lower level variances are passed with --yffxvar, and the total lower level DOFs are passed with --ffxdofdat.

Output and visualization

To visualize these three analyses, we will first concatenate them into one file to make it easier to view in tkmedit:

mri_concat tal.rfx.osgm/osgm/sig.nii \
           tal.wrfx.osgm/osgm/sig.nii \
           tal.ffx.osgm/osgm/sig.nii  \
        --o all.sig.nii)
tkmedit fsaverage orig.mgz -aux brain.mgz -bc-main-fsavg \
     -overlay all.sig.nii -fthresh 2 -fmax 4

Configure the overlay with View->Configure->Functional Overlay. Scroll through the "time" points to see the differences in the analyses.

Correction for Multiple Comparisons/Cluster Analysis

With so many voxels in fMRI maps, it is very likely that many voxels will appear to be active purely by random chance (ie, a false positive). The is known as the "Problem of Multiple Comparions". One way around this is to do a cluster analysis in which active voxels are eliminated unless they appear in a cluster, the idea being that false positives will not appear next to each other. To do this in FSFAST, run the following command on the RFx analysis:

mri_volcluster --in tal.rfx.osgm/osgm/sig.nii --thmin 2 \
   --fwhmdat tal.rfx.osgm/fwhm.dat --cwpvalthresh 0.1 \
   --mask tal.rfx.osgm/mask.nii --fsaverage \
   --sum tal.rfx.osgm/osgm/cluster.sum \
   --cwsig tal.rfx.osgm/osgm/cwsig.cluster.nii \
   --out tal.rfx.osgm/osgm/sig.cluster.nii \
   --ocn tal.rfx.osgm/osgm/ocn.cluster.nii 

In this command we use the signifiance map as input thresholded at 2, where 2 is -log10(p), so p < .01. The --fwhmdat option tells mri_volcluster to use the spatial smoothness estimate from GLM analysis (saved in tal.rfx.osgm/fwhm.dat). The "--cwpvalthresh 0.1" tells it to ignore clusters unless their p-value is less than 0.1 (you can threshold more stringently later on).

One of the outputs is a cluster table (cluster.sum). This is a text file with the list of clusters. View it with:

 more tal.rfx.osgm/osgm/cluster.sum  You can also see it here: FsFastTutorial/ClusterSummary. The table shows the size of each cluster in voxels and mm^3, the Talairach coordinate, the maximum significance in the cluster, and the clusterwise p-value (CWP). Some of them are 0, meaning that the p-value was so low that it could not be computed (remember, this is a good thing!).

The other outputs are volumes. cwsig.cluster.nii is a map of the clusters with the voxel value equal to the -log10(pvalue) of the cluster that the voxel is associated with. sig.cluster.nii is the original sig map with non-cluster voxels removed. ocn.cluster.nii is a map where the value at each voxel is replaced by the number of the cluster that the voxel is associated with. View the clusterwise significance:

}}} tkmedit fsaverage orig.mgz -aux brain.mgz -bc-main-fsavg \

  • -overlay tal.rfx.osgm/osgm/cwsig.cluster.nii -fthresh 2 -fmax 4

}}}

Surface-based

TBD

FsFast Tutorial SlideShow

Navigation(slideshow)

  • ["/000 Frontmatter"]
  • ["/300 Download data"]
  • ["/400 Get familiar with sessions format"]
  • ["/500 Make a directory for your study"]
  • ["/600 Make paradigm files for your experiment"]
  • ["/700 Motion correct the data"]
  • ["/800 Normalize signal intensity"]
  • ["/900 Set up session-level analysis"]
  • ["/905 Average session-level data by condition"]
  • ["/910 Define an omnibus contrast"]
  • ["/920 Compute statistical maps of the omnibus contrast"]
  • ["/930 Run functional and structural registration"]
  • ["/940 Visualization"]

FsFastTutorialV4.5 (last edited 2011-05-19 15:29:07 by NickSchmansky)