Skip to content

nonMetricStress

function nonMetricStress(
hdIn,
ldIn,
opts?): NonMetricStressResult;

Defined in: metrics/nonmetric.ts:134

Stress measured against the best monotone fit rather than the raw distances.

Forgives any distortion that preserves the ordering of distances, penalising only departures from monotonicity. The most permissive member of the stress family: use it when only the ranking of distances is meant to be meaningful.

  • Needs: high-dimensional data and projection. No labels.
  • Range: [0, 1], lower is better; 0 means the projected distances are a monotone function of the originals. The bound holds because the all-zero curve is a feasible monotone fit scoring exactly 1, so the best fit cannot do worse.
  • Cost: O(N² log N) time and O(N²) memory — the pairs must be sorted, so unlike most measures here they are materialised. maxPairs guards the allocation.

disparities, sortedHigh and sortedLow give the fitted curve and the points it was fitted to, which plot directly as a Shepard diagram.

ParameterType
hdInPointsInput
ldInPointsInput
optsNonMetricStressOptions

NonMetricStressResult

Kruskal, Psychometrika 29 (1964) https://doi.org/10.1007/BF02289565

import { nonMetricStress } from "@saehrimnir/sickle";
const s = nonMetricStress(data, projection);
s.value; // 0.0311 — only departures from monotonicity are charged
// The fitted curve and the pairs it was fitted to plot as a Shepard diagram.
s.sortedHigh.length; // 19900 — n(n-1)/2 pairs
s.disparities[0]; // the monotone fit at the smallest original distance