Class: RubyStatistics::Distribution::Empirical

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-statistics/distribution/empirical.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(samples:) ⇒ Empirical

Returns a new instance of Empirical.



6
7
8
# File 'lib/ruby-statistics/distribution/empirical.rb', line 6

def initialize(samples:)
  self.samples = samples
end

Instance Attribute Details

#samplesObject

Returns the value of attribute samples.



4
5
6
# File 'lib/ruby-statistics/distribution/empirical.rb', line 4

def samples
  @samples
end

Instance Method Details

#cumulative_function(x:) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/ruby-statistics/distribution/empirical.rb', line 11

def cumulative_function(x:)
  cumulative_sum = samples.reduce(0) do |summation, sample|
    summation += if sample <= x
                   1
                 else
                   0
                 end

    summation
  end

  cumulative_sum / samples.size.to_r
end