Class: RubyStatistics::Distribution::Empirical
- Inherits:
-
Object
- Object
- RubyStatistics::Distribution::Empirical
- Defined in:
- lib/ruby-statistics/distribution/empirical.rb
Instance Attribute Summary collapse
-
#samples ⇒ Object
Returns the value of attribute samples.
Instance Method Summary collapse
-
#cumulative_function(x:) ⇒ Object
Formula grabbed from here: statlect.com/asymptotic-theory/empirical-distribution.
-
#initialize(samples:) ⇒ Empirical
constructor
A new instance of Empirical.
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
#samples ⇒ Object
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
Formula grabbed from here: statlect.com/asymptotic-theory/empirical-distribution
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 |