als-statistics
Version:
Modular JS statistics toolkit for Node.js and the browser: descriptive stats, correlations (Pearson/Spearman/Kendall), t-tests & ANOVA (Student/Welch), reliability (Cronbach’s alpha), regression (linear/logistic), clustering (DBSCAN/HDBSCAN), and table/co
57 lines (51 loc) • 1.84 kB
JavaScript
import Analyze from './analyze/index.js'
import { htmlTable, round, range } from './utils/index.js'
import Stats from './descriptive/index.js'
import Table from './table/index.js'
import Column from './column/index.js'
import { filterKeys } from './utils/filter-keys.js'
import { Counter } from './utils/counter.js'
class Statistics {
static counter = new Counter('statistics')
static tools = { range, round, htmlTable }
static Table = Table;
static Stats = Stats;
static Analyze = Analyze; // CDF, CompareMeans, Correlate, Clustering, Regression
static Column = Column;
constructor(name) {
this.name = Statistics.counter.getName(name);
this.tables = {}
}
get colNames() {
const colNames = new Set()
for (let tName in this.tables) {
this.tables[tName].colValues.forEach(({ name }) => { colNames.add(name) });
}
return Array.from(colNames)
}
columns(name, ...colFilter) {
const colNames = filterKeys(this.colNames, colFilter), columns = {};
for (let tName in this.tables) {
colNames.forEach(colName => {
const col = this.tables[tName].columns[colName];
const values = col && col.values;
if (values) columns[`${tName}_${colName}`] = values;
})
}
return new Table(columns, { name, alignColumns: false })
}
addTable(obj, options) {
const table = new Table(obj, options)
this.tables[table.name] = table;
return table
}
deleteTable(tableName) { delete this.tables[tableName] }
}
Table.Statistics = Statistics
export default Statistics
export { Analyze as Analyze }
export { htmlTable as htmlTable }
export { range as range }
export { round as round }
export { Stats as Stats }
export { Table as Table }