Class: Rust::StatisticalTests::Hypothesis

Inherits:
Object
  • Object
show all
Defined in:
lib/rust/stats/tests.rb

Overview

Represents a hypothesis behind one or more results.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title) ⇒ Hypothesis

Creates a new hypothesis with a given title.



94
95
96
97
# File 'lib/rust/stats/tests.rb', line 94

def initialize(title)
    @title = title
    @results = []
end

Instance Attribute Details

#resultsObject (readonly)

Returns the value of attribute results.



88
89
90
# File 'lib/rust/stats/tests.rb', line 88

def results
  @results
end

#titleObject (readonly)

Returns the value of attribute title.



89
90
91
# File 'lib/rust/stats/tests.rb', line 89

def title
  @title
end

Class Method Details

.find(title_or_instance) ⇒ Object

Returns the hypothesis with the given title_or_instance as title (if String).

Raises:

  • (TypeError)


72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/rust/stats/tests.rb', line 72

def self.find(title_or_instance)
    return Hypothesis.new(nil) if title_or_instance == nil
    
    if title_or_instance.is_a?(String)
        ObjectSpace.each_object(Hypothesis) do |instance|
            return instance if instance.title == title_or_instance
        end
        
        return Hypothesis.new(title_or_instance)
    elsif title_or_instance.is_a?(Hypothesis)
        return title_or_instance
    end
    
    raise TypeError, "Expected nil, String or Hypothesis"
end

Instance Method Details

#add(result) ⇒ Object

Registers a result for this hypothesis.



102
103
104
# File 'lib/rust/stats/tests.rb', line 102

def add(result)            
    @results << result
end

#adjusted_pvalue_for(result, method) ⇒ Object

Returns the adjusted p-value for a specific result with respect to all the other results obtained under this same hypothesis, using the specified method.



110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/rust/stats/tests.rb', line 110

def adjusted_pvalue_for(result, method)
    p_values = @results.map { |r| r.pvalue }
    index = @results.index(result)
    
    adjusted_pvalues = Rust::StatisticalTests::PValueAdjustment.method(method).adjust(*p_values)
    
    if adjusted_pvalues.is_a?(Numeric)
        return adjusted_pvalues
    else
        return adjusted_pvalues[index]
    end
end