Ravn::
EnumerableRefinements
module
Aggregate functions for Enumerables; adapted from:
Calculate the mean of the members of the collection.
def mean
return self.sum / self.length.to_f
end
Calculate the sample variance of the members of the collection.
def sample_variance
m = self.mean
sum = self.inject( 0 ) {|accum, i| accum + (i-m) ** 2 }
return sum / (self.length - 1).to_f
end
Calculate the deviation from the mean of the members of the collection.
def standard_deviation
return Math.sqrt( self.sample_variance )
end