Module: Termplot::Widgets::Statistics
- Included in:
- Dataset
- Defined in:
- lib/termplot/widgets/statistics.rb
Instance Method Summary collapse
Instance Method Details
#count ⇒ Object
4 5 6 |
# File 'lib/termplot/widgets/statistics.rb', line 4 def count data.count end |
#mean ⇒ Object
8 9 10 11 |
# File 'lib/termplot/widgets/statistics.rb', line 8 def mean return 0 if data.empty? data.sum(0.0) / count end |
#standard_deviation ⇒ Object
13 14 15 16 17 18 |
# File 'lib/termplot/widgets/statistics.rb', line 13 def standard_deviation return 0 if data.empty? data_mean = mean variance = data.map { |x| (data_mean - x) ** 2 }.sum / count Math.sqrt(variance) end |