Cumulative statistics. Start from zero and add samples or start with existing values and add more samples. Calculates mean, standard deviation, and other values.
The Python version is mentioned in the PeepCode Play by Play with Zed Shaw.
Start from scratch:
stats = new Stats()
stats.sample(42)
stats.sample(21)
console.log(stats.mean) // Average
Start from existing:
stats = new Stats(4, 16, 1, 4, 4)
stats.sample(18)
console.log(stats.sd) // Standard deviation
Combine statistics with an existing record:
stats = new Stats(4, 16, 1, 4, 4)
stats.combine(otherStatsRecord)
console.log(stats.n) // Number of samples
sum
- Total of all samples recordedsumsq
- Cumulative sum of squares of all samplesn
- Number of samplesmin
- Smallest samplemax
- Largest samplesd
- Standard deviationmean
- Average
We're using it at PeepCode Screencasts to build an internal reporting system with CouchDB. We use this code in CouchDB reduce views to emit statistics for reports.
- Original Python version by Zed Shaw @zedshaw http://zedshaw.com
- Port to JavaScript and enhancements by Geoffrey Grosenbach @topfunky http://peepcode.com