spearmanCorrelation function

double spearmanCorrelation(
  1. List<double> x,
  2. List<double> y
)

Computes the Spearman rank correlation coefficient.

This is a non-parametric measure of correlation that assesses monotonic relationships.

Implementation

double spearmanCorrelation(List<double> x, List<double> y) {
  if (x.length != y.length) {
    throw ArgumentError('x and y must have the same length');
  }
  if (x.length < 2) {
    throw ArgumentError('At least 2 points are required');
  }

  // Convert to ranks
  final rankX = _rank(x);
  final rankY = _rank(y);

  return correlation(rankX, rankY);
}