summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Simianer <p@simianer.de>2015-12-19 00:42:53 +0100
committerPatrick Simianer <p@simianer.de>2015-12-19 00:42:53 +0100
commitcbdc1b76b2a64dd0f70c54a55ca24cfd0ff431e7 (patch)
tree42e4b4d0070315c9c395de15fb991fa3974bc00d
parent5c2833c505dda0d1646b8f8c1e62abd391f0401e (diff)
corrected stddev
-rwxr-xr-xstddev8
1 files changed, 7 insertions, 1 deletions
diff --git a/stddev b/stddev
index 2634f63..6a29e74 100755
--- a/stddev
+++ b/stddev
@@ -5,6 +5,7 @@ require 'trollop'
conf = Trollop::options do
banner "stddev [-r <d>] < <one number per line>"
opt :round, "Number of digits after decimal point.", :type => :int, :default => -1
+ opt :corrected, "corrected stddev", :type => :bool, :default => false
end
sum = 0.0
@@ -24,7 +25,12 @@ cached.each { |v|
var += (avg - v)**2
}
-stddev = Math.sqrt(var/i.to_f)
+stddev = 0
+if conf[:corrected]
+ stddev = Math.sqrt(var/(i.to_f-1))
+else
+ stddev = Math.sqrt(var/i.to_f)
+end
if conf[:round] >= 0
puts stddev.round conf[:round]