Class: Rust::StatisticalTests::T

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

Class Method Summary collapse

Class Method Details

.paired(d1, d2, alpha = 0.05, **options) ⇒ Object

Raises:

  • (TypeError)


135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/rust/stats/tests.rb', line 135

def self.paired(d1, d2, alpha = 0.05, **options)
    raise TypeError, "Expecting Array of numerics" if !d1.is_a?(Array) || !d1.all? { |e| e.is_a?(Numeric) }
    raise TypeError, "Expecting Array of numerics" if !d2.is_a?(Array) || !d2.all? { |e| e.is_a?(Numeric) }
    raise "The two distributions have different size" if d1.size != d2.size
    
    Rust.exclusive do
        Rust["t.a"] = d1
        Rust["t.b"] = d2
        
        warnings = Rust._eval("t.result = t.test(t.a, t.b, alternative='two.sided', paired=T)")
        result = Rust::StatisticalTests::Result.new
        result.name       = "Paired t-test"
        result.pvalue     = Rust._pull("t.result$p.value")
        result[:t]        = Rust._pull("t.result$statistic")
        result.exact      = true
        result.alpha      = alpha
        result.hypothesis = Rust::StatisticalTests::Hypothesis.find(options[:hypothesis])
        
        return result
    end
end

.unpaired(d1, d2, alpha = 0.05, **options) ⇒ Object

Raises:

  • (TypeError)


157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/rust/stats/tests.rb', line 157

def self.unpaired(d1, d2, alpha = 0.05, **options)
    raise TypeError, "Expecting Array of numerics" if !d1.is_a?(Array) || !d1.all? { |e| e.is_a?(Numeric) }
    raise TypeError, "Expecting Array of numerics" if !d2.is_a?(Array) || !d2.all? { |e| e.is_a?(Numeric) }
    
    Rust.exclusive do
        Rust["t.a"] = d1
        Rust["t.b"] = d2
        
        Rust._eval("t.result = t.test(t.a, t.b, alternative='two.sided', paired=F)")
        result = Rust::StatisticalTests::Result.new
        result.name       = "Welch Two Sample t-test"
        result.pvalue     = Rust._pull("t.result$p.value")
        result[:t]        = Rust._pull("t.result$statistic")
        result.exact      = true
        result.alpha      = alpha
        result.hypothesis = Rust::StatisticalTests::Hypothesis.find(options[:hypothesis])
        
        return result
    end
end