Skip to content

Incorrect quantile computation.  #72

@jerome-benoit

Description

@jerome-benoit

The implementation borrowed from mitata is incorrect and off by at least one for all quantiles.

Correct implementation:

const quantileSorted = (arr, q) => {
  const base = (arr.length - 1) * q;
  const baseIndex = Math.floor(base);
  if (arr[baseIndex + 1] != null) {
    return (
      arr[baseIndex] +
      (base - baseIndex) * (arr[baseIndex + 1] - arr[baseIndex])
    );
  }
  return arr[baseIndex];
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions