function corr(x, y) {
const n = x.length;
if (y.length !== n)
throw new Error("The two columns must have the same length.");
const x_ = d3.mean(x);
const y_ = d3.mean(y);
const XY = d3.sum(x, (_, i) => (x[i] - x_) * (y[i] - y_));
const XX = d3.sum(x, (d) => (d - x_) ** 2);
const YY = d3.sum(y, (d) => (d - y_) ** 2);
return XY / Math.sqrt(XX * YY);
}