module SugarRefinery::ArrayStats
Public Instance Methods
mean()
click to toggle source
# File lib/sugar_refinery/array_stats.rb, line 6 def mean inject(&:+) / length.to_f end
stdev(type = :population)
click to toggle source
# File lib/sugar_refinery/array_stats.rb, line 10 def stdev(type = :population) case type when :population then stdev_population when :sample then stdev_sample else raise ArgumentError.new("%s is not a valid argument" % type) end end
stdev_population()
click to toggle source
# File lib/sugar_refinery/array_stats.rb, line 22 def stdev_population Math.sqrt(inject(0.0) { |sum, x| sum + (mean - x) ** 2 } / length) end
stdev_sample()
click to toggle source
# File lib/sugar_refinery/array_stats.rb, line 18 def stdev_sample Math.sqrt(inject(0.0) { |sum, x| sum + (mean - x) ** 2 } / (length - 1)) end
z_score(type = :population)
click to toggle source
# File lib/sugar_refinery/array_stats.rb, line 26 def z_score(type = :population) map { |x| (x - mean) / stdev(type) } end