Module: Enumerable
- Defined in:
- lib/terragona/stats.rb
Overview
Instance Method Summary collapse
Instance Method Details
#mean ⇒ Object
10 11 12 13 |
# File 'lib/terragona/stats.rb', line 10 def mean return if self.empty? return self.sum / self.length.to_f end |
#sample_variance ⇒ Object
15 16 17 18 19 |
# File 'lib/terragona/stats.rb', line 15 def sample_variance m = self.mean sum = self.inject(0){|accum, i| accum + (i - m) ** 2 } return sum / (self.length - 1).to_f end |
#standard_deviation ⇒ Object
21 22 23 |
# File 'lib/terragona/stats.rb', line 21 def standard_deviation return Math.sqrt(self.sample_variance) end |
#sum ⇒ Object
6 7 8 |
# File 'lib/terragona/stats.rb', line 6 def sum return self.inject(0){|accum, i| accum + i } end |