## 2 Materials and Methods
### A Data-Driven Approach for Characterizing Changes in Respiratory Baseline  
According to the AASM, an apnea event is scored if there is a drop in peak thermal airflow signal excursions by \(\geq\)90% of the corresponding baseline for a duration \(\geq\)10 s [11]. Nevertheless, the airflow baseline is not precisely defined neither in the AASM Scoring Manual nor in sleep literature. \begin{table}
\begin{tabular}{l c c c c} \hline \hline
**Severity Level** & **OSA** & **CSA** & **MSA** & **Total** \\ \hline
**None/Minimal** & 20 & 312 & 0 & 332 \\
**Mild** & 1302 & 1887 & 78 & 3267 \\
**Moderate** & 3056 & 4240 & 400 & 7696 \\
**Severe** & 10,922 & 23,960 & 2143 & 37,025 \\
**Total** & 15,300 & 30,399 & 2621 & 48,320 \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Distribution of Number and Types of Apneic Events per each Class of the Severity Levels. To overcome this limitation, a data driven approach will be used to derive the respiratory flow baseline from the airflow signal (FlowTH). The derived baseline will then be used to characterize dynamic changes in respiration with respect to this (dynamic) baseline in order to detect the occurrence of apneic events. To establish respiratory baseline, we will consider two important respiratory features: Inter-breath intervals and breath amplitudes. A sliding window method will be used for detecting apnea events in the oronasal airflow signal (FlowTH). At time step \(t\), two windows will be established. The first window (baseline window-\(W_{b}\)) will be used to derive the local respiratory baseline. The second window (detection window-\(W_{m}\)) will be used to detect apneic events based on relative changes in inter-breath intervals and breath amplitudes in \(W_{m}\) with respect to those in the \(W_{b}\). In this study, we considered a \(W_{b}\) of length \(L_{b}=600\) s that contains the airflow measurements up to time \(t\) and a \(W_{m}\) of length \(L_{m}=100\) s that contains airflow measurements starting from time step \(t+1\). After constructing \(W_{b}\) and \(W_{m}\), peaks and valleys of the respiratory airflow signal are detected in both windows. An example of \(W_{b}\) and \(W_{m}\) that both include an apneic event along with peak and valley detections is illustrated in Figure 1a. The inter-breath intervals and the breath amplitudes can now be extracted from \(W_{b}\) and \(W_{m}\) as follows:  
\[PP_{i} = t_{i+1}-t_{i} \tag{1}\] \[PV_{i} = P_{i}-V_{i} \tag{2}\]  
where the airflow breath \(i\) has a peak \(P_{i}\) that occurs at time instance \(t_{i}\), a valley \(V_{i}\), an inter-breath interval \(PP_{i}\), and a breath amplitude \(PV_{i}\). These Equations generate sequences of inter-breath intervals and breath amplitudes in \(W_{b}\) and \(W_{m}\) as illustrated in Figure 1b,c,f,g. After getting these sequences, it is required to extract the (inter-breath) intervals and (breath) amplitudes in \(W_{b}\) that contribute most to the respiratory baseline estimate of this window. Similarly, it is required to extract the intervals and amplitudes in \(W_{m}\) that belong to the apneic event to be detected. This can be effectively done by sorting sequences of intervals and amplitudes in both \(W_{b}\) and \(W_{m}\) based on corresponding values. For convenience, \(PP_{i}\) and \(PV_{i}\) in \(W_{b}\) are sorted in a descending order while those in \(W_{m}\) are sorted in an ascending order as illustrated in Figure 1d,e,h,i. This process will generate ordered sequences \(PP_{b}=\{PP_{i}^{d}\}\), \(PV_{b}=\{PV_{i}^{d}\}\), \(PP_{m}=\{PP_{i}^{a}\}\), and \(PV_{m}=\{PV_{i}^{a}\}\) where subscripts \(b\) and \(m\) specify \(W_{b}\) and \(W_{m}\) respectively, and superscripts \(a\) and \(d\) specify ascending and descending orders respectively. Although the length of \(W_{b}\) and \(W_{m}\) are fixed, the number of airflow breaths in these windows typically vary during different sleep stages and across different patients.