npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

online-stats

v1.5.0

Published

Online algorithms for data exploration and analysis (piece-by-piece)

Downloads

740

Readme

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 mean
const 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.Mean()

mean(1) // -> 1
mean(2) // -> 1.5
mean(9) // -> 4

console.log(mean()) // -> 4

Variance

const v = Stats.Variance({ddof: 1}) // 0 (default) - population variance, 1 - sample variance

v(1) // -> 0
v(2) // -> 0.5
v(9) // -> 19

console.log(v()) // -> 19

Median

const median = Stats.Median()

median(1) // -> 1
median(2) // -> 1.5
median(9) // -> 2

console.log(median()) // -> 2

Min

const min = Stats.Min()

min(2) // -> 2
min(6) // -> 2
min(1) // -> 1

console.log(min()) // -> 1

Max

const max = Stats.Max()

max(2) // -> 2
max(6) // -> 6
max(1) // -> 6

console.log(max()) // -> 6

Standard Deviation

const std = Stats.Std({ddof: 1}) // 0 (default) - population std, 1 - sample std (unbiased)

std(1) // -> 0
std(2) // ~> 0.7071
std(9) // ~> 4.3589

console.log(std()) // ~> 4.3589

Covariance

const a = [1, 3, 2, 5, 8, 7, 12, 2, 4]
const b = [8, 6, 9, 4, 3, 3, 2, 7, 7]
const cov = Stats.Covariance({ddof: 1})

a.forEach((ax, i) => { cov(ax, b[i]) })
console.log(cov()) // -> -8.069

Histogram

const hist = Stats.Histogram(20)

hist(2)
hist(6)
hist(1)

console.log(hist())

Autocovariance

const autocov = Stats.AutoCov(5)

;[1, 2, 3, 4, 5, 6, 7].forEach(v => { autocov(v) })

console.log(autocov())

Autocorrelation

const autocor = Stats.AutoCor(5)

;[1, 2, 3, 4, 5, 6, 7].forEach(v => { autocor(v) })

console.log(autocor())

Linear regression

const lr = Stats.LinReg()

const f = x => 0.5 * x + 2
;[1, 2, 3, 4, 5, 6].forEach(v => { lr(v, f(v)) })

console.log(lr([7])) // Predict