fMRI Short Course Activity

First-Level Modeling in FSL FEAT

A publishable tutorial and answer key for completing a first-level fMRI GLM analysis using timing files, FEAT, and Andy's Brain Book.

Overview

A first-level fMRI model estimates task-related BOLD responses within a single subject and usually within a single run. In this activity, the task is modeled with two conditions: incongruent trials and congruent trials.

FSL FEAT estimates how much each voxel's time series matches the predicted BOLD response for each condition. The predicted responses are created from timing files, convolved with the hemodynamic response function, and entered into the general linear model.

Central idea: the timing files define when each task condition happened. FEAT turns those timing files into regressors, fits those regressors to each voxel's BOLD signal, and produces beta maps, contrast maps, and statistical maps.

1. Start Open OnDemand and set up the HPC environment

  1. Open CU Boulder Open OnDemand

    Go to https://ondemand.rc.colorado.edu/ and launch a Core Desktop session. FSL's graphical interface requires an interactive desktop display.

  2. Open a terminal inside the desktop session

    Run the following commands:

    module load slurm/alpine
    start_session

    The first command loads the Alpine Slurm environment. The second command starts an interactive compute session, which prevents you from running the analysis directly on a login node.

  3. Load the course software environment

    setup_env

    Run this each time you open a new terminal for the activity.

  4. Confirm FSL is available

    which fsl

    A valid output should return a path to the FSL executable. If it says fsl: command not found, the environment has not been loaded correctly.

2. Move to your scratch directory

The activity uses scratch space for analysis outputs. Move into the scratch directory:

cd /scratch/alpine/amhe4269
pwd

The pwd command confirms your current location. FEAT writes many output files, including design files, statistical images, logs, and HTML reports, so scratch is the correct place to work.

3. Launch FSL

Launch the FSL GUI:

fsl &

The ampersand runs FSL in the background, which keeps the terminal usable. Once the FSL window opens, choose FEAT FMRI analysis.

4. Understand the first-level GLM

The general linear model expresses the observed BOLD signal as a weighted combination of predictors plus unexplained error:

Y = Xβ + ε
Term Meaning in fMRI
Y The measured BOLD time series for one voxel.
X The design matrix, made from task regressors and other modeled effects.
β Beta weights, one for each regressor.
ε Residual error, the part of the signal not explained by the model.

For this activity, the conceptual model is:

BOLD signal = β1(Incongruent) + β2(Congruent) + residual error

This model is fit separately at each voxel. That is why first-level fMRI modeling is often described as a mass univariate analysis.

5. Check the timing files

FSL timing files use a three-column format:

onset duration value
Column Meaning
Column 1 Trial onset in seconds from the start of the scan.
Column 2 Trial duration in seconds.
Column 3 Amplitude or modulation value. For this activity, this is usually 1.

Example:

12.5  1.0  1
30.0  1.0  1
47.5  1.0  1

For the Flanker task, the relevant files are:

incongruent_run1.txt
incongruent_run2.txt
congruent_run1.txt
congruent_run2.txt

Inspect the run 1 files before entering them into FEAT:

cat sub-08/func/incongruent_run1.txt
cat sub-08/func/congruent_run1.txt

6. Set up FEAT for first-level statistics

  1. Choose the correct analysis mode

    In FEAT, change the analysis type from Full Analysis to Statistics. This tells FEAT that preprocessing has already been done and that you only want to run the statistical model.

  2. Use an existing FEAT directory as input

    Select Input is a FEAT directory, then choose the preprocessed run 1 FEAT directory.

    run1.feat
  3. Open the full model setup

    Go to Stats, then click Full model setup.

  4. Set the number of original EVs

    Number of original EVs = 2

    EV means explanatory variable. Here, the two EVs are incongruent and congruent trials.

7. Enter the explanatory variables

EV1: Incongruent

EV name incongruent
Basic shape Custom (3 column format)
Filename incongruent_run1.txt
Convolution Double-Gamma HRF
Temporal derivative Unchecked for this activity.

EV2: Congruent

EV name congruent
Basic shape Custom (3 column format)
Filename congruent_run1.txt
Convolution Double-Gamma HRF
Temporal derivative Unchecked for this activity.

FEAT will take the event onsets and durations, create an event time series, and convolve it with the double-gamma HRF. The resulting regressors are the predicted BOLD responses for each condition.

8. Set up contrasts

In Contrasts & F-tests, set:

Number of contrasts = 3
Contrast name EV1 incongruent EV2 congruent Question being tested
incongruent 1 0 Where is activity associated with incongruent trials greater than implicit baseline?
congruent 0 1 Where is activity associated with congruent trials greater than implicit baseline?
incongruent-congruent 1 -1 Where is activity stronger for incongruent than congruent trials?

9. Inspect the design matrix

After clicking Done, FEAT will show the design matrix. You should see a high-pass filtering component and two condition regressors, one for incongruent trials and one for congruent trials.

Quality check: make sure the two task regressors are not identical. A common mistake is accidentally loading the same timing file for both EVs.

Before running the model, check:

  • The model has two task EVs.
  • The EVs are in the correct order: incongruent first, congruent second.
  • The correct run 1 timing files are loaded.
  • The contrasts match the EV order.
  • The design matrix does not show obvious errors.

10. Run the model and understand the outputs

Click Go in FEAT. After the model finishes, open the FEAT report:

firefox run1.feat/report.html &

Important output files include:

File Meaning
stats/pe1.nii.gz Beta map for the incongruent EV.
stats/pe2.nii.gz Beta map for the congruent EV.
stats/cope1.nii.gz Contrast estimate for incongruent greater than baseline.
stats/cope2.nii.gz Contrast estimate for congruent greater than baseline.
stats/cope3.nii.gz Contrast estimate for incongruent greater than congruent.
stats/zstat3.nii.gz Z-statistical map for the incongruent greater than congruent contrast.

11. Command-line checks

Use these commands to confirm that FEAT produced the expected files:

ls run1.feat
ls run1.feat/stats

ls run1.feat/stats/pe*.nii.gz
ls run1.feat/stats/cope*.nii.gz
ls run1.feat/stats/zstat*.nii.gz

Check the model files:

cat run1.feat/design.con
cat run1.feat/design.mat

Open the main contrast in FSLeyes:

fsleyes run1.feat/filtered_func_data.nii.gz run1.feat/stats/zstat3.nii.gz &

Code and workflow check

Terminal workflow

module load slurm/alpine
start_session
setup_env
which fsl
cd /scratch/alpine/amhe4269
fsl &

FEAT workflow

FEAT → Statistics
Input is a FEAT directory → select run1.feat
Stats → Full model setup
Number of original EVs = 2

EV1:
Name = incongruent
Shape = Custom (3 column format)
File = incongruent_run1.txt
Convolution = Double-Gamma HRF
Temporal derivative = off

EV2:
Name = congruent
Shape = Custom (3 column format)
File = congruent_run1.txt
Convolution = Double-Gamma HRF
Temporal derivative = off

Contrasts:
1. incongruent: [1 0]
2. congruent: [0 1]
3. incongruent-congruent: [1 -1]

Click Done.
Inspect the design matrix.
Click Go.
Open report.html.
Inspect Stats and Post-stats.

Conceptual summary

The first-level GLM estimates condition-specific BOLD responses within one subject and one run. The timing files define when each condition occurred. FSL convolves those timings with the HRF to create predicted BOLD regressors. FEAT fits those regressors to every voxel, estimates beta maps for each condition, and produces contrast maps for the requested comparisons.