# The NIRS Brain AnalyzIR Toolbox
## 3 Statistical Modules
### Second-Level Statistical Models
\begin{array}{c}\Theta_{A}\\ \vdots\\ \Theta_{N}\end{array} \right]+\
u \tag{16}\]  
where the terms \(\Gamma_{low}\), \(\Gamma_{med}\), and \(\Gamma_{highT}\) denote the main group level effects for the three task conditions and the terms \(\Gamma_{X:Age}\) denote the interaction terms between the three conditions and age. The second matrix (**B**) and coefficients (\(\Theta\)) denote the random effects terms (here indicating subject as a random effect). Since the covariance of this model is known from the first level model (Section 3.1), the mixed effects model is then solved for using weighted least-squares regression where a weighting matrix (\(\Omega\)) is applied to the left and right hand sides of the expression and given by  
\[\mathbf{\Omega}\cdot\mathbf{\beta}=\mathbf{\Omega}\cdot\mathbf{A}\times\Gamma +\mathbf{\Omega}\cdot\mathbf{B}\cdot\mathbf{\Theta}+\mathbf{\Omega}\cdot\
u\] (17a) where the whitening matrix is defined as \[\Omega^{T}\times\Omega=\mathbf{Cov}_{\mathbf{\beta}}^{-1} \tag{17b}\]  
and \(\mathbf{Cov}_{\mathbf{\beta}}\) is the noise covariance matrix given in Equations (9b) and (12b), which was estimated from the temporal general linear model (Section 3.1) \(\mathbf{\Omega}\) is estimated from a singular value decomposition of the symmetric covariance matrix. Note that we have written this expression only for one fNIRS measurement channel for simplicity, but in reality this model also includes all source-to-detector channels simultaneously and is given by the form  
\[\mathbf{\Omega}\;(\mathbf{A}\otimes I_{CHAN})\cdot\Gamma+\mathbf{\Omega}( \mathbf{B}\otimes I_{CHAN})\cdot\mathbf{\Theta}+\
u, \tag{18}\]  
where \(I_{\mathbf{CHAN}}\) is an identity matrix of size number of fNIRS source-to-detector pairs and \(\otimes\) is the Kronecker operator. In this way, all fNIRS source-detector pairs are analyzed simultaneously, which allows the use of the full covariance noise model (including spatial relationships) to be used in whitening the model via Equation (17). When running the higher-order statistical models, there is a program flag for including \"diagnostics\" as part of the toolbox. If selected, this flag will store additional model assessment information in the output variable which can be used to select outlier subjects, examine goodness-of-fit of the model, and plot the model (e.g., showing a scatter plot of how brain activity varies with age). In our second-level models, we are able to use the full covariance from the first-level model to performed weighted least-squares. This model additionally supports iterative (robust) statistics to down-weight outliers. This allows us to account for the fact that the noise in measurement channels may vary across the fNIRS probe or across subjects. In particular, contact of the optodes to the scalp will be have a large impact on the spatial variations of noise. In comparison to second level analysis using external programs such as SPSS, where either all measurements are considered to have the same noise or where the diagonal component of the noise covariance can be used to created a weighted model, by using the full covariance noise model we are able to control for the interdependence of measurements (e.g., artifacts or physiology that share noise across multiple channels). Figure 4 shows the comparison in the second-level or group-level analysis with no outliers (left column) and with outliers (right column) as shown in 4(a-c) and 4(d-f), respectively. In this simulation, we used 10 files for analyzing the second-level analysis. In the mixed effects model (see Table 3), we modeled the first-level beta values as the dependent variable with either only fixed effects (FE) or fixed and random effects (RE), combining with/without robust and covariance-weighting flags. Thirty-two channels from one file with no outliers (Figure 4a) and with 4 out of 32 channels outliers (4(b)) are shown. In this case, the outlier channels simulate a few positions with poor coupling to the scalp.