I have the following array [123, 350, 3456, 98]
and I need to remove items out of standard deviation, such as 3456 . I already have the standard deviation calculation as below:
class Array
def average
return 0 unless self.size > 0
self.sum / self.size
end
def deviation
average = self.average
sum = 0
self.map { |ar| sum += ar - average }
variance = sum / (self.size - 1)
Math.sqrt(variance)
end
end
And to get the deviation just run: [123, 350, 3456, 98].deviation # => 1.0
But now I'm not sure how this might help me in removing 3456 .