To apply velotest, we assume to have a high-dimensional dataset of gene expression levels and velocity vectors (g, v) ∈ (G, V) and corresponding two-dimensional embeddings \((\hat{{{{\bf{g}}}}},\hat{{{{\bf{v}}}}})\in (\hat{{{{\bf{G}}}}},\hat{{{{\bf{V}}}}})\). More specifically, \(\hat{{{{\bf{v}}}}}\) defines the vector pointing from \(\hat{{{{\bf{g}}}}}\) to \(\hat{{{{\bf{g}}}}}+\hat{{{{\bf{v}}}}}\).

Testing procedure

To assess the quality of an embedded velocities \(\hat{{{{\bf{v}}}}}\) we quantify the velocity alignment using cosine similarity: First, we select neighbors of the cell in the direction of the velocity \(\hat{{{{\bf{v}}}}}\) in the two-dimensional embedding space. Then, we evaluate whether the high-dimensional velocity v also points to those cells in the high-dimensional space using cosine similarity (Fig. 1a). The test statistic for \(\hat{{{{\bf{v}}}}}\) is then defined as the mean cosine similarity over all selected cells in the two-dimensional embedding space. We calculate this test statistic using all possible velocity vectors under H0 that are visually distinct from the embedded velocity (Supplementary Fig. 2). To establish a notion of ‘visual distinction’, we introduce an exclusion angle γ which limits alternative velocities to be at least γ degree distinct from the embedded velocity \(\hat{{{{\bf{v}}}}}\) (see Connection between significance level α and exclusion angle γ and Choice of hyperparameters for a discussion). We conduct the test by calculating a p value based on the test distribution under the null hypothesis for each cell individually, and correct via Bonferroni correction for multiple testing.

Since this testing procedure is based on an underlying fixed gene expression embedding and does not make any claims about it, we recommend a two-step approach if the validity of this gene expression embedding is additionally in question: first, assess the gene expression embedding quality independently, and only then apply velotest to evaluate the velocity projection. Detecting poor gene embeddings is a separate problem that requires dedicated tools (See e.g., ref. 25 and references therein).

Test statistic

To compute the test statistic, we first identify the k-nearest neighbors \({{{\rm{NN}}}}(\hat{{{{\bf{g}}}}})\) in the two-dimensional space for every datapoint \(\hat{{{{\bf{g}}}}}\) (default value k = 200, Supplementary Fig. 4, see Choice of hyperparameters for a discussion and cell-specific choices for k). The test statistic T for a single datapoint \((\hat{{{{\bf{g}}}}},\hat{{{{\bf{v}}}}})\) is then defined as

$${T}_{\hat{{{{\bf{g}}}}}}(\hat{{{{\bf{v}}}}})=\dfrac{1}{\#{{{\rm{N{N}}}}}_{\hat{g}}(\hat{{{{\bf{v}}}}})}{\sum}_{{{{\bf{h}}}}\in {{{\rm{N{N}}}}}_{\hat{g}}(\hat{{{{\bf{v}}}}})}{{{\rm{d}}}}_{\cos} ({{{\bf{v}}}},{{{\bf{h}}}} – {{{\bf{g}}}}),$$

(1)

where \({{{\rm{N{N}}}}}_{\hat{g}}(\hat{{{{\bf{v}}}}})\) is a subset of \({{{\rm{NN}}}}(\hat{{{{\bf{g}}}}})\) which includes all gene expression embeddings which are within a 2β cone (with β being the neighborhood angle, Fig. 1a) of the visualized velocity \(\hat{{{{\bf{v}}}}}\). The cosine similarity dcos is then calculated in the original, high-dimensional space. We take the preimage v of the visualized velocity \(\hat{{{{\bf{v}}}}}\) and the preimages g and h of the embedded gene expression levels and calculate \({{\mbox{d}}}_{{{{\rm{cos}}}}}({{{\bf{v}}}},{{{\bf{h}}}} – {{{\bf{g}}}})=\frac{{{{\bf{v}}}}\times ({{{\bf{h}}}} – {{{\bf{g}}}})}{\parallel {{{\bf{v}}}}\parallel \parallel {{{\bf{h}}}} – {{{\bf{g}}}}\parallel }\). This statistic assesses whether the high-dimensional velocity v points in the direction of the preimage of the selected nearest neighbors \({{{\rm{N{N}}}}}_{\hat{g}}(\hat{{{{\bf{v}}}}})\).

As the distribution of this test statistic under the null hypothesis H0 does not have a closed form and will differ between cells, we infer the null distribution by evaluating the test statistic for alternative velocity embeddings \({\hat{{{{\bf{v}}}}}}_{a}\) from the unit circle that are at least distinct from the visualized velocity by an angle of γ (see Supplementary Fig. 6 for different choices of γ). To get \({\hat{{{{\bf{v}}}}}}_{a}\), we first sample an angle θ ∈ [γ, 360∘ − γ) and convert it to its cartesian representation \({\hat{{{{\bf{v}}}}}}_{a}={{{\bf{s}}}}(\theta )\).

As we have a finite neighborhood \(\,{\mbox{NN}}\,(\hat{{{{\bf{g}}}}})\), the test statistic \({T}_{\hat{{{{\bf{g}}}}}}\) can only take finitely many values and we can get the full mapping \({T}_{\hat{{{{\bf{g}}}}}}:({0}^{\circ },36{0}^{\circ })\to ( – 1,1)\), \(\theta \,\mapsto {T}_{\hat{{{{\bf{g}}}}}}({{{\bf{s}}}}(\theta ))\), in which we assume without loss of generality that \(\hat{{{{\bf{v}}}}}\) corresponds to an angle of 0∘ (Supplementary Fig. 2).

With this mapping, we can calculate the p value using the observed statistic \({T}_{\hat{{{{\bf{g}}}}}}(\hat{{{{\bf{v}}}}})\) as

$$p=p\left({T}_{\hat{{{{\bf{g}}}}}}\ge {T}_{\hat{{{{\bf{g}}}}}}(\hat{{{{\bf{v}}}}})| {H}_{0}\right)=\dfrac{1}{\int_{D}1d\theta }\int_{D}{{\mathbb{1}}}_{{T}_{\hat{{{{\bf{g}}}}}}({{{\bf{s}}}}(\theta ))\ge {T}_{\hat{{{{\bf{g}}}}}}(\hat{{{{\bf{v}}}}})}d\theta,$$

(2)

where the integration domain D ⊆ [γ, 360∘ − γ] includes all valid alternative angles that are visually distinct from the embedded velocity \(\hat{{{{\bf{v}}}}}\) (see Alg. 1 for the complete testing procedure).

We perform this test for every cell in the dataset, typically in the order of thousands for scRNA-seq datasets. We therefore correct for multiple testing to avoid Type I errors (false positives). As the tests have a non-trivial dependence structure, we resort to correcting via the Bonferroni correction17 despite its conservatism, as it does not have any dependency assumptions (unlike the Benjamini–Hochberg procedure26). The generalized Benjamini–Yekutieli27 procedure, which controls FDR without any independence assumptions, yields results qualitatively comparable to Bonferroni (Supplementary Fig. 12). Having said that, even for non-corrected test results, the overall interpretation of well and poorly represented regions remains vastly the same (Supplementary Fig. 7), e.g., for the Pancreas dataset, the alpha and epsilon cluster are still not significant. We argue that conservatism is preferable here: since we care about the overall appearance of the embedding rather than individual cells, single false negatives are less consequential than false positives, which could mislead users into trusting regions that are in fact multiple-testing artifacts. The resulting stringent threshold may increase false negatives, which is precisely why we additionally propose the graphical diagnostic: a single, correction-free test of the entire embedding, at the cost of cluster-level resolution. The choice of correction, therefore, does not compromise the reliability of our results. The one caveat is that the absolute number of significant cells should not be interpreted in isolation, and only comparisons across embedding methods support valid conclusions.

Algorithm 1

Test for single cell (g, v) if its embedded velocity \(\hat{{{{\bf{v}}}}}\) is better than a randomly chosen velocity.

Isolated velocities

As our test statistic is based on neighboring cells that lie within a 2β cone, we cannot compute a test statistic for cells \((\hat{{{{\bf{g}}}}},\hat{{{{\bf{v}}}}})\) for which the cone neighborhood \({{{\rm{N{N}}}}}_{\hat{g}}(\hat{{{{\bf{v}}}}})\) is empty. We therefore exclude these cells from our test procedure, which typically leads to very few untested cells on the boundary of the visualized embeddings (Supplementary Fig. 8).

Similarly, we exclude velocities from D that have empty neighborhoods from the computation of the p value, and the integration domain D becomes finally \(D=\{\theta \in [\gamma,36{0}^{\circ } – \gamma ]\,|\, N{N}_{\hat{g}}({{{\bf{s}}}}(\theta ))\ne {{\emptyset}}\}\). We thereby limit the number of alternative hypotheses tested, which reduces the statistical power of the test for those cells. This reduction of the domain is especially prominent for embeddings that have thin structures, like the developing neutrophil cluster in the Covid dataset (Fig. 1e). For such structures, the support of the null distribution is reduced as alternative velocities need non-empty cone neighborhoods (see Supplementary Fig. 13). Note that a single neighboring cell within the 2β = 45∘ cone is sufficient to define the test statistic. In the most extreme case (e.g., Supplementary Fig. 13a), the test essentially evaluates whether a velocity vector is better aligned to one or the opposite direction.

However, e.g., for the vast majority of cells in the developing neutrophil cluster, the domain of the test statistic covers a large portion of the unit circle. We therefore do not consider this a critical limitation for interpretation. Even in thin structures, neighboring cells exist in multiple directions, each serving as a valid alternative hypothesis. Moreover, the gene expression embedding places cells in thin structures precisely because all surrounding clusters are highly distinct. Evaluating a velocity direction pointing towards these distant clusters is not meaningful, and the fact that the test domain naturally excludes such directions is arguably a desirable property of the test statistic.

Connection between significance level α and exclusion angle γ

Using the exclusion angle γ to limit the evaluation domain of the test statistic \({T}_{\hat{{{{\bf{g}}}}}}({\hat{{{{\bf{v}}}}}}_{a})\) has an effect on the significance level α for our testing procedure (regardless of the correction for multiple testing). Considering a significance level α, α × 100% of the overall velocities are allowed to have a higher test statistic than the observed statistic. On the other hand, for an exclusion angle γ, we additionally allow alternative velocities in a cone of 2γ, which are up to \(\left(\frac{2\gamma }{36{0}^{\circ }}\right)\times 100\%\) of the overall velocities, to have a higher test statistic than the observed statistic. With both significance level α and exclusion angle γ in play, we have up to a combined \((\alpha+\frac{2\gamma }{36{0}^{\circ }})\times 100\%\) effective samples of the overall velocities. Obtaining this amount of effective samples is equivalent to considering an effective significance level of up to \({\alpha }^{*}=(\alpha+\frac{2\gamma }{36{0}^{\circ }})\) for the decision criteria on our testing procedure. Thus, the empirical relation between a chosen significance level α and exclusion angle γ effectively imposes an updated significance level α* for our tests. However, if all alternative velocities do not produce a higher test statistic, the effective significance level is not increased as much, and under the specific case where none of the test statistics for the alternative velocities in the exclusion cone are higher than the observed statistic, the effective significance level stays at α* = α.

Judging the overall embedding instead of individual velocity vectors

Multiple testing procedures require correction methods to adjust significance levels for sequential tests. This directly affects the decision criteria of rejecting the null hypothesis based on the resulting p values. While multiple testing is necessary to answer questions regarding the statistical significance of observed velocities at the single-cell level, we provide an alternative graphical diagnostic to tackle inference for the observed velocities for the overall data.

We consider the p values computed based on the test statistic \({T}_{\hat{{{{\bf{g}}}}}}(\hat{{{{\bf{v}}}}})\) such that \({p}_{\hat{g}}\) is the p value for the cell associated with \(\hat{{{{\bf{g}}}}}\). We further consider \({p}_{\hat{g}}\) to be realizations of the random variable P associated with the p values. The random variable P is therefore uniformly distributed under the null hypothesis, \(P \sim {{{\mathcal{U}}}}(0,1)\) (see ref. 28 for more details). This follows from the p values being a function of the test statistic T such that P = FT (T). Then, the cumulative distribution function (CDF) of P can be derived using the probability integral transform of the test statistic T under the null such that FP(p) = p. This is the CDF of a continuous uniform distribution over the interval [0, 1].

Thus, by plotting the histogram of samples \({p}_{\hat{g}}\), we can graphically identify deviations from uniformity as evidence in favor of rejecting the null hypothesis. For the visualization, we allocate the p value samples to histogram bins. This allocation follows a binomial distribution based on the number of p value samples and the proportion of allocating a p value to a bin. We use Freedman–Diaconis rule29 to choose the number of bins and construct a 95% confidence band based on the resulting binomial distribution. Any deviations outside of this confidence region are directly attributed to evidence against the null distribution. For a specific dataset, we interpret the non-uniformity as evidence against the visualized velocity being a random velocity embedding. Based on our experiments, the graphical diagnostic suggests strong evidence against the visualized velocity being just a random velocity embedding (through departure from uniformity) for the pancreatic endocrinogenesis dataset using the dynamic model (see Fig. 1c). On the other hand, we lack sufficient evidence to make the same statement with a similar level of confidence regarding the velocity embedding of the SARS-CoV-2 data3 (Fig. 1e).

Test-optimal velocities

Using the above-defined test statistic \({T}_{\hat{{{{\bf{g}}}}}}({\hat{{{{\bf{v}}}}}}_{a})\) for alternative velocities, we can search for velocities that preserve the information of the high-dimensional velocity v as much as possible. To this end, we solve

$${\hat{{{{\bf{v}}}}}}_{\hat{g}}^{*}={\arg \max }_{\theta }{T}_{\hat{{{{\bf{g}}}}}}({{{\bf{s}}}}(\theta ))$$

to find the velocity embedding which would maximize the test statistic given gene expression embeddings \(\hat{{{{\bf{G}}}}}\). While this alternative velocity embedding is optimal under the given gene expression embedding and test statistic, we want to emphasize that the preserved information of the high-dimensional velocity might still be limited. This is indicated by a test statistic that is close to 0 (or negative), representing that on average the high-dimensional velocity v is perpendicular (or pointing into an opposite direction) to the preimages of the cells in the 2β cone and their corresponding high-dimensional vector h − g (Supplementary Fig. 3). This can either stem from the underlying gene expression embedding or the data itself.

Choice of hyperparameters

The results of velotest rely essentially on three hyperparameters: the neighborhood size k, the neighborhood angle β, and the exclusion angle γ. Their influence and optimal choice are dependent on the data as well as the embedding structure.

We recommend choosing the neighborhood size k as big as possible without spanning unconnected areas on the embedding (see Supplementary Fig. 4b, c for k = 200). By spanning unconnected regions, the test statistics for alternative embedding vectors can be unreliable, as commonly used embedding procedures for scRNA-seq (e.g., t-SNE) preserve local structures but less of the global arrangement25. For the presented datasets, we chose a default value of k = 200, reduced it to 100 for the dentate gyrus and mouse organogenesis datasets (Supplementary Fig. 4b, c), and increased it to 300 for the gastrulation erythroid dataset after visual inspection. For the datasets in Fig. 1, the test is robust to the choice of k and the interpretation remains consistent across k = 50 to k = 500 (Supplementary Fig. 5). Choosing low values (k = 50) results in slightly fewer significant cells and marginal changes in the distribution (e.g., Supplementary Fig. 5a, b).

In addition, we investigated an automated procedure to choose k for each cell individually. The motivation is that no single choice of k necessarily suits all cells in a dataset equally well: some cells have a surrounding structure that only permits a small k, while others allow a larger one. Since manually choosing k for every cell is impractical in datasets of thousands of cells, this automated procedure offers a convenient way to simplify an initial investigation, avoiding the need to set a dataset-wide k by hand. We show in Supplementary Fig. 10 that it yields the same conclusions for the datasets presented in Fig. 1. Once the analysis moves beyond this initial stage, we advise always inspecting the automatically chosen k, which can be done by visualizing the resulting neighborhoods as in Supplementary Fig. 11.

The automated procedure chooses k by detecting the first jump in the distances between newly added cells and the growing neighborhood (Alg. 2). Specifically, starting from cell i, we iteratively expand a neighborhood set and record the minimum squared Euclidean distance \({\delta }_{t}^{(i)}\) from the t-th nearest neighbor to the already-selected set (Alg. 2, INCREMENTALDIST). We then standardize this sequence per cell and select ki as the index of the first entry exceeding σthr = 4 standard deviations above the cell’s mean, corresponding to an abrupt jump to a structurally disconnected region (Supplementary Fig. 11). If no such jump is found, \({k}_{\max }\) is used; a floor of \({k}_{\min }\) guards against very sparse local neighborhoods. We set \({k}_{\min }=20\) and \({k}_{\max }=500\) as meaningful default values.

Algorithm 2

Automated per-cell selection of neighborhood size k.

The two angular parameters β and γ are dependent on the visual interpretation: the neighborhood angle β defines which gene embeddings are accepted to be in a similar direction as the visualized velocity \(\hat{{{{\bf{v}}}}}\). We chose β = 22.5∘ as a default value, and therefore interpret all gene embeddings within the 2β = 45∘ cone to be aligned with \(\hat{{{{\bf{v}}}}}\). Choosing too small values would lead to a test statistic that is very sensitive to the exact placement of the cell embeddings. On the contrary, choosing too large values would violate the notion that those neighbors lie in the direction of the velocity vector. We found robust results within a reasonable range of β = 5∘ to β = 30∘ (Supplementary Fig. 9).

The exclusion angle γ has a stronger influence on the test results (Supplementary Fig. 6), and its choice is grounded in the question of what angular difference a human observer can reliably perceive in a velocity vector field. Psychophysical studies show that human orientation discrimination thresholds can be below 1∘ under optimal conditions for isolated, high-contrast stimuli30. However, thresholds increase for short lines due to reduced spatial integration, and are further elevated in cluttered displays where “crowding” limits access to individual features31,32. For vector elements of only a few millimeters embedded in a dense vector field, effective perceptual thresholds are therefore expected to lie in the range of several degrees.

We accordingly recommend not choosing γ larger than 10∘: the exclusion cone should remove only those alternative directions that are visually indistinguishable from the embedded velocity, and not more. This is also consistent with how the visualization is interpreted: especially for stream plots (e.g., Fig. 1b, first row), but even for grid plots (e.g., Fig. 1b, last row), multiple velocity vectors are summarized, and one is often interested in the overall direction of the trajectory rather than the exact angle of one specific cell. To discourage misuse, our implementation raises a warning if the user sets γ above this threshold, as larger values increase the number of significant vectors under a modified null hypothesis. We name the test velotestγ based on the used exclusion angle γ to make clear how strict the applied test was, e.g., velotest10 for γ = 10∘. Despite the influence of this hyperparameter, we see similar patterns for a broad range of exclusion angles γ (Supplementary Fig. 6). For example, even for very large exclusion angles, the alpha and epsilon clusters in the pancreas dataset do not show good embedding qualities for the stochastic velocity model, similarly for the bone marrow dataset. If some or all of the test statistics for the velocities in the exclusion angle are larger than the observed test statistic (Supplementary Fig. 2a), the p value would increase if the exclusion cone were not to be used; but those alternative velocities are, in fact, visually hard to distinguish from the embedded velocity. For many cells, however, the statistics in the exclusion angle lie on both sides of the observed test statistic, and these cells would become significant only for very large exclusion angles (Supplementary Figs. 2b, d and 6).

Runtime of velotest

The runtime of velotest is mainly dependent on the number of datapoints in the dataset. For the investigated datasets, we find reasonable runtimes of velotest10 below 1 min up to 2 min on an M1 Pro MacBook and 32 GB memory, based on 300 neighbors and β = 22. 5° (Table 1).

Table 1 Dataset sizes and runtimes of velotest

Reporting summary

Further information on research design is available in the Nature Portfolio Reporting Summary linked to this article.