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.
35 lines (31 loc) • 1.32 kB
JavaScript
const Table = require('./table/index')
const range = require('./utils/range')
const newColumn = require('./utils/new-column')
class Statistics {
static range = range
static statistics = new Statistics('default-statistics')
static newTable(data) { return new Table(data) }
static newColumn(values) { return newColumn(values) }
constructor() {
this.tables = {}
}
addTable(name,obj) { this.tables[name] = new Table(obj); return this.tables[name] }
filterRows(indexes) { for (let n in this.tables) { this.tables[n].filterRows(indexes) }; return this }
clearRowsFilters(indexes) { for (let n in this.tables) { this.tables[n].clearRowsFilters(indexes) }; return this }
clearAllRowsFilters() { for (let n in this.tables) { this.tables[n].clearAllRowsFilters() }; return this }
descriptive(metricName) {
const newTable = new Table()
Object.entries(this.tables).forEach(([name,table]) => {
newTable.addColumn(name,table.descriptive(metricName,newTable))
})
return newTable
}
transpose() {
const newStatistics = new Statistics()
for (let n in this.tables) {
newStatistics.tables[n+'_transposed'] = this.tables[n].transpose(n)
}
return newStatistics
}
}
module.exports = Statistics