Module: Enumerable
- Defined in:
- lib/enumerableext.rb
Instance Method Summary collapse
- #kurtosis ⇒ Object
- #mean ⇒ Object
- #popstddev ⇒ Object
- #popvariance ⇒ Object
- #skew ⇒ Object
- #std ⇒ Object
- #stddev ⇒ Object
- #sum ⇒ Object
- #variance ⇒ Object
Instance Method Details
#kurtosis ⇒ Object
33 34 35 36 37 |
# File 'lib/enumerableext.rb', line 33 def kurtosis fourthsum = self.inject(0){|acc, i| acc + (i - self.mean)**4} fourthmoment = fourthsum/self.length.to_f return (fourthmoment / (self.popvariance)**2) end |
#mean ⇒ Object
6 7 8 |
# File 'lib/enumerableext.rb', line 6 def mean return self.sum/self.length.to_f end |
#popstddev ⇒ Object
19 20 21 |
# File 'lib/enumerableext.rb', line 19 def popstddev return Math.sqrt(self.popvariance) end |
#popvariance ⇒ Object
15 16 17 |
# File 'lib/enumerableext.rb', line 15 def popvariance return self.variance*((self.length.to_f-1.0)/self.length.to_f) end |
#skew ⇒ Object
27 28 29 30 31 |
# File 'lib/enumerableext.rb', line 27 def skew thirdsum = self.inject(0){|acc, i| acc + (i - self.mean)**3} thirdmoment = thirdsum/self.length.to_f return thirdmoment / (self.popvariance)**(3.0/2.0) end |
#std ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/enumerableext.rb', line 39 def std result = [] (0..self.length-1).each do |i| result[i] = (self[i] - self.mean)/self.stddev end return result end |
#stddev ⇒ Object
23 24 25 |
# File 'lib/enumerableext.rb', line 23 def stddev return Math.sqrt(self.variance) end |
#sum ⇒ Object
2 3 4 |
# File 'lib/enumerableext.rb', line 2 def sum return self.inject(0){|acc, i| acc+i} end |
#variance ⇒ Object
10 11 12 13 |
# File 'lib/enumerableext.rb', line 10 def variance varsum = self.inject(0){|acc, i| acc + (i - self.mean)**2} return(varsum/(self.length.to_f-1.0)) end |