Skip to content

spearmanRho

function spearmanRho(
hdIn,
ldIn,
opts?): MetricResult;

Defined in: metrics/correlation.ts:97

Rank correlation between original and projected distances — Shepard goodness.

Asks only whether distances kept their order, so a projection that stretches distances non-linearly but consistently still scores 1. That makes it a fairer global measure than stress for methods that deliberately warp scale.

  • Needs: high-dimensional data and projection. No labels.
  • Range: [-1, 1], higher is better.
  • Cost: O(N² log N) time and O(N²) memory — it ranks every pair, so unlike most measures here it materialises them. maxPairs guards the allocation.
ParameterType
hdInPointsInput
ldInPointsInput
optsSpearmanOptions

MetricResult

Shepard, Psychometrika 27 (1962) https://doi.org/10.1007/BF02289630

import { spearmanRho } from "@saehrimnir/sickle";
// Takes the points directly — it needs every pair ranked, so it does not read
// off `analyze` and it materialises the full N×N matrix.
spearmanRho(data, projection).value; // 0.988
// Guarded by `maxPairs` (default 60e6, counting n²), so it refuses past
// n ≈ 7 745 rather than attempting the allocation.
spearmanRho(data, projection, { maxPairs: 2e8 });