Default Mode Network extraction of ADHD dataset

This example shows a full step-by-step workflow of fitting a GLM to signal extracted from a seed on the Posterior Cingulate Cortex and saving the results. More precisely, this example shows how to use a signal extracted from a seed region as the regressor in a GLM to determine the correlation of each region in the dataset with the seed region.

More specifically:

  1. A sequence of fMRI volumes are loaded.

  2. A design matrix with the Posterior Cingulate Cortex seed is defined.

  3. A GLM is applied to the dataset (effect/covariance, then contrast estimation).

  4. The Default Mode Network is displayed.

Note

If you are using Nilearn with a version older than 0.9.0, then you should either upgrade your version or import maskers from the input_data module instead of the maskers module.

That is, you should manually replace in the following example all occurrences of:

from nilearn.maskers import NiftiMasker

with:

from nilearn.input_data import NiftiMasker
import numpy as np

from nilearn import plotting
from nilearn.datasets import fetch_adhd
from nilearn.glm.first_level import (
    FirstLevelModel,
    make_first_level_design_matrix,
)
from nilearn.maskers import NiftiSpheresMasker

Prepare data and analysis parameters

Prepare the data.

adhd_dataset = fetch_adhd(n_subjects=1)

# Prepare timing
t_r = 2.0
slice_time_ref = 0.0
n_scans = 176

# Prepare seed
pcc_coords = (0, -53, 26)
[get_dataset_dir] Dataset found in /home/runner/nilearn_data/adhd

Extract the seed region’s time course

Extract the time course of the seed region.

seed_masker = NiftiSpheresMasker(
    [pcc_coords],
    radius=10,
    detrend=True,
    standardize="zscore_sample",
    low_pass=0.1,
    high_pass=0.01,
    t_r=2.0,
    memory="nilearn_cache",
    memory_level=1,
    verbose=0,
)
seed_time_series = seed_masker.fit_transform(adhd_dataset.func[0])
frametimes = np.linspace(0, (n_scans - 1) * t_r, n_scans)

Plot the time course of the seed region.

import matplotlib.pyplot as plt

fig = plt.figure(figsize=(9, 3))
ax = fig.add_subplot(111)
ax.plot(frametimes, seed_time_series, linewidth=2, label="seed region")
ax.legend(loc=2)
ax.set_title("Time course of the seed region")
plt.show()
Time course of the seed region

Estimate contrasts

Specify the contrasts.

design_matrix = make_first_level_design_matrix(
    frametimes,
    hrf_model="spm",
    add_regs=seed_time_series,
    add_reg_names=["pcc_seed"],
)
dmn_contrast = np.array([1] + [0] * (design_matrix.shape[1] - 1))
contrasts = {"seed_based_glm": dmn_contrast}

Perform first level analysis

Setup and fit GLM.

/home/runner/work/nilearn/nilearn/examples/04_glm_first_level/plot_adhd_dmn.py:97: UserWarning: Mean values of 0 observed. The data have probably been centered.Scaling might not work as expected
  first_level_model = first_level_model.fit(

Estimate the contrast.

print("Contrast seed_based_glm computed.")
z_map = first_level_model.compute_contrast(
    contrasts["seed_based_glm"], output_type="z_score"
)
Contrast seed_based_glm computed.

Saving snapshots of the contrasts

from pathlib import Path

display = plotting.plot_stat_map(
    z_map, threshold=3.0, title="Seed based GLM", cut_coords=pcc_coords
)
display.add_markers(
    marker_coords=[pcc_coords], marker_color="g", marker_size=300
)

output_dir = Path.cwd() / "results" / "plot_adhd_dmn"
output_dir.mkdir(exist_ok=True, parents=True)
filename = "dmn_z_map.png"
display.savefig(output_dir / filename)
print(f"Save z-map in '{filename}'.")
plot adhd dmn
Save z-map in 'dmn_z_map.png'.

Generating a report

It can be useful to quickly generate a portable, ready-to-view report with most of the pertinent information. This is easy to do if you have a fitted model and the list of contrasts, which we do here.

report = first_level_model.generate_report(
    contrasts=contrasts,
    title="ADHD DMN Report",
    cluster_threshold=15,
    min_distance=8.0,
    plot_type="glass",
)

We have several ways to access the report:

It can be viewed in a notebook

Statistical Report - First Level Model
ADHD DMN Report Implement the General Linear Model for single run :term:`fMRI` data.

Description

Data were analyzed using Nilearn (version= 0.11.2.dev243+gf74c4c5c0; RRID:SCR_001362).

At the subject level, a mass univariate analysis was performed with a linear regression at each voxel of the brain, using generalized least squares with a global ar1 noise model to account for temporal auto-correlation and a cosine drift model (high pass filter=0.01 Hz).

Model details

Value
Parameter
drift_model cosine
high_pass (Hertz) 0.01
hrf_model glover
noise_model ar1
signal_scaling 0
slice_time_ref 0.0
standardize False
t_r (seconds) 2.0

Design Matrix

run 0

Plot of design matrix for 0.

correlation matrix

Plot of correlation of design matrix for run 0.

Contrasts

Plot of the contrast seed_based_glm (run 0).

Mask

Mask image

Statistical Maps

seed_based_glm

Stat map plot for the contrast: seed_based_glm
Cluster Table
Height control fpr
α 0.001
Threshold (computed) 3.291
Cluster size threshold (voxels) 15
Minimum distance (mm) 8.0
Cluster ID X Y Z Peak Stat Cluster Size (mm3)
1 3.0 -54.0 18.0 13.01 83781
1a 0.0 -57.0 30.0 12.68
1b 0.0 -48.0 30.0 11.96
1c -3.0 -51.0 18.0 11.91
2 0.0 51.0 -6.0 11.08 27027
2a 3.0 69.0 3.0 10.62
2b 0.0 57.0 3.0 10.31
2c 0.0 63.0 15.0 10.12
3 57.0 -66.0 27.0 10.91 6507
3a 48.0 -57.0 30.0 8.99
3b 51.0 -69.0 27.0 8.51
3c 45.0 -69.0 39.0 6.39
4 -42.0 24.0 -24.0 10.71 1296
4a -42.0 9.0 -30.0 5.87
4b -39.0 24.0 -18.0 4.97
4c -42.0 15.0 -39.0 4.63
5 48.0 -66.0 -21.0 10.71 2943
5a 42.0 -54.0 -24.0 7.29
5b 33.0 -78.0 -36.0 5.37
5c 39.0 -72.0 -27.0 4.82
6 42.0 27.0 -24.0 10.71 891
6a 39.0 36.0 -15.0 7.45
6b 39.0 21.0 -18.0 4.72
7 -63.0 -12.0 -9.0 9.20 2916
7a -63.0 -18.0 -15.0 9.05
7b -48.0 -24.0 -6.0 6.86
7c -57.0 -12.0 -9.0 6.59
8 -48.0 -69.0 42.0 8.93 8478
8a -42.0 -72.0 33.0 8.72
8b -54.0 -66.0 36.0 8.71
8c -48.0 -75.0 30.0 7.57
9 -12.0 39.0 54.0 8.52 4023
9a -24.0 30.0 48.0 8.51
9b -18.0 30.0 42.0 8.39
9c -15.0 30.0 51.0 7.87
10 60.0 -3.0 -12.0 7.94 2889
10a 66.0 -18.0 -6.0 6.62
10b 66.0 -27.0 -3.0 6.35
10c 57.0 -12.0 -9.0 6.15
11 -57.0 3.0 -15.0 7.02 1242
11a -51.0 3.0 -21.0 5.60
11b -51.0 9.0 -27.0 5.21
12 51.0 9.0 -39.0 6.73 729
13 -24.0 -75.0 51.0 6.65 567
13a -15.0 -75.0 57.0 4.84
13b -36.0 -72.0 51.0 4.52
14 21.0 -33.0 0.0 6.54 2079
14a 21.0 -21.0 -12.0 5.72
14b 30.0 -27.0 -9.0 5.15
14c 9.0 -30.0 -6.0 4.64
15 3.0 42.0 54.0 6.42 540
15a 0.0 27.0 60.0 6.40
16 51.0 -60.0 -21.0 6.42 486
16a 57.0 -54.0 -24.0 4.85
17 24.0 57.0 0.0 6.38 1593
17a 24.0 63.0 -12.0 4.95
17b 33.0 63.0 -3.0 4.61
17c 24.0 66.0 6.0 3.98
18 -39.0 9.0 39.0 6.36 1323
18a -48.0 9.0 42.0 5.19
19 -39.0 -36.0 -21.0 6.27 1026
19a -42.0 -24.0 -21.0 5.48
19b -39.0 -12.0 -36.0 4.78
20 36.0 9.0 36.0 6.25 999
20a 36.0 18.0 36.0 5.15
20b 39.0 9.0 42.0 5.04
20c 48.0 12.0 45.0 4.66
21 6.0 -6.0 -12.0 6.13 1188
21a 12.0 6.0 -12.0 4.52
21b 18.0 -3.0 -12.0 4.42
22 -9.0 -51.0 -39.0 6.10 1134
22a 3.0 -60.0 -51.0 4.72
23 0.0 -33.0 75.0 6.08 1647
23a -9.0 -24.0 78.0 5.86
23b 0.0 -27.0 75.0 5.55
23c 0.0 -21.0 66.0 4.06
24 51.0 -45.0 36.0 5.98 594
24a 57.0 -45.0 27.0 4.64
25 -15.0 57.0 30.0 5.94 1161
25a -21.0 54.0 36.0 5.72
25b -9.0 51.0 33.0 4.79
25c -18.0 42.0 30.0 4.29
26 -12.0 21.0 -9.0 5.62 675
26a -12.0 24.0 3.0 5.24
27 -27.0 54.0 0.0 5.36 621
27a -24.0 54.0 9.0 3.98
28 27.0 -69.0 -6.0 5.32 1971
28a 21.0 -75.0 -9.0 5.22
28b 27.0 -57.0 -12.0 4.83
28c 33.0 -51.0 -9.0 4.52
29 -48.0 0.0 -33.0 5.25 459
30 -51.0 -63.0 -36.0 5.20 810
30a -45.0 -69.0 -45.0 4.81
30b -48.0 -69.0 -36.0 4.80
31 -9.0 -78.0 9.0 5.15 648
32 -3.0 -9.0 72.0 4.76 621
32a 0.0 3.0 69.0 3.87
32b -3.0 -9.0 63.0 3.59
33 -42.0 -60.0 -6.0 4.76 405
34 9.0 21.0 -3.0 4.66 405

About

  • Date preprocessed:


Or in a separate browser window report.open_in_browser()

Or we can save as an html file.

Total running time of the script: (0 minutes 19.688 seconds)

Estimated memory usage: 882 MB

Gallery generated by Sphinx-Gallery