# (Advanced)Mathematical definition Last updated: 2026-07-11 This note defines the observed-to-expected ratio used by `stg_pair_enrichment()` and separates the scientific estimator from the finite value used only for heatmap display. --- ## 1. Statistical unit and notation Let $r$ index an independent ROI or biological replicate, $c$ index a condition, and $i,j,k$ index cell types. Within ROI $r$, define: | Symbol | Definition | |---|---| | $S_{ir}$ | number of singlets assigned to type (i) | | $S_r=\sum_kS_{kr}$ | total singlet count | | $p_{ir}=S_{ir}/S_r$ | empirical singlet proportion | | $D_r$ | total number of certain heterotypic mixed units | | $O_{ijr}$ | observed count of the undirected pair $\{i,j\}$ | The braces $\{i,j\}$ indicate an unordered pair: $\{i,j\}=\{j,i\}$. Therefore, each biological pair appears once in the triangular heatmap. --- ## 2. Conditional heterotypic null model Consider two independent draws $X,Y$ from the ROI singlet composition. Before conditioning, ```{math} P(X=i,Y=j)=p_{ir}p_{jr}. ``` For $i\ne j$, the unordered event $\{i,j\}$ contains two mutually exclusive ordered outcomes, $(i,j)$ and $(j,i)$. Thus, ```{math} P(\{i,j\})=2p_{ir}p_{jr}. ``` The probability that two draws have different types is ```{math} H_r=P(X\ne Y) =1-P(X=Y) =1-\sum_kp_{kr}^2. ``` Because the analyzed RCTD class consists of heterotypic doublets, the relevant sample space is $X\ne Y$. The conditional pair probability is therefore ```{math} q_{ijr} =P(\{i,j\}\mid X\ne Y) =\frac{2p_{ir}p_{jr}}{1-\sum_kp_{kr}^2}, \qquad i1$, or $L>0$: enriched relative to the null. - $R_{O/E}=1$, or $L=0$: consistent with the null expectation. - $0