Class: Fathom::Distributions::Gaussian

Inherits:
Object
  • Object
show all
Extended by:
SharedMethods
Defined in:
lib/fathom/distributions/gaussian.rb

Class Method Summary collapse

Class Method Details

.interval_values(opts = {}) ⇒ Object



30
31
32
33
34
# File 'lib/fathom/distributions/gaussian.rb', line 30

def interval_values(opts={})
  confidence_interval = opts.fetch(:confidence_interval, 0.9)
  bound = (1 - confidence_interval) / 2.0
  [lower_bound(opts.merge(:confidence_interval => bound)), upper_bound(opts.merge(:confidence_interval => bound))]
end

.inverse_cdf(opts = {}) ⇒ Object Also known as: lower_bound



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/fathom/distributions/gaussian.rb', line 13

def inverse_cdf(opts={})
  mean = opts[:mean]
  sd = opts[:sd]
  sd ||= opts[:std]
  sd ||= opts[:standard_deviation]
  lower = opts.fetch(:lower, true)
  lower = false if opts[:upper]
  confidence_interval = opts.fetch(:confidence_interval, 0.05)
  value = lower ? GSL::Cdf.gaussian_Pinv(confidence_interval, sd) : GSL::Cdf.gaussian_Qinv(confidence_interval, sd)
  value + mean
end

.rand(sd) ⇒ Object



9
10
11
# File 'lib/fathom/distributions/gaussian.rb', line 9

def rand(sd)
  rng.gaussian(sd)
end

.rngObject



5
6
7
# File 'lib/fathom/distributions/gaussian.rb', line 5

def rng
  @rng ||= GSL::Rng.alloc(GSL::Rng::MT19937_1999, Kernel.rand(100_000))
end

.standard_deviations_under(confidence_interval) ⇒ Object

If only I had the background to explain what this is.… I want to know how many standard deviations are expressed by the confidence interval I can then divide the range by this number to get the standard deviation



39
40
41
# File 'lib/fathom/distributions/gaussian.rb', line 39

def standard_deviations_under(confidence_interval)
  GSL::Cdf.gaussian_Qinv((1 - confidence_interval) / 2) * 2
end

.upper_bound(opts = {}) ⇒ Object



26
27
28
# File 'lib/fathom/distributions/gaussian.rb', line 26

def upper_bound(opts={})
  inverse_cdf(opts.merge(:lower => false))
end