Tutorials › Statistical Methods for Single-Cell RNA Sequencing › Averaging MNN Correction Vectors

Integration Methods and Their Benchmarking · Tutorial 161 of 700

Averaging MNN Correction Vectors

See how MNN correction vectors are combined into a cell-level adjustment, and how weighting, sparse matches, and directional conflict can make that adjustment unstable.

Advanced 10 min read

What You'll Learn

  • Define a cell-level correction as a weighted average of nearby MNN correction vectors.
  • Choose and normalize local weights using a distance-based kernel.
  • Calculate weighted vector averages coordinate by coordinate.
  • Interpret the norm of an average when correction directions agree or conflict.
  • Recognize how sparse matches and bandwidth choices can destabilize corrections.
  • Compare weighted averaging with uniform averaging and using a single pair.

From MNN Pairs to a Cell-Level Correction

A mutual nearest-neighbor (MNN) pair supplies a cross-batch displacement in the selected feature space. But a cell may have several nearby MNN pairs, and their vectors need not be identical. Averaging them provides one local correction for that cell rather than letting any single pair determine the adjustment. The result depends both on the vectors and on how much influence each neighboring pair receives.

Suppose a cell \(i\) in a target batch has \(K_i\) neighboring MNN pairs. Write \(v_{ik}\) for the correction vector contributed by pair \(k\), oriented consistently as the adjustment to apply to cell \(i\). For example, if \(z_i\) is the target-side endpoint and \(z_{ik}^{*}\) is its paired cell in the other batch, a possible convention is \(v_{ik}=z_{ik}^{*}-z_i\). Reversing that convention reverses all corrections, so the direction must be stated and used consistently.

Definition: A cell-level weighted MNN correction is \(c_i=\sum_{k=1}^{K_i}w_{ik}v_{ik}\), where \(w_{ik}\geq 0\) and \(\sum_{k=1}^{K_i}w_{ik}=1\). The corrected coordinate is \(z_i+c_i\). The weights express the relative contribution of the neighboring pairs to this cell's adjustment.

The vectors must all be represented in the same feature space, with the same coordinate scaling and orientation. If the vectors have undergone cosine normalization, the average combines those normalized vectors; it does not recover their original lengths. If unnormalized vectors are used instead, their magnitudes also affect the average. These are different choices, and the averaging calculation should make clear which vectors enter it.

Choosing and Normalizing Local Weights

A simple scheme gives every neighboring pair equal weight. A local, distance-based scheme gives more weight to pairs whose target-side endpoints are closer to cell \(i\). Let \(r_{ik}\) be that distance in the chosen feature space, and let \(h>0\) be a bandwidth. One possible kernel weight is

$$ a_{ik}=\exp\left(-\frac{r_{ik}^{2}}{2h^{2}}\right), \qquad w_{ik}=\frac{a_{ik}}{\sum_{\ell=1}^{K_i}a_{i\ell}}. $$

Because each \(a_{ik}\) is positive, these weights are nonnegative and sum to one. The bandwidth controls how quickly influence falls with distance: a smaller \(h\) concentrates weight on the closest pairs, while a larger \(h\) makes weights more similar. This kernel is an example, not a universal requirement. The essential properties for a convex weighted average are nonnegative weights with a positive total, normalized to sum to one.

Local weighting relies on a substantive assumption: nearby MNN pairs are informative about the correction appropriate for cell \(i\). It also relies on the pairs being sufficiently comparable in the selected representation. If nearby pairs point in sharply different directions, their average may be small or may point in a direction that represents no individual pair well. Averaging cannot repair incorrect matches or establish that the batches share the same biological state.

Worked Example: Combining Three Correction Vectors

Suppose a hypothetical cell has three neighboring pair vectors, in arbitrary feature-space units, \(v_{i1}=(1,0)\), \(v_{i2}=(0.8,0.2)\), and \(v_{i3}=(-1,0)\). Let their already normalized weights be \(0.5741\), \(0.3482\), and \(0.0777\). The weights are valid because \(0.5741+0.3482+0.0777=1.0000\).

Compute the average coordinate by coordinate:

$$ \begin{aligned} c_i &=0.5741(1,0)+0.3482(0.8,0.2)+0.0777(-1,0)\\ &=(0.5741+0.27856-0.0777,\;0+0.06964+0)\\ &=(0.77496,\;0.06964)\approx(0.7750,\;0.0696). \end{aligned} $$

The first coordinate is positive because the two positive first-coordinate contributions outweigh the negative one. The second coordinate comes only from the second vector: \(0.3482\times0.2=0.06964\). The applied correction is therefore about \(0.7750\) units in the first coordinate and \(0.0696\) units in the second. This example uses the vectors as specified; if cosine normalization is applied first, the vectors entering the calculation, and thus the answer, will generally differ.

What the Average Means—and What It Can Hide

A weighted average is a compromise among its contributing vectors. Since the weights are nonnegative and sum to one, the result lies in their convex hull: it cannot be an extrapolation beyond every contributing vector in the sense of a convex combination. This does not mean it is necessarily a good correction. A compromise can be misleading when the contributing directions disagree.

A useful geometric summary is the norm \(\lVert c_i\rVert\). If all contributing vectors are unit length and point in nearly the same direction, their average has a norm near one. If they point in opposing directions, their contributions can cancel and the average norm can be small. That small norm may indicate directional disagreement; it does not, by itself, show that the cell needs little correction.

Justification: For normalized weights, the triangle inequality gives \(\lVert c_i\rVert=\lVert\sum_k w_{ik}v_{ik}\rVert\leq\sum_k w_{ik}\lVert v_{ik}\rVert\). Thus, if all input vectors have norm one, \(\lVert c_i\rVert\leq1\). Equality occurs when the positively weighted vectors point in the same direction. Opposing directions can reduce the norm through cancellation.

The average also has a precise optimization interpretation. It is the vector \(c\) that minimizes the weighted sum of squared distances from the contributing vectors. To see this, let \(F(c)=\sum_k w_{ik}\lVert v_{ik}-c\rVert^2\). Differentiating with respect to \(c\) gives \(\nabla F(c)=2(c-\sum_k w_{ik}v_{ik})\). Setting this gradient to zero yields \(c=\sum_k w_{ik}v_{ik}\). Since the Hessian is \(2I\), which is positive definite, this stationary point is the unique minimum.

Worked Example: Detecting Cancellation Among Directions

Consider three hypothetical unit correction vectors with weights \(0.45\), \(0.40\), and \(0.15\): \(v_{i1}=(1,0)\), \(v_{i2}=(-1,0)\), and \(v_{i3}=(0,1)\). The weights sum to one, and the vectors are all in the same two-dimensional space.

Their weighted average is

$$ c_i=0.45(1,0)+0.40(-1,0)+0.15(0,1) =(0.45-0.40,\;0.15)=(0.05,\;0.15). $$

Its norm is \(\lVert c_i\rVert=\sqrt{0.05^2+0.15^2}=\sqrt{0.025}\approx0.1581\). This is much smaller than the unit norms of the inputs. The small result occurs because the first two vectors nearly cancel; it should not be interpreted as evidence that all three pairs indicate a negligible adjustment. If the implementation applies this average directly, the net adjustment is small, but the low norm warns that the pairs disagree in direction.

Sparse Support and Weight Sensitivity

A cell supported by only a few pairs has little redundancy in its estimated local correction. With one pair, its weighted average is exactly that pair's vector, regardless of the weighting scheme. With two or three pairs, changing the neighborhood or bandwidth can substantially alter the result. In contrast, many nearby, directionally consistent pairs can make the average less sensitive to any one contribution, although a large count alone does not guarantee that the matches are appropriate.

Worked Example: A Bandwidth-Sensitive Correction

Suppose a hypothetical cell has just two neighboring pairs. Their distances from the cell are \(r_{i1}=0.2\) and \(r_{i2}=1.0\), and their correction vectors are \(v_{i1}=(1,0)\) and \(v_{i2}=(0,1)\). Use the Gaussian weights defined above.

With bandwidth \(h=1\), the unnormalized weights are \(a_{i1}=e^{-0.02}\approx0.9802\) and \(a_{i2}=e^{-0.5}\approx0.6065\). Their sum is \(1.5867\), so the normalized weights are approximately \(w_{i1}=0.6177\) and \(w_{i2}=0.3823\). Thus,

$$ c_i=0.6177(1,0)+0.3823(0,1)=(0.6177,\;0.3823). $$

Now reduce the bandwidth to \(h=0.5\). The unnormalized weights are \(e^{-0.08}\approx0.9231\) and \(e^{-2}\approx0.1353\), giving normalized weights of about \(0.8721\) and \(0.1279\). The correction becomes \(c_i=(0.8721,\;0.1279)\). The closer pair now dominates much more strongly. With only two orthogonal directions, the bandwidth choice materially changes the correction's direction and magnitude. This is a reason to examine sensitivity to reasonable neighborhood and bandwidth choices, rather than treating one setting as self-evidently stable.

Practical Checks and Alternatives

Before applying an averaged correction, check that the input vectors share a coordinate system and orientation, that the weights are nonnegative and sum to one, and that the calculation uses the intended raw or cosine-normalized vectors. A zero-length displacement cannot be cosine-normalized by division by its norm; it requires explicit handling rather than an undefined normalization. Check the number of contributing pairs and whether a small number of them carries nearly all the weight. Also inspect the average norm relative to the input norms: a very small norm alongside unit-length inputs can signal cancellation.

These checks are diagnostics, not proof of successful integration. A stable-looking average can still arise from systematically inappropriate matches, and an unstable average can reflect limited local support. Broader assessment of MNN match quality is a separate question. In particular, correcting coordinates cannot establish that biological differences between batches are absent or that a shared-state assumption is justified.

ApproachWhat it doesTrade-off
Uniform averageGives every neighboring pair equal weight.Simple, but a relatively distant pair has the same influence as a close one.
Distance-weighted averageGives closer pairs more influence through normalized local weights.Uses locality, but results depend on the distance definition and bandwidth.
Single-pair correctionUses one selected MNN vector for the cell.Avoids averaging disagreement but is highly dependent on that one pair.

Weighted averaging is therefore most interpretable when several relevant neighboring pairs provide reasonably consistent directions. It summarizes local evidence; it does not quantify uncertainty by itself, guarantee a smooth correction field, or replace checking the assumptions behind the MNN pairs.

Common pitfall: A learner sees a small averaged vector and concludes that the batch adjustment is negligible. That conclusion ignores possible cancellation. Compare the input directions and weights: a small average of large, opposing vectors can indicate disagreement rather than consensus on a small correction.

Check Your Understanding

Answer each question, then compare your reasoning with the solutions below.

  1. For vectors \((2,0)\) and \((0,2)\) with weights \(0.25\) and \(0.75\), calculate the weighted average.
  2. Why must weights be normalized to sum to one if the result is intended to be a weighted average?
  3. Three unit vectors point in the same direction and have normalized weights. What is the norm of their average? What changes if two point in opposite directions?
  4. A cell has one MNN pair. What does the weighted average equal, and what limitation follows?
  5. Why does changing the bandwidth have a larger potential effect when only two pairs contribute?

Solutions. (1) \(0.25(2,0)+0.75(0,2)=(0.5,1.5)\). (2) Normalization makes the result a convex combination, so the weights describe relative contributions rather than arbitrarily scaling the total vector; it also supports the usual interpretation of a weighted mean. (3) If each vector is the same unit vector, their average is that unit vector and has norm one. Opposing directions can cancel, reducing the norm. (4) The average equals the sole pair vector because its weight must be one. The cell has no other pair to provide redundancy or reveal disagreement. (5) With two pairs, changing the bandwidth can shift much of the total weight from one direction to the other, substantially changing the compromise vector.

Clinical Biostats