# The NIRS Brain AnalyzIR Toolbox
## 2 Architecture of Toolbox
### Processing Modules Classes
#### 2.2.2.1 Baseline Correction  
The baseline correction algorithm is designed to remove statistical outliers in the innovations of the data following an autoregressive integrative (ARI) model fit of the data. In this code, a _p_th-order ARI (_p_,1) model is first fit to each channel of fNIRS data,  
\[(Y(k)-Y(k-1))=\sum_{i=1}^{p}a_{i}\cdot(Y(k-i)-Y(k-1-i))+innov(k) \tag{4}\] \begin{table}
\begin{tabular}{c c c} \hline \hline
**Modules** & **Description** & **Citation** \\ \hline \multicolumn{3}{c}{**Pre-processing**} \\ \hline BeerLambertLaw & Converts optical density to hemoglobin & [34] \\ \hline Resample & [PERSON] filter and resample the data & Matlab: _resample.m_ function \\ \hline OpticaIDensity & Conversion of raw data to optical density & \\ \hline \multicolumn{3}{c}{**Data management**} \\ \hline AddDemographics & Add subject information from the table & \\ \hline Change5 timulusInfo & Change stimulus info to data given a table & \\ \hline Discard5 tims & Removes specified stimulus conditions from design & \\ \hline Fix5 tims & Modify onset/duration/amplitude of stimulus & \\ \hline Keep5 tims & Removes all stimuli except those specified & \\ \hline Remove5 timLess & Discard data files with no stimulus information & \\ \hline \multicolumn{3}{c}{**Filter**} \\ \hline BaselineCorrection & Motion-correction filter to remove DC sifts & See Section 2.2.2.1 \\ \hline PCAFilter & PCA filter for motion or physiology & [19] \\ \hline WaveletFilter & Filter to remove outliers and low-frequency & [35] \\ \hline \multicolumn{3}{c}{**Statistical analysis**} \\ \hline ANOVA & Group-level ANOVA model & Matlab: _filtme.m_ function \\ \hline AR-IRLS & GLM analysis using autoregressive model & [16] \\ \hline Connectivity & Computes all-to-all connectivity model & [18] \\ \hline Hyperscanning & Computes all-to-all connectivity between two files & [18] \\ \hline ImageReconstruction & Subject or group-level image reconstruction model & [33; 36; 37] \\ \hline MixedEffects & Group-level linear mixed effects model & Matlab: _filtme.m_ function \\ \hline NIRS-SPM & GLM analysis using NIRS-SPM & [20] \\ \hline OLS & GLM analysis using ordinary least squares & [19] \\ \hline RemoveOutlierSubjects & Flags and removes outlier subjects based on leverage & \\ \hline SubjLevelStats & Subject-level analysis & Matlab: _filtme.m_ function \\ \hline \multicolumn{3}{c}{**Additional**} \\ \hline HOMER2 & Interface to HOMER2 code & [10; 19] \\ \hline \hline \end{tabular}
\end{table} 
Table 2: List of the basic processing modules in the AnalyzIR toolbox. where \(k\) is the index of the measurement sample. The optimal model order (\(p\)) is computed from a Bayesian information criterion with a default maximum of 8 times the sample rate (e.g., 8 \(\times\) 10 Hz = 80 samples). The integrative order is set at 1 and is not adjusted. Based on the estimated model coefficients, the innovations time course is extracted. The innovations of the model are the unique information \"injected\" at each time point, which is not predicted by the autoregressive history of the data. As described in our work on AR pre-whitening of the GLM model [16] both spike and shift variations of motion artifacts in fNIRS data are often statistical outliers in this innovations space. Although not all motion artifacts will be outliers, fixing non-statistical outliers are less relevant for the model. From the studentized innovations, a weighting function is computed using the Huber bisquare function  
\[\mathbf{w}\bigg{(}\frac{inn}{\sigma}\bigg{)}= \begin{cases}1-\Big{(}\frac{im}{ \sigma\cdot\kappa}\Big{)}^{2}&\Big{|}\frac{im}{\sigma}\Big{|}<\kappa\\ 0&\Big{|}\frac{im}{\sigma}\Big{|}\geq\kappa\end{cases}  \tag{5}\]  
where the weight (\(\mathbf{w}\)) varies from 0 (discard; definitely an outlier) to 1 (keep), \(\sigma\) is the standard deviations of the errors, and \(\kappa\) is the tuning constant (\(\kappa=4.685\) for the bisquare produce 95% efficiency when the errors are normal).