# Probability of sampling enough cells of a rare type among profiled cells

`singlecell_sampling_probability` · Runs: On the server · Level: Its calculation passed Drybench's full check: source read, a separately written implementation, edge and refusal cases, and an outside comparison where one exists. It stays below the top level because no measured prediction error is available for the model. Calculation fully checked; model error not measured

Works out the probability that profiled cells hold at least k cells of a rare type, by a binomial model.

Research and education software; not medical advice, and not for diagnosis or treatment decisions. It computes from the inputs it receives. It does not check the person's data, design or sample.

[Catalogue](https://www.drybench.com/mcp/catalogue) / [Cell culture](https://www.drybench.com/mcp/catalogue/cell-culture)

[Ask your assistant](https://www.drybench.com/mcp/connect)

```cite
Probability of sampling enough cells of a rare type among profiled cells (singlecell_sampling_probability), Drybench MCP server 1.0.0; singlecell-sampling-probability@1.0.1 (Calculation fully checked; model error not measured); https://www.drybench.com/mcp/tools/singlecell-sampling-probability
```

## What it is

Returns the probability that profiled cells hold at least k cells of a rare type, by a binomial sampling model. Use when the cells profiled per sample are fixed and the question is whether a rare type will be seen, in one sample and in all of several. Not for the number of cells needed: use \`singlecell\_cells\_required\`. Cells are those recovered after quality control, each an independent, unbiased draw; the frequency, the minimum and the samples are stated, never assumed; counts above the ranges are refused.

Field: [Cell culture, microbiology, virology](https://www.drybench.com/mcp/catalogue/cell-culture).

## What it does

**You give**

- `cellsPerSample` (required): The cells profiled per sample: recovered after quality control, not loaded. At most ten million. Must be at least 1 and at most 9007199254740991.
- `frequency` (required): The frequency of the cell type among profiled cells, as a fraction (1) or in %, above 0 and at most 1. Never assumed. Must be above 0 and at most 1.
- `minimumCells` (required): The fewest cells of the type wanted in each sample. Never assumed. At most 10,000. Must be at least 1 and at most 9007199254740991.
- `samples` (required): The number of samples, each profiled separately; 1 for a single sample. Never assumed. At most 10,000. Must be at least 1 and at most 9007199254740991.

No request is recorded for this tool.

**Limits**

- Research arithmetic for planning single-cell experiments on values you supply; probabilities come from a stated sampling model, and no cell number or target is chosen for you.
- Each recovered cell is taken as an independent draw at the frequency you state, the same in every sample.
- Capture bias, doublets, quality-control loss and differences between samples are not modelled.
- A model's probability, not a forecast.
- Every computed number a reply returns, other than an integer or an exact decimal, is rounded once to 12 significant figures: to the nearest, a change of at most 5 × 10⁻¹² of its value, except that a lower bound is rounded down and an upper bound up, a change of less than 1 × 10⁻¹¹; the method computes, and decides any pass or fail, on the unrounded value.

**It will not answer when**

- the number of cells per sample, the fewest cells wanted or the number of samples is above the range the method was checked over.
- the model's probability for one sample, or for every sample, is above zero and below the smallest normal double.

### Every input, with its units

4 inputs

- `cellsPerSample` (required): The cells profiled per sample: recovered after quality control, not loaded. At most ten million. Must be at least 1 and at most 9007199254740991.
- `frequency` (required): The frequency of the cell type among profiled cells, as a fraction (1) or in %, above 0 and at most 1. Never assumed. Must be above 0 and at most 1.
- `minimumCells` (required): The fewest cells of the type wanted in each sample. Never assumed. At most 10,000. Must be at least 1 and at most 9007199254740991.
- `samples` (required): The number of samples, each profiled separately; 1 for a single sample. Never assumed. At most 10,000. Must be at least 1 and at most 9007199254740991.

### Every refusal, with its code

2 refusals

| Code | When |
| --- | --- |
| `COUNT_ABOVE_RANGE` | the number of cells per sample, the fewest cells wanted or the number of samples is above the range the method was checked over. |
| `RESULT_OUTSIDE_DOUBLE_RANGE` | the model's probability for one sample, or for every sample, is above zero and below the smallest normal double. |

## The calculation

The method's equations, constants and worked example.

### [Probability that profiled cells hold enough cells of a rare type](https://www.drybench.com/methods/m/singlecell-sampling-probability/1.0.1)

`singlecell-sampling-probability@1.0.1`

**Equation 1**

```text
P₁ = F_NB(N − k
k, f) = 1 − Σ_{i=0}^{k−1} C(N, i)·f^i·(1 − f)^(N − i)
formed as the smaller of its two sums: one minus the lower sum over i < k when k is at or below N·f, else the upper sum from i = k, which stops when the next term with the geometric bound on all that follow is below 2^−60 of the sum, or at i = N
order of checks: the kit's checks of each argument against the schema's range (counts at least 1 and at most 2^53 − 1, frequency above 0 and at most 1, else OUT_OF_RANGE), then the method's range (cells per sample at most 10^7, the fewest cells and the samples at most 10,000, else COUNT_ABOVE_RANGE), then RESULT_OUTSIDE_DOUBLE_RANGE
a frequency in % is divided by 100 and its range (0, 1] is tested on the converted double, not the stated decimal, so 100.00000000000001 % is accepted as 1
```

| Symbol | Meaning |
| --- | --- |
| `N` | the number of cells profiled per sample: cells recovered after quality control, not cells loaded (argument cellsPerSample) |
| `f` | the frequency of the cell type among the profiled cells, a fraction above 0 and at most 1 (argument frequency) |
| `k` | the fewest cells of the type wanted in a sample (argument minimumCells) |
| `C(N, i)` | the binomial coefficient, the number of ways to choose i cells among N |
| `F_NB` | the cumulative negative binomial distribution, as the source writes the model: the probability of at most N − k cells of other types before the k-th cell of the type |
| `P₁` | the probability that one sample holds at least k cells of the type, returned as probabilityPerSample; exactly 0 when k is above N |

Source 1.

**Equation 2**

```text
P = P₁^s
```

| Symbol | Meaning |
| --- | --- |
| `P₁` | the probability for one sample |
| `s` | the number of samples, each profiled separately (argument samples) |
| `P` | the probability that every one of the s samples holds at least k cells of the type, returned as probabilityAllSamples |

Source 1.

A model of nature: it predicts a measurement and can be wrong for your sample. No prediction error is available.

**Worked example**

Worked example: one case of singlecell-sampling-probability\@1.0.1, from its inputs through each step to the answer. Values are written as a person writes them; the working carries more digits, so your own figure may differ in the last digit shown.

**Inputs**

- cellsPerSample = 10
- frequency = 0.1
- minimumCells = 1
- samples = 3

**Steps**

1. noneOfTheType = 0.34867844, from cellsPerSample, frequency; by equation 1.
2. perSample = 0.65132156, from noneOfTheType; by equation 1; gives probabilityPerSample.
3. allSamples = 0.27630349, from perSample, samples; by equation 2; gives probabilityAllSamples.

The working, as the case writes it:

```text
with k = 1 the sum has one term, the probability that no cell is of the type: (1 − 0.1)^10 = 0.34867844
so one sample holds at least one with probability 1 − 0.34867844 = 0.65132156, and all 3 samples do with probability 0.65132156^3 = 0.27630349 (worked by hand by Drybench on 12 November 2026
not an independent check)
```

**Answer**

- probabilityPerSample = 0.65132156
- probabilityAllSamples = 0.27630349

Where these values came from: an outside program, mpmath (arithmetic: mpf powers and products) 1.3.0; stored reference values (mpmath 1.3.0 arithmetic at 400 digits).

At build the tool returned this answer within the tolerance the file states: both probabilities relative 1e-9, with a floor of 1e-209 below 1e-200; statuses, codes and units exact.

Who worked this case: not recorded.

## Sources

1. Schmid KT, Höllbacher B, Cruceanu C, Böttcher A, Lickert H, Binder EB, Theis FJ, Heinig M, scPower accelerates and optimizes the design of multi-sample single cell transcriptomic studies, Nat Commun 12:6625 (2021) Used for: Probability that profiled cells hold enough cells of a rare type. At: section Methods, Frequency of the rarest cell type. **Read in full, 12 November 2026**

Read by AI-assisted sessions. No person has checked these readings.

## How it is checked

**Level:** Calculation fully checked; model error not measured.

**Checked against:** A reference program this project wrote itself, mpmath (arithmetic: mpf powers and products), 1.3.0, direct summation of the binomial terms in mpmath 1.3.0 at 400 decimal digits; no special function; not an outside program; a reference program this project wrote itself, second implementation (Python 3.13, mpmath), 2026-11-14, mpmath sums at 100 to 120 significant digits, rounded once to a double; not an outside program.

**Cases:** No case set is linked to this version.

**Not checked:** Whether cells are captured independently and without bias for the type; doublets, ambient RNA and quality-control loss; whether the frequency is the same in every sample; cells loaded against cells recovered; Abrams et al. 2019, which the source cites for the model and which does not print it; any measured comparison of recovered against expected cells.

No independent scientist has yet reviewed this.

### Changes to its methods

0 changes

No change is logged for these method versions.
