Class: Rust::StatisticalTests::Result

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

Overview

Represents the result of a statistical hypothesis test.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeResult

Returns a new instance of Result.



19
20
21
# File 'lib/rust/stats/tests.rb', line 19

def initialize
    @statistics = {}
end

Instance Attribute Details

#alphaObject

Returns the value of attribute alpha.



16
17
18
# File 'lib/rust/stats/tests.rb', line 16

def alpha
  @alpha
end

#exactObject

Returns the value of attribute exact.



15
16
17
# File 'lib/rust/stats/tests.rb', line 15

def exact
  @exact
end

#hypothesisObject

Returns the value of attribute hypothesis.



17
18
19
# File 'lib/rust/stats/tests.rb', line 17

def hypothesis
  @hypothesis
end

#nameObject

Returns the value of attribute name.



12
13
14
# File 'lib/rust/stats/tests.rb', line 12

def name
  @name
end

#pvalueObject

Returns the value of attribute pvalue.



14
15
16
# File 'lib/rust/stats/tests.rb', line 14

def pvalue
  @pvalue
end

#statisticsObject

Returns the value of attribute statistics.



13
14
15
# File 'lib/rust/stats/tests.rb', line 13

def statistics
  @statistics
end

Instance Method Details

#[](name) ⇒ Object



23
24
25
# File 'lib/rust/stats/tests.rb', line 23

def [](name)
    return @statistics[name.to_sym]
end

#[]=(name, value) ⇒ Object



27
28
29
# File 'lib/rust/stats/tests.rb', line 27

def []=(name, value)
    @statistics[name.to_sym] = value
end

#adjusted_pvalue(method = 'bonferroni') ⇒ Object

If a hypothesis is available, returns the adjusted p-value with respect to all the other results obtained for the same hypothesis. Otherwise, simply returns the p-value for this result. The method for adjustment can be optionally specified (Bonferroni, by default).



36
37
38
39
# File 'lib/rust/stats/tests.rb', line 36

def adjusted_pvalue(method='bonferroni')
    return @pvalue unless @hypothesis
    @hypothesis.adjusted_pvalue_for(self, method)
end

#significantObject

Returns true if the results are significant according to the specified alpha.



53
54
55
# File 'lib/rust/stats/tests.rb', line 53

def significant
    pvalue < alpha
end

#to_sObject



57
58
59
60
61
62
# File 'lib/rust/stats/tests.rb', line 57

def to_s
    return "#{name}. P-value = #{pvalue} " +
            "(#{significant ? "significant" : "not significant"} w/ alpha = #{alpha}); " + 
            "#{ statistics.map { |k, v| k.to_s + " -> " + v.to_s  }.join(", ") }." +
            (!exact ? " P-value is not exact." : "")
end