Here we provide a set of MATLAB based scripts to perform direct linear discriminant analysis on fMRI data.
Please use the following paper to cite the toolbox:
Kakaei,E. & Braun, J. (2023) - Gradual change of cortical representations with growing visual expertise for synthetic shapes.
If you are using MD758 parcellation please refer to MD758 parcellation and cite accordingly.
You need following requirements to run DLDA:
- MATLAB (tested on version 9.3 and 9.12)
- Statistics and Machine Learning Toolbox
- NIFTI toolbox (niftimatlib; download here)
- MD758 parcellation (already included)
First, download or clone the repository. NIFTI toolbox should be installed and included in the MATLAB path. Before following the pipeline, you can go over the demo file as an example of how to use this toolbox.
WARNING: Due to large amount of data that fMRI images contain, this process can be memory consuming. Make sure to save any unsaved processes before running this program.
After having your fMRI images preprocessed, first you need to create a setting and a profile structure array which contain the necessary information for the DLDA pipeline. The setting and profile structures should include the following information:
%% stg (settings)
stg.atlasnii % 'path_to_atlas_nifti_file.nii' (.nii only)
stg.atlaslist % 'path_to_atlas_list.mat' atlas region information
stg.ROI_ID % array of ROIs
stg.window % [TR1 TR2] (event centered windows from TR1 to TR2)
stg.TR % fMRI TR in seconds
stg.classificationID % ID of the classes for classification
stg.Nrepetition % number of train-test repetition
stg.TestFraction % fraction of data used for cross-validation
stg.StatsPermutations % number of first-level permutation test
stg.PrevalencePermutations % number of second-level permutation test (prevalence analysis)
stg.alpha % level of significance
stg.SaveDirectory % directory in which toolbox will save the output files
%% prf (profile) is a structure of 1-by-N (N: number of images)
prf(i).subject % name or ID of the subject
prf(i).images % path to the pre-processed .nii image file
prf(i).ID % ID of the events (trigger:-3, ID of the class presented)
prf(i).time % time of the events (MR trigger and class presentation)
Once these information is provided you can take follow the DLDA pipeline which takes the setting and profile variables and performs the following steps:
- Checking settings and profile:
check_inputs(stg,prf)
controls for missing fields of the assigned variables. - Preparing saving directory:
prepare_savedir(stg,prf)
creates all the required folders under thestg.SaveDirectory
directory. - Splitting original image:
split_images(stg,prf)
divides the original preprocessed images into smaller files for each given ROI, for each subject. - Sequencing events:
get_sequences(stg,prf)
recognizes TR indices for all events. - Cleaning ROI data:
get_clean_data(stg,prf,ROI)
whitens and detrends data for a given ROI. - Combine class data over sessions:
get_class_data(stg,prf,clean_data)
combines the cleaned data over sessions and divides them by classes. - Dividing train/test sets:
train_test_division(stg,class_data)
divides the combined class data into train and test sets. - Training classifier:
training_optimal_space(TrainBatch)
finds the optimal subspace and the centroids of each class in that subspace. - Crossvalidation of classifier:
test_classification(TestBatch,G)
projects the test-set into the optimal subspace G. Then,test_stats(stg,projected_test_data,M)
provides multiple cross-validation measures and performs the first-level permutation.
Additionally, we have included get_prevalence
which performs a population prevalence inference using a 2-level permutation test Allefeld et al. 2016.