Class: Rust::StatisticalTests::Hypothesis

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title) ⇒ Hypothesis

Returns a new instance of Hypothesis.



66
67
68
69
# File 'lib/rust/stats/tests.rb', line 66

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

Instance Attribute Details

#resultsObject (readonly)

Returns the value of attribute results.



63
64
65
# File 'lib/rust/stats/tests.rb', line 63

def results
  @results
end

#titleObject (readonly)

Returns the value of attribute title.



64
65
66
# File 'lib/rust/stats/tests.rb', line 64

def title
  @title
end

Class Method Details

.find(title_or_instance) ⇒ Object

Raises:

  • (TypeError)


47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/rust/stats/tests.rb', line 47

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



71
72
73
# File 'lib/rust/stats/tests.rb', line 71

def add(result)            
    @results << result
end

#adjusted_pvalue_for(instance, method) ⇒ Object



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

def adjusted_pvalue_for(instance, method)
    p_values = @results.map { |r| r.pvalue }
    index = @results.index(instance)
    
    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