Published
Edited
Jan 8, 2022
1 fork
5 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
chatterjee = (data, { x = (d) => d[0], y = (d) => d[1] } = {}) => {
// 0. Extract values
const X = d3.map(data, x);
const Y = d3.map(data, y);
const N = X.length;

// 1. rearrange along X
const I = d3.sort(d3.range(N), (i) => X[i]);

// 2. rank Y
const rank = d3.rank(Y);

// 3. compute ξ (simple formula with no ties)
return (
1 -
(3 / (N * N - 1)) *
d3.sum(d3.pairs(I), ([a, b]) => Math.abs(rank[a] - rank[b]))
);
}
Insert cell
data = Array.from({ length: N }, (_, i) => [
i / N + rnd(),
func(i / N, i) + rnd()
])
Insert cell
rnd = d3.randomNormal(0, noise / 2)
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more