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
33 lines (30 loc) • 1.27 kB
JavaScript
import { IndependentTTest } from './independent-t-test.js'
import { OneWayAnova } from './one-way-anova.js'
import { PairedTTest } from './paired.js'
import { OneSampleTTest } from './one-sample.js'
const prepare = (keys, data) => {
if(keys.length === 0) return data
// TODO not tested
const samples = {};
keys.forEach(k => samples[k] = data[k])
return samples
}
export class CompareMeans {
static IndependentTTest = IndependentTTest;
static OneWayAnova = OneWayAnova;
static PairedTTest = PairedTTest;
static OneSampleTTest = OneSampleTTest;
constructor(data) {
this.data = data;
}
paired(...colNames) { return new PairedTTest(prepare(colNames, this.data)) }
independent(...colNames) { return new IndependentTTest(prepare(colNames, this.data), false) }
independentWelch(...colNames) { return new IndependentTTest(prepare(colNames, this.data), true) }
anova(...colNames) { return new OneWayAnova(prepare(colNames, this.data), false) }
anovaWelch(...colNames) { return new OneWayAnova(prepare(colNames, this.data), true) }
oneSample(colName, mu0) {
if(!colName) colName = Object.keys(this.data)[0]
const data = { [colName]: this.data[colName] }
return new OneSampleTTest(data, mu0)
}
}