Module: Enumerable

Defined in:
lib/enumerableext.rb

Instance Method Summary collapse

Instance Method Details

#kurtosisObject



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

#meanObject



6
7
8
# File 'lib/enumerableext.rb', line 6

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

#popstddevObject



19
20
21
# File 'lib/enumerableext.rb', line 19

def popstddev
     return Math.sqrt(self.popvariance)
end

#popvarianceObject



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

#skewObject



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

#stdObject



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

#stddevObject



23
24
25
# File 'lib/enumerableext.rb', line 23

def stddev
     return Math.sqrt(self.variance)
end

#sumObject



2
3
4
# File 'lib/enumerableext.rb', line 2

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

#varianceObject



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