Module: DescriptiveStatistics::Spread
- Included in:
- AllMethods
- Defined in:
- lib/descriptive-statistics/spread.rb
Instance Method Summary collapse
- #population_standard_deviation ⇒ Object
- #population_variance ⇒ Object
- #relative_standard_deviation ⇒ Object
- #standard_deviation ⇒ Object
- #variance ⇒ Object
- #zscore ⇒ Object
Instance Method Details
#population_standard_deviation ⇒ Object
28 29 30 31 |
# File 'lib/descriptive-statistics/spread.rb', line 28 def population_standard_deviation return if length < 1 Math.sqrt(population_variance) end |
#population_variance ⇒ Object
10 11 12 13 14 15 |
# File 'lib/descriptive-statistics/spread.rb', line 10 def population_variance return if length < 1 precalculated_mean = mean sum = self.inject(0) {|accumulator, value| accumulator + (value - precalculated_mean) ** 2 } sum / length.to_f end |
#relative_standard_deviation ⇒ Object
22 23 24 25 26 |
# File 'lib/descriptive-statistics/spread.rb', line 22 def relative_standard_deviation return if length < 1 precalculated_mean = mean (population_standard_deviation / precalculated_mean) * 100.0 end |
#standard_deviation ⇒ Object
17 18 19 20 |
# File 'lib/descriptive-statistics/spread.rb', line 17 def standard_deviation return if length < 2 Math.sqrt(variance) end |
#variance ⇒ Object
3 4 5 6 7 8 |
# File 'lib/descriptive-statistics/spread.rb', line 3 def variance return if length < 1 precalculated_mean = mean sum = self.inject(0) {|accumulator, value| accumulator + (value - precalculated_mean) ** 2 } sum / (length.to_f - 1) end |
#zscore ⇒ Object
33 34 35 36 37 38 |
# File 'lib/descriptive-statistics/spread.rb', line 33 def zscore return if length < 2 stdev = standard_deviation m = mean stdev.zero? ? Array.new(self.length, 0) : self.collect { |v| (v - m) / stdev } end |