From cbdc1b76b2a64dd0f70c54a55ca24cfd0ff431e7 Mon Sep 17 00:00:00 2001
From: Patrick Simianer
Date: Sat, 19 Dec 2015 00:42:53 +0100
Subject: corrected stddev
---
stddev | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
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 ] < "
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]
--
cgit v1.2.3