Sha256: f9452f693d5d113acbeb4830f0e5e3e34bbe339ab029f7764187b7a80c2b9cc9

Contents?: true

Size: 622 Bytes

Versions: 11

Compression:

Stored size: 622 Bytes

Contents

module Metricize
  module Stats

    def sum
      return self.inject(0){|accum, i| accum + i }
    end

    def mean
      return self.sum / self.length.to_f
    end

    def sample_variance
      m = self.mean
      sum = self.inject(0){|accum, i| accum + (i - m) ** 2 }
      return sum / (self.length - 1).to_f
    end

    def standard_deviation
      return Math.sqrt(self.sample_variance)
    end

    def calculate_percentile(percentile)
      return self.first if self.size == 1
      values_sorted = self.sort
      k = (percentile*(values_sorted.length-1)+1).floor - 1
      values_sorted[k]
    end

  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
metricize-0.5.7 lib/metricize/stats.rb
metricize-0.5.6 lib/metricize/stats.rb
metricize-0.5.4 lib/metricize/stats.rb
metricize-0.5.3 lib/metricize/stats.rb
metricize-0.5.2 lib/metricize/stats.rb
metricize-0.5.1 lib/metricize/stats.rb
metricize-0.5.0 lib/metricize/stats.rb
metricize-0.4.7 lib/metricize/stats.rb
metricize-0.4.6 lib/metricize/stats.rb
metricize-0.4.5 lib/metricize/stats.rb
metricize-0.4.4 lib/metricize/stats.rb