online-stats
Collection of online algorithms for data exploration and analysis. Online algorithms process inputs piece by piece. That means you can process data without storing it in memory. More about online algorithms
Most algorithms of online-stats
also support more usual batch mode (i.e. mean([1,2,3,4])
)
Installation
npm i -S online-stats
Usage
const Stats = require('online-stats') // { Mean, Median, Max, Min, ... }
To process data sequentially we need functions to have internal state. That's why there's one extra step - functions initialization
const mean = Stats.Mean() // -> function meanconst median = Stats.Median() // -> function median...
When functions are initialized, just call them passing a value (for example: mean(x)
).
Result is returned. To get a final result just call a function without any params: const result = mean()
Mean
const mean = Stats // -> 1 // -> 1.5 // -> 4 console // -> 4
Variance
const v = Stats // 0 (default) - population variance, 1 - sample variance // -> 0 // -> 0.5 // -> 19 console // -> 19
Median
const median = Stats // -> 1 // -> 1.5 // -> 2 console // -> 2
Min
const min = Stats // -> 2 // -> 2 // -> 1 console // -> 1
Max
const max = Stats // -> 2 // -> 6 // -> 6 console // -> 6
Standard Deviation
const std = Stats // 0 (default) - population std, 1 - sample std (unbiased) // -> 0 // ~> 0.7071 // ~> 4.3589 console // ~> 4.3589
Covariance
const a = 1 3 2 5 8 7 12 2 4const b = 8 6 9 4 3 3 2 7 7const cov = Stats aconsole // -> -8.069
Histogram
const hist = Stats console
Autocovariance
const autocov = Stats ;1 2 3 4 5 6 7 console
Autocorrelation
const autocor = Stats ;1 2 3 4 5 6 7 console
Linear regression
const lr = Stats const f = 05 * x + 2;1 2 3 4 5 6 console // Predict