Class: Rubystats::StudentTDistribution

Inherits:
ProbabilityDistribution show all
Includes:
SpecialMath
Defined in:
lib/rubystats/student_t_distribution.rb

Constant Summary

Constants included from NumericalConstants

NumericalConstants::EPS, NumericalConstants::GAMMA, NumericalConstants::GAMMA_X_MAX_VALUE, NumericalConstants::GOLDEN_RATIO, NumericalConstants::LOG_GAMMA_X_MAX_VALUE, NumericalConstants::MAX_FLOAT, NumericalConstants::MAX_ITERATIONS, NumericalConstants::MAX_VALUE, NumericalConstants::PRECISION, NumericalConstants::SQRT2, NumericalConstants::SQRT2PI, NumericalConstants::TWO_PI, NumericalConstants::XMININ

Instance Attribute Summary

Attributes included from SpecialMath

#log_beta_cache_p, #log_beta_cache_q, #log_beta_cache_res, #log_gamma_cache_res, #log_gamma_cache_x

Instance Method Summary collapse

Methods included from SpecialMath

#beta, #beta_fraction, #complementary_error, #error, #gamma, #gamma_fraction, #gamma_series_expansion, #incomplete_beta, #incomplete_gamma, #log_beta, #log_gamma, #orig_gamma

Methods inherited from ProbabilityDistribution

#cdf, #check_range, #find_root, #get_factorial, #icdf, #mean, #pdf, #rng, #variance

Methods included from ExtraMath

#binomial

Constructor Details

#initialize(degree_of_freedom = 1.0) ⇒ StudentTDistribution

Constructs a student t distribution.



9
10
11
12
13
14
# File 'lib/rubystats/student_t_distribution.rb', line 9

def initialize(degree_of_freedom=1.0)
  raise "Argument Error: degrees of freedom for student t distribution must be greater than zero." if degree_of_freedom <= 0.0
  @dof = degree_of_freedom.to_f   
  @pdf_factor = Math.gamma((@dof + 1.0) / 2.0) / ( Math.sqrt(@dof * Math::PI) * Math.gamma(@dof / 2.0))	  
	  @stdnorm = Rubystats::NormalDistribution.new(0.0,1.0)	  
end

Instance Method Details

#get_meanObject

Returns the mean of the distribution



17
18
19
# File 'lib/rubystats/student_t_distribution.rb', line 17

def get_mean
  (@dof > 1) ? 0.0 : Float::NAN      
end

#get_standard_deviationObject

Returns the standard deviation of the distribution



22
23
24
# File 'lib/rubystats/student_t_distribution.rb', line 22

def get_standard_deviation
  return Math.sqrt(get_variance)
end

#get_varianceObject

Returns the variance of the distribution



27
28
29
# File 'lib/rubystats/student_t_distribution.rb', line 27

def get_variance
  (@dof > 2.0) ? (@dof / (@dof - 2)) : Float::NAN      
end