Created
March 11, 2014 14:32
-
-
Save derickson/9486939 to your computer and use it in GitHub Desktop.
standard deviation MongoDB aggregation pipline using method from http://en.wikipedia.org/wiki/Standard_deviation#Rapid_calculation_methods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// standard deviation MongoDB aggregation pipline | |
// using method from http://en.wikipedia.org/wiki/Standard_deviation#Rapid_calculation_methods | |
var parts = db.stat.aggregate( { $group: { _id: null, | |
s0: {$sum:1}, | |
s1:{$sum:"$stat"}, | |
s2:{$sum:{$multiply:["$stat","$stat"]}} }} ).result[0]; | |
var stddev = Math.sqrt( parts.s0 * parts.s2 - Math.pow( parts.s1, 2) ) / parts.s0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment