# The NIRS Brain AnalyzIR Toolbox
## 3 Statistical Modules
### Second-Level Statistical Models  
Second-level (e.g., group) models using fixed-effects, mixed-effects, or ANOVA are offered as modules in the toolbox. For all three of these processing modules, a formula is specified to define the statistical model used. This formula is defined in Wilkinson-Rogers notation (2000), which is also used in Matlab (e.g., _filtme.m_ function) and R software packages. The statistical model formula is able to use any demographics variables stored in the first-level _ChannelStats_ variables such as subject ID, group membership, age, etc. Both categorical and continuous variables are supported in these models. Examples of the Wilkinson-Roger's notation is shown in Table 3.  
As an example, let's consider a group level model consisting of 20 subjects with a range of ages. Each subject preformed three tasks (low, medium, and high) and therefore there are a total of 60 variables (\(\beta\); 20 subjects x tasks) from the first-level models. For the moment, we are only dealing with a single source-detector pair to simplify the example. We wish to use a mixed effects model to examine the group response and the effect of age on the brain response. The formula we will use has the form \"beta \(\--\)\(1\) + cond + cond \(\times\) age + (1 subject)\", which encodes a model with a term for each task conditions (independent of the subject age) and a second term capturing how the brain response to the condition covariates according to subject age. We will center the variables in the model (the default option in the toolbox), which means that the age-independent term will represent the brain activity for a subject of the average age in our group. In this formula, the demographics variable \"subject\" is denoted as a random effect, which will pool across the three conditions for each of the 20 subjects. The group-level mixed effects model is described by the equation  
\[\beta=\mathbf{A}\cdot\Gamma+\mathbf{B}\cdot\Theta+\epsilon \tag{15}\]  
where \(\beta\) is the vector of weights obtained from the first level statistical model entries for each subject, task condition, and source-detector pair. \(\mathbf{A}\) is the fixed effects model and \(\mathbf{B}\) is the random effects model matrices. In this example of using inclusion of the age as a cofactor is given by  
Figure 3: General linear model (GLM) comparison of no motion (left column) and motion-affected (right column). In panels (**a,d**), raw signals with no motion artifacts and with artifacts are shown. After simulations, the ROC curves for the various processing applied to the simulated data are shown in (**b,e**). Panels (**c,f**) show control for type-I errors for the same data and processing. An ideal curve would be along the diagonal (slope = 1), where the reported and actual FPRs would be the same. \begin{table}
\begin{tabular}{l l} \hline \hline
**Formula** & **Interpretation** \\ \hline beta \(\--\)\(1\) + cond + (11 subject) & Effect of condition, controlling for subject \\ \hline beta \(\--\)\(1\) + group:cond + (11 age) & Effect of condition for each group, controlling for age \\ \hline beta \(\--\)\(1\) + group + cond + group\({}^{\star}\)cond + (11 IQ) & Main effects of group and condition, and a group x condition interaction, controlling for IQ \\ \hline \hline \end{tabular}
\end{table} 
Table 3: Examples of Wilkinson–Rogers notation. \[\left[ \begin{array}{c}\beta_{Subj_{A},Cond_{Luo}}\\ \beta_{Subj_{A},Cond_{Mact}}\\ \beta_{Subj_{A},Cond_{Mact}}\\ \beta_{Subj_{A},Cond_{High}}\\ \vdots\\ \beta_{Subj_{N},Cond_{Luo}}\\ \beta_{Subj_{N},Cond_{Mact}}\\ \beta_{Subj_{N},Cond_{High}}\end{array} \right]=\left[ \begin{array}{cccc}1 &&age_{A}&&\\ 1&&age_{A}&&\\ &1&&age_{A}&\\ &\ddots&&\ddots&\\ 1&&age_{N}&&\\ &1&&age_{N}&\\ &1&&age_{N}&\\ \end{array} \right]\left[ \begin{array}{c}\Gamma_{Low}\\ \Gamma_{Med}\\ \Gamma_{High}\\ \Gamma_{Low:Age}\\ \Gamma_{Med:Age}\\ \Gamma_{Med:Age}\\ \Gamma_{Hig:Age}\end{array} \right]+\left[ \begin{array}{c}1\\ 1\\ 1\\ \vdots\\ 1\\ 1\\ 1\end{array} \right]\times\left[