Module: Rust::StatisticalTests::T

Defined in:
lib/rust-tests.rb

Class Method Summary collapse

Class Method Details

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

Raises:

  • (TypeError)


213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/rust-tests.rb', line 213

def 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)


235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'lib/rust-tests.rb', line 235

def 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