class Benchmark::Experiment::DescriptiveStatistics
Attributes
first_quartile[R]
maximum[R]
median[R]
minimum[R]
name[R]
sample[R]
third_quartile[R]
Public Class Methods
new(sample, name = '')
click to toggle source
# File lib/benchmark/lab/descriptive_statistics.rb, line 4 def initialize(sample, name = '') # raise exception if empty sample @name = name @sample = sample.sort @minimum, @maximum = @sample.minmax @median = calculate_median_of(@sample) @first_quartile = calculate_first_quartile_of(@sample) @third_quartile = calculate_third_quartile_of(@sample) end
Public Instance Methods
interquartile_range()
click to toggle source
# File lib/benchmark/lab/descriptive_statistics.rb, line 20 def interquartile_range @third_quartile - @first_quartile end
sample_size()
click to toggle source
# File lib/benchmark/lab/descriptive_statistics.rb, line 16 def sample_size sample.size end
to_json(options = {})
click to toggle source
# File lib/benchmark/lab/descriptive_statistics.rb, line 24 def to_json(options = {}) { 'name' => name, 'sample' => sample, 'sample_size' => sample_size, 'minimum' => minimum, 'maximum' => maximum, 'first_quartile' => first_quartile, 'third_quartile' => third_quartile, 'median' => median, 'interquartile_range' => interquartile_range }.to_json end
Private Instance Methods
calculate_first_quartile_of(data)
click to toggle source
mathworld.wolfram.com/Quartile.html en.wikipedia.org/wiki/Quartile
# File lib/benchmark/lab/descriptive_statistics.rb, line 49 def calculate_first_quartile_of(data) return calculate_median_of(data[0..(data.size / 2)]) if data.size.odd? calculate_median_of(data[0..((data.size - 1) / 2)]) end
calculate_median_of(data)
click to toggle source
# File lib/benchmark/lab/descriptive_statistics.rb, line 41 def calculate_median_of(data) return data[data.size / 2] if data.size.odd? (data[(data.size - 1) / 2] + data[data.size / 2]) / 2.0 end
calculate_third_quartile_of(data)
click to toggle source
# File lib/benchmark/lab/descriptive_statistics.rb, line 55 def calculate_third_quartile_of(data) return calculate_median_of(data[(data.size / 2)..-1]) if data.size.odd? calculate_median_of(data[(data.size / 2)..-1]) end