diff options
author | Patrick Simianer <p@simianer.de> | 2015-12-19 00:42:53 +0100 |
---|---|---|
committer | Patrick Simianer <p@simianer.de> | 2015-12-19 00:42:53 +0100 |
commit | cbdc1b76b2a64dd0f70c54a55ca24cfd0ff431e7 (patch) | |
tree | 42e4b4d0070315c9c395de15fb991fa3974bc00d /stddev | |
parent | 5c2833c505dda0d1646b8f8c1e62abd391f0401e (diff) |
corrected stddev
Diffstat (limited to 'stddev')
-rwxr-xr-x | stddev | 8 |
1 files changed, 7 insertions, 1 deletions
@@ -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] |