Class: Statistics::Distribution::TStudent
- Inherits:
-
Object
- Object
- Statistics::Distribution::TStudent
- Defined in:
- lib/statistics/distribution/t_student.rb
Instance Attribute Summary collapse
-
#degrees_of_freedom ⇒ Object
Returns the value of attribute degrees_of_freedom.
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
Instance Method Summary collapse
-
#cumulative_function(value) ⇒ Object
Extracted from codeplea.com/incomplete-beta-function-c This function is shared under zlib license and the author is Lewis Van Winkle.
- #density_function(value) ⇒ Object
-
#initialize(v) ⇒ TStudent
constructor
A new instance of TStudent.
- #mean ⇒ Object
- #variance ⇒ Object
Constructor Details
#initialize(v) ⇒ TStudent
Returns a new instance of TStudent.
7 8 9 10 |
# File 'lib/statistics/distribution/t_student.rb', line 7 def initialize(v) self.degrees_of_freedom = v @mode = 0 end |
Instance Attribute Details
#degrees_of_freedom ⇒ Object
Returns the value of attribute degrees_of_freedom.
4 5 6 |
# File 'lib/statistics/distribution/t_student.rb', line 4 def degrees_of_freedom @degrees_of_freedom end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
5 6 7 |
# File 'lib/statistics/distribution/t_student.rb', line 5 def mode @mode end |
Instance Method Details
#cumulative_function(value) ⇒ Object
Extracted from codeplea.com/incomplete-beta-function-c This function is shared under zlib license and the author is Lewis Van Winkle
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/statistics/distribution/t_student.rb', line 14 def cumulative_function(value) upper = (value + Math.sqrt(value * value + degrees_of_freedom)) lower = (2.0 * Math.sqrt(value * value + degrees_of_freedom)) x = upper/lower alpha = degrees_of_freedom/2.0 beta = degrees_of_freedom/2.0 Math.incomplete_beta_function(x, alpha, beta) end |
#density_function(value) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/statistics/distribution/t_student.rb', line 26 def density_function(value) return if degrees_of_freedom <= 0 upper = Math.gamma((degrees_of_freedom + 1)/2.0) lower = Math.sqrt(degrees_of_freedom * Math::PI) * Math.gamma(degrees_of_freedom/2.0) left = upper/lower right = (1 + ((value ** 2)/degrees_of_freedom.to_f)) ** -((degrees_of_freedom + 1)/2.0) left * right end |
#mean ⇒ Object
37 38 39 |
# File 'lib/statistics/distribution/t_student.rb', line 37 def mean 0 if degrees_of_freedom > 1 end |
#variance ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/statistics/distribution/t_student.rb', line 41 def variance if degrees_of_freedom > 1 && degrees_of_freedom <= 2 Float::INFINITY elsif degrees_of_freedom > 2 degrees_of_freedom/(degrees_of_freedom - 2.0) end end |