4. 🧠 Source‐Based Analysis Reference - jasonnan2/Automated-Analysis-of-EEG GitHub Wiki

This section outlines the standard analysis workflow using the SourceObject class to process, analyze, and visualize source localized EEG data. Reference script is runSource.m

Example


# load in required variables
% Initialize SourceObject
sourceObject = SourceObject(project.sourceData, project.info, baselineTime, timeRange, cfg);

% Clean missing subject data
sourceObject = sourceObject.cleanDatasets();

% Preprocess: outlier removal, baseline correction
sourceObject = sourceObject.standardProcessing();

% Calculate average source activity across ROIs/freqs/time
sourceObject = sourceObject.calRoiData();

% Compile all significant ROIs into a summary table
sourceObject = sourceObject.calSigTbl();

% Compute average signal per network using predefined netwrk struct
sourceObject = sourceObject.calNetData(netwrk);

% Compute ROI-to-ROI and network-to-network connectivity
sourceObject = sourceObject.calConnectivity(netwrk);
% Run group comparisons with default cfg
sourceObject = sourceObject.analyzeRoi();
% Plot average network-level activity
sourceObject.plotNetwork();
% Plot network connectivity matrices overriding default cfg and set to 0. 
sourceObject.plotNetConnectivity('FDRflag', 0);

📚 Initial Set Up and Processing

obj = SourceObject(project.sourceData, project.info, baselineTime, timeRange,cfg)

Initializes a new source analysis object

Parameter Description
sourceData Struct with source-level data for each group
info Metadata from project.info
baselineTime 1×2 vector (in ms) of baseline correction
timeRange Struct defining labeled time windows
cfg (optional) Configuration struct for analysis/plotting

obj.cleanDatasets()

Removes subjects missing across any group or variable.


obj.standardProcessing(...)

Performs outlier removal and optional baseline correction.

Parameter Description Default
'outlier' '5SD' or '3MAD' method for subject-level outlier removal '5SD'
'calBaseline' Whether to apply baseline correction 1

obj.calRoiData()

Computes average roi-level activity across frequencies, time windows, and groups and stores in obj.sourceResults.roiData

Parameter Description
None No Parameters

Defining netwrk for network based analysis

Each network should be defined as a struct with the following fields:

Field Description
name String label of the network (e.g., 'FPN', 'DMN')
roi Vector of integers representing ROI indices assigned to that network

fpn    = [5 6 55 66 59 60];
netwrk(1).name = 'FPN';
netwrk(1).roi  = fpn;

con    = [3 4 19 20 37 38 39 40 41 42 57 58 67 68];
netwrk(2).name = 'CON';
netwrk(2).roi  = con;

obj.calNetData(netwrk)

Computes network-level averages and stores in sourceResults.netData.

Parameter Description
netwrk Struct array defining brain networks

obj.calConnectivity(netwrk, ...)

Computes ROI-to-ROI and network-to-network connectivity matrices.

  • 'roi' (default):
    Computes ROI-to-ROI connectivity, applies Fisher Z-transform, averages within each network, then converts back to connectivity.

  • 'network':
    Averages ROI time series within each network first, then computes network-to-network connectivity directly.
    Intra-network connectivity is always computed using the ROI-level method.

Parameter Description
netwrk Struct of networks as above
method (Optional) 'net' or 'roi'. 'net' is default.

Main Analysis Section

⚠️ If no name-value pairs are specified, values in cfg are used by default. Name-value pairs override cfg.

💻 obj.analyzeRoi(...)

Performs group comparisons and identifies significant ROIs.

Parameter Description
'hmFile' Path to head model file (default used if empty)
'rois2plot' Numeric array of ROI indices to include
'vars2plot' Cell array of variable names to include
'freq2plot' Frequencies to analyze
'times2plot' Time windows to compare (e.g., 'time1')
'combinations' Nx2 array of group indices to compare (e.g., [1 2])
'FDRflag' 1 = apply FDR correction; 0 = uncorrected
'toPlot' 1 = generate brain Maps
'isnormal' 'auto', 1 (normal), or 0 (non-parametric)

Populates sourceResults.sigROIs and sigROIsP.


obj.calSigTbl(...)

Extracts significantly different neural measures and saves them into a table for each variable and time window. Must be run after obj.analyzeRoi().

Parameter Description
chanTypes (optional) A string specifying which ROIs to include in the table: 'sig' (default) extracts only significant ROIs'all' includes all ROIs

Output: Populates obj.results.sigValues.(variable).(time) with the resulting tables.


📊 obj.plotNetwork(...)

Plots network based grouped bar charts for selected variables, frequencies, and time ranges.

Parameter Description
'vars2plot' Cell array of variable names to include
'freq2plot' Frequencies to analyze
'times2plot' Time windows to compare (e.g., 'time1')
'groups2plot ' 1xN array of group indices to compare (e.g., [1 2])
'FDRflag' 1 = apply FDR correction; 0 = uncorrected
'isnormal' 'auto', 1 (normal), or 0 (non-parametric)
'color_list' Cell array indicating custom colors for each group

obj.plotNetConnectivity(...)

Plots connectivity heatmaps marked with significance. Plots include individual groups and group difference comparisons.

Parameter Description
'vars2plot' Cell array of variable names to include
'freq2plot' Frequencies to analyze
'times2plot' Time windows to compare (e.g., 'time1')
'combinations' Nx2 array of group indices to compare (e.g., [1 2])
'FDRflag' 1 = apply FDR correction; 0 = uncorrected
'isnormal' 'auto', 1 (normal), or 0 (non-parametric)

Must run calConnectivity() first.