# The NIRS Brain AnalyzIR Toolbox
## 4 Image Reconstruction Modules
### Group-Level Image Reconstruction  
The image reconstruction code in the AnalyzIR toolbox can be used for either single subject reconstructions or as a group-level model. In the group-level model, a linear mixed effects model is used and specified using the same Wilkinson-Rogers notation as the channel space group-level statistical models. In the group-level image reconstruction, a single inverse model is simultaneously solved for all subjects and task conditions within a large-scale inverse rather than a separate inverse for each image. As detailed in our previous work [36], this allows the estimate of a single group-level image, which is based on finding a solution to the model that concurrently fits all the subjects' data. This was previously shown to greatly improve group-level image estimates by reducing the uncertainties added by the ill-posed nature of the problem [36].  
In the group-level reconstruction, the optical forward model can be represented using a three-level model and given by the following equations  
Level I--Measurement level:  
\[\mathbf{\gamma}^{Subject}=\mathbf{H}\cdot\mathbf{\beta}^{Subject}+\mathbf{v}^{Subject}\] (25a) Level II--Subject level: \[\mathbf{\beta}^{Subject}=\mathbf{\beta}^{Group}+\Delta\mathbf{\beta}^{Subject}\] (25b) Level III--Group level: \[\mathbf{\beta}^{Group}=\mathbf{\beta}^{Group}_{0}+\mathbf{\omega}^{Group} \tag{25c}\]  
where \(\mathbf{\beta}^{Group}_{0}\) is a prior on the expected value of the brain image for the group and the three noise terms (\(\mathbf{\
u}\), \(\Delta\mathbf{\beta}\), \(\mathbf{\omega}\)) are defined as follows (\(\mathcal{N}_{N}(\mathbf{\mu},\mathbf{\Sigma})\) denotes a \(N\)-variate normal distribution with mean vector \(\mathbf{\mu}\) and covariance matrix \(\mathbf{\Sigma}\) where \(N\) is the number of measurements):  
\[\mathbf{v}^{Subject}\sim\mathcal{N}_{N}\Big{(}0,\mathbf{C_{N}^{-1}}\Big{)}\quad \Delta\mathbf{\beta}^{Subject}\sim\mathcal{N}_{N}\Big{(}0,\mathbf{C_{B}^{-1}} \Big{)}\quad\quad\mathbf{\omega}^{Group}\sim\mathcal{N}_{N}\Big{(}0,\mathbf{C_{G}^ {-1}}\Big{)} \tag{25d}\]  
The free-energy expression for the model is given by  
\[\underset{\{\mathbf{\beta},\mathbf{C_{N}},\mathbf{C_{B}},\mathbf{C_{G}}\}}{\arg \max}\quad-\tfrac{1}{2}\|\mathbf{Y}-\mathbf{H}\cdot\mathbf{\beta}^{Subject}\|^{2} _{\mathbf{C_{N}}}-\tfrac{1}{2}\|\Delta\mathbf{\beta}^{Subject}\|^{2}_{\mathbf{C_{ B}}}-\tfrac{1}{2}\|\beta^{Group}-\mathbf{\beta}^{Group}_{0}\|^{2}_{\mathbf{C_{G}}} \tag{26}\]To solve the model, the covariance matrices are parameterized and ReML is implemented to solve the model, which is very similar to the inverse model in 4.2. The details can be found in [36]. In this model, all the subjects are simultaneously used to estimate the most consistent underlying image of the group-level brain activity. Our previous work [36] demonstrated that this greatly reduced the spatial point-spread introduced by probe registration and head anatomy differences and helped to avoid the effects of \"blind-spots\" in low density fNIRS probes by additionally using the information from all the subjects. The group-level random effects model described in [PERSON] et al. [36] is implemented in the image reconstruction code of our toolbox. In addition, this model has been extended to allow additional covariates and terms similar to the channel-level mixed effects model discussed in Section 3.5. Our image reconstruction model uses the same Wilkinson-Rogers' notation as the channel-level version.