thirtysixthspan / descriptive_statistics

MIT License
755 stars 69 forks source link

Variance & STDEV => population not sample #11

Closed markjrussell closed 11 years ago

markjrussell commented 11 years ago

The variance & standard deviation methods return the population var/st. deviation, not the sample method which is usually what one would want and what users would be likely to expect.

variance.rb ought to read:

module DescriptiveStatistics
  def variance
    mean = self.mean
    self.map{ |sample| (mean - sample) ** 2 }.inject(:+) / (self.number - 1)
  end
end

I've submitted a pull request for this change

thirtysixthspan commented 11 years ago

Thanks! However, this is a gem for descriptive statistics not inferential statistics. Thus, we provide the standard deviation of the data provided (i.e., the population). If you think this needs clarification in the docs, that would be welcome!