UNPKG

als-statistics

Version:

A powerful and lightweight JavaScript library for descriptive statistics, regression, clustering, outlier detection, and noise analysis using a flexible table/column architecture.

18 lines (17 loc) 835 B
class Noice { constructor(sample) { this.sample = sample this.zThreshold = 2.5 + (0.5 * Math.abs(sample.skewness)); // Dynamic z threshold depends on skewness } get noiseByRelativeDispersion() { return this.sample.relativeDispersion < 1 } get noiseByCV() { return this.sample.cv < 1 } get noiseByIQR() { return this.sample.iqr < this.sample.stdDev } get noiseBySkewness() { return Math.abs(this.sample.skewness) < 1 } noiseByZ(min = 0.01) { const { zScores, zThreshold, n, relativeDispersion } = this.sample const outliersAbove = zScores.filter(z => z > zThreshold).length / n; const outliersBelow = zScores.filter(z => z < -zThreshold).length / n; return (outliersAbove + outliersBelow) < Math.min(min, min * relativeDispersion); } } module.exports = Noice