.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_hbn_site_profiles.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_plot_hbn_site_profiles.py: =============================== Harmonize HBN data using ComBat =============================== This example loads AFQ data from the Healthy Brain Network (HBN) preprocessed diffusion derivatives [1]_. The HBN is a landmark pediatric mental health study. Over the course of the study, it will collect diffusion MRI data from approximately 5,000 children and adolescents. We recently processed the available data from over 2,000 of these subjects, and provide the tract profiles from this dataset, which can be downloaded from AWS thanks to [INDI](http://fcon_1000.projects.nitrc.org/). We first load the data by using the :func:`AFQDataset.from_files` static method and supplying AWS S3 URIs instead of local file names. We then impute missing values and plot the mean bundle profiles by scanning site, noting that there are substantial site differences. Lastly, we harmonize the site differences using NeuroComBat [2]_ and plot the harmonized bundle profiles to verify that the site differences have been removed. .. [1] Adam Richie-Halford, Matthew Cieslak, Lei Ai, Sendy Caffarra, Sydney Covitz, Alexandre R. Franco, Iliana I. Karipidis, John Kruper, Michael Milham, Bárbara Avelar-Pereira, Ethan Roy, Valerie J. Sydnor, Jason Yeatman, The Fibr Community Science Consortium, Theodore D. Satterthwaite, and Ariel Rokem, "An open, analysis-ready, and quality controlled resource for pediatric brain white-matter research" bioRxiv 2022.02.24.481303; doi: https://doi.org/10.1101/2022.02.24.481303 .. [2] Jean-Philippe Fortin, Drew Parker, Birkan Tunc, Takanori Watanabe, Mark A Elliott, Kosha Ruparel, David R Roalf, Theodore D Satterthwaite, Ruben C Gur, Raquel E Gur, Robert T Schultz, Ragini Verma, Russell T Shinohara. "Harmonization Of Multi-Site Diffusion Tensor Imaging Data" NeuroImage, 161, 149-170, 2017; doi: https://doi.org/10.1016/j.neuroimage.2017.08.047 .. GENERATED FROM PYTHON SOURCE LINES 39-48 .. code-block:: Python import numpy as np from neurocombat_sklearn import CombatModel from sklearn.impute import SimpleImputer from sklearn.model_selection import train_test_split from afqinsight import AFQDataset from afqinsight.plot import plot_tract_profiles .. GENERATED FROM PYTHON SOURCE LINES 49-60 Fetch the HBN data ------------------ As a shortcut, we have incorporated a few studies into the software. In these cases, a :class:`AFQDataset` class instance can be initialized using the :func:`AFQDataset.from_study` static method. This expects the name of one of the studies that are supported (see the method documentation for the list of these studies). By passing `"hbn"`, we request that the object download the HBN dataset from the AWS Open Data program where it has been stored and initialize the objects with the subjects and nodes information. Subjects' age is set as the target variable. After dropping subjects that don't have their age recorded, there are 1867 subjects in the dataset. .. GENERATED FROM PYTHON SOURCE LINES 60-66 .. code-block:: Python dataset = AFQDataset.from_study("hbn") dataset.drop_target_na() print(dataset) .. rst-class:: sphx-glr-script-out .. code-block:: none subjects.tsv: 0%| | 0.00/211k [00:00`_ package to apply ComBat to our data. We love this library, however, it is not fully compliant with the scikit-learn transformer API, so we cannot use the :func:`AFQDataset.model_fit_transform` method to apply this transformer to our dataset. No problem! We can simply copy the unharmonized dataset into a new variable and then overwrite the features of the new dataset with the ComBat output. Lastly, we replot the mean bundle profiles and confirm that ComBat did its job. .. GENERATED FROM PYTHON SOURCE LINES 122-149 .. code-block:: Python # Fit the ComBat transformer to the training set combat = CombatModel() combat.fit( dataset_train.X, dataset_train.y[:, 2][:, np.newaxis], dataset_train.y[:, 1][:, np.newaxis], dataset_train.y[:, 0][:, np.newaxis], ) # And then transform a copy of the test set harmonized_test = dataset_test.copy() harmonized_test.X = combat.transform( dataset_test.X, dataset_test.y[:, 2][:, np.newaxis], dataset_test.y[:, 1][:, np.newaxis], dataset_test.y[:, 0][:, np.newaxis], ) site_figs = plot_tract_profiles( X=harmonized_test, group_by=harmonized_test.classes["scan_site_id"][ harmonized_test.y[:, 2].astype(int) ], group_by_name="Site", figsize=(14, 14), ) .. rst-class:: sphx-glr-horizontal * .. image-sg:: /auto_examples/images/sphx_glr_plot_hbn_site_profiles_003.png :alt: IFOL, UNCL, UNCR, IFOR, ATRL, CSTL, CSTR, ATRR, ARCL, SLFL, SLFR, ARCR, ILFL, CGCL, CGCR, ILFR, Orbital, AntFrontal, SupFrontal, Motor, SupParietal, Temporal, PostParietal, Occipital :srcset: /auto_examples/images/sphx_glr_plot_hbn_site_profiles_003.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/images/sphx_glr_plot_hbn_site_profiles_004.png :alt: IFOL, UNCL, UNCR, IFOR, ATRL, CSTL, CSTR, ATRR, ARCL, SLFL, SLFR, ARCR, ILFL, CGCL, CGCR, ILFR, Orbital, AntFrontal, SupFrontal, Motor, SupParietal, Temporal, PostParietal, Occipital :srcset: /auto_examples/images/sphx_glr_plot_hbn_site_profiles_004.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out .. code-block:: none /opt/hostedtoolcache/Python/3.10.15/x64/lib/python3.10/site-packages/sklearn/preprocessing/_encoders.py:828: FutureWarning: `sparse` was renamed to `sparse_output` in version 1.2 and will be removed in 1.4. `sparse_output` is ignored unless you leave `sparse` to its default value. warnings.warn( /opt/hostedtoolcache/Python/3.10.15/x64/lib/python3.10/site-packages/sklearn/preprocessing/_encoders.py:828: FutureWarning: `sparse` was renamed to `sparse_output` in version 1.2 and will be removed in 1.4. `sparse_output` is ignored unless you leave `sparse` to its default value. warnings.warn( 0%| | 0/2 [00:00` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_hbn_site_profiles.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_hbn_site_profiles.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_