What a Reliability Diagram Shows
A cell-type classifier can assign each cell a probability for every candidate label. Those numbers are useful only if their magnitudes have a sensible interpretation. For example, among cells assigned a probability near 0.8 for a particular cell type, does that label occur in roughly 80% of the reference-labeled cells? A reliability diagram makes this comparison visible.
The diagram evaluates the probabilities against labels in a validation set whose annotations are treated as the reference outcome for this analysis. It does not establish that those labels are biologically definitive, nor does it show that the annotation caused any downstream result. Its interpretation depends on the validation labels and on whether the validation cells are relevant to the cells for which the model will be used.
The condition says that cells assigned probability \(q\) to class \(k\) should have reference label \(k\) at frequency \(q\), in the population being assessed. It is a statement about frequency among cells with a given predicted probability, not a claim that an individual cell has a fractional or known label. For practical diagrams, probabilities are grouped into bins because a finite validation set will rarely contain many cells with exactly the same probability.
Constructing a Class-Specific Diagram
For a chosen class \(k\), partition the probability range into bins \(B_1,\ldots,B_m\). For example, bins might cover \([0,0.2)\), \([0.2,0.4)\), and so on, with the final bin including 1. Let \(I_b\) be the validation cells whose class-\(k\) probabilities fall in bin \(B_b\), and let \(n_b\) be their number. For each nonempty bin, calculate the average predicted probability and the observed fraction with reference label \(k\):
Plot \(\bar{p}_{bk}\) on the horizontal axis and \(\hat{r}_{bk}\) on the vertical axis. The diagonal \(y=x\) represents perfect agreement between the bin's average prediction and its observed class frequency. A point above the diagonal has \(\hat{r}_{bk}>\bar{p}_{bk}\): the class occurred more often than the probabilities suggested in that bin. A point below it indicates overprediction of that class in the bin. The point's size can represent \(n_b\), so a reader can distinguish a well-supported pattern from one based on very few cells.
The population justification is direct. For a bin event \(P_k\in B_b\), where \(P_k\) denotes the predicted probability for a randomly selected cell, class-wise calibration gives:
The first equality is the iterated-expectation rule, and the second substitutes \(E[Z_k\mid P_k]=P_k\). Thus, under calibration, the population observed frequency in a probability bin equals the population mean predicted probability in that bin. The plotted values are sample estimates of these quantities; finite samples need not lie exactly on the diagonal. This argument conditions on a cell's own probability falling in the bin, not on the full vector of probabilities for all cells.
Worked Example: Building a Diagram for One Cell Type
Suppose a hypothetical held-out set contains 14 cells for which a classifier's probabilities for a particular cell type are grouped into three bins. The table gives the number of cells, the sum of their probabilities, and the number whose reference label is that type.
| Probability bin | \(n_b\) | Sum of probabilities | Reference positives |
|---|---|---|---|
| [0.2, 0.4) | 4 | 1.30 | 1 |
| [0.4, 0.7) | 5 | 2.75 | 3 |
| [0.7, 1.0] | 5 | 4.00 | 4 |
For the first bin, \(\bar{p}_{1k}=1.30/4=0.325\), while \(\hat{r}_{1k}=1/4=0.250\). The plotted point is \((0.325,0.250)\), below the diagonal: in this sample, the class occurred less often than the average probability predicted.
For the second bin, \(\bar{p}_{2k}=2.75/5=0.550\) and \(\hat{r}_{2k}=3/5=0.600\), giving \((0.550,0.600)\), above the diagonal. For the third, \(\bar{p}_{3k}=4.00/5=0.800\) and \(\hat{r}_{3k}=4/5=0.800\), exactly on it. These are sample summaries, not proof that the underlying class is calibrated in the third bin.
A simple weighted absolute calibration gap for these bins is \(\sum_b(n_b/14)|\hat{r}_{bk}-\bar{p}_{bk}|\). Here it is \((4/14)(0.075)+(5/14)(0.050)+(5/14)(0)=0.0393\), or about 3.93 percentage points. This summary describes the binned discrepancies; it does not replace examining the diagram, since opposite directions and localized problems can be hidden by a single number.
Choosing Bins and Reading Their Limits
Bin choice affects both the visual pattern and the stability of each point. Equal-width bins divide the probability scale into intervals of the same length. They make positions easy to compare across the scale, but high-confidence or low-confidence regions can contain few cells. Equal-frequency bins are chosen to contain roughly similar numbers of cells. They can reduce differences in point precision, but their probability ranges may be very different in width and can change with the validation sample. Ties in predicted probabilities can also make exactly equal bin counts impossible; keep tied values together where practical and report how boundaries were handled.
There is no universally best number of bins. Many narrow bins can reveal local departures but yield noisy observed proportions. A small number of broad bins is steadier but can conceal curvature or offsetting behavior within a bin. State the binning rule and show the bin counts. When the scientific interpretation depends on a particular probability range, choose bins that preserve that range and disclose the choice rather than adjusting boundaries until the plot looks reassuring.
Sparse bins deserve special care. A bin with one or two cells can sit far from the diagonal simply because its observed fraction can only take a few values, such as 0, 0.5, or 1. A large discrepancy in such a bin is a prompt to inspect the evidence, not a precise estimate of a stable calibration error. Conversely, a bin with many cells can still be misleading if those cells are highly dependent, for example because many come from the same donor.
Worked Example: Interpreting a Sparse Bin
In a hypothetical diagram, 6 of 8 cells in a bin have the reference label, so the observed fraction is \(6/8=0.750\). Their average predicted probability is 0.600. The plotted point is \((0.600,0.750)\), apparently above the diagonal by 0.150. Because there are only eight cells, the observed fraction is uncertain.
For illustration, a Wilson interval for a binomial proportion with \(x=6\), \(n=8\), and 95% confidence uses \(\hat{p}=x/n=0.750\), \(z=1.96\), and denominator \(1+z^2/n\). Its center and half-width are:
The resulting interval is approximately \((0.409,0.929)\). Under the simple independent-binomial approximation, it expresses substantial uncertainty about the bin's observed frequency; it is not a 95% probability statement about a fixed parameter. Here the interval is only an illustration: cells with different predicted probabilities need not have a common success probability, and cells from the same donor may be dependent. Those features can make the ordinary binomial interval inappropriate. A donor-aware resampling or other design-appropriate uncertainty analysis may be needed for inferential claims.
Calibration Must Be Examined by Class
For a problem with \(K\) cell types, construct a one-versus-rest diagram for each class \(k\): the event is “the reference label is \(k\),” and the probability is \(p_{ik}\). This is class-wise calibration. It can reveal that probabilities for one cell type are systematically too high while probabilities for another are too low, even if a pooled display appears satisfactory.
Do not confuse this with top-label or confidence calibration. Top-label calibration asks whether cells for which the model's largest class probability is, for example, 0.8 are correctly classified about 80% of the time. Class-wise calibration instead asks whether a particular class probability \(p_{ik}\) matches the frequency of that class. The two questions use different groupings and can have different answers. Likewise, a class-wise diagram does not show whether the model ranks cells well, whether every cell has an unambiguous biological identity, or whether a reference label is correct.
Worked Example: Why a Pooled Plot Can Hide Class Errors
Consider two cell types, A and B, each with 20 hypothetical validation cells in a bin whose mean predicted probability for that class is 0.800. For type A, 18 of 20 cells have reference label A, so its observed fraction is \(18/20=0.900\), a gap of \(+0.100\). For type B, 14 of 20 have reference label B, so its observed fraction is \(14/20=0.700\), a gap of \(-0.100\).
If the two class summaries are pooled without retaining class identity, the average observed fraction is \((18+14)/40=32/40=0.800\), equal to the pooled mean predicted probability of 0.800. That pooled agreement conceals opposite class-specific departures. The appropriate reliability display therefore preserves class identity, with a separate series or panel for each cell type. The example is about calibration summaries, not a claim that the two sets of class-specific events are independent.
Diagnostics, Alternatives, and Limitations
Inspect more than distance from the diagonal. Check the bin counts, whether the points cover the probability range of interest, and whether a pattern persists across reasonable binning choices. A single extreme point in a tiny bin may be sampling noise; a consistent curve above or below the diagonal across populated bins is more concerning. Compare class-specific panels: a good-looking average can conceal a poor result for a less frequent class. Also check that the validation labels, probability-generating procedure, and target population align with the intended use. Leakage between model fitting and validation can make the diagram look artificially reassuring.
A smooth calibration curve is an alternative to bins: it estimates observed class frequency as a function of predicted probability without hard boundaries. It avoids abrupt bin edges but depends on smoothing choices and can be unstable where data are sparse. A calibration intercept and slope provide compact summaries of certain systematic patterns, but they do not show all local departures. Reliability diagrams are often preferred for visual diagnosis; numerical summaries can supplement them, not replace the plot and its support information.
A diagram is descriptive, not a stand-alone hypothesis test. It has limited resolution, depends on binning, and evaluates performance only in the labeled validation population. Calibration can change when the mixture of donors, batches, tissues, or cell states changes. In single-cell data, treating thousands of cells as independent can greatly overstate how much information a validation set contains when many cells come from a small number of donors. Report the validation design and use uncertainty methods that respect its dependence structure when making inferential claims.
Check Your Understanding
Answer the questions, then compare your reasoning with the solutions below.
- A bin contains 12 cells, with predicted probabilities summing to 8.4 and 9 reference positives. What are the plotted coordinates, and what is the direction of the discrepancy?
- Why does class-wise calibration imply equality of population observed and predicted averages within a probability bin?
- What is one benefit and one limitation of equal-frequency bins compared with equal-width bins?
- Two classes have equal-sized bins with equal mean predictions, but one is overpredicted and the other underpredicted. Why can pooling be misleading?
- Why might a binomial interval for a bin be unreliable when cells come from a small number of donors?
Solutions. (1) The mean prediction is \(8.4/12=0.700\), and the observed fraction is \(9/12=0.750\), so the point is \((0.700,0.750)\), above the diagonal. (2) By iterated expectation, \(E[Z_k\mid P_k\in B]=E\{E[Z_k\mid P_k]\mid P_k\in B\}=E[P_k\mid P_k\in B]\). (3) Equal-frequency bins tend to have more comparable counts, but their probability widths vary and may depend on the sample. (4) Opposite class-specific gaps can cancel in a pooled average, hiding errors that matter for each class. (5) Cells from the same donor may be correlated, so the effective information is smaller than the cell count suggests and the independent-binomial model understates uncertainty.