module Rust::StatisticalTests::Wilcoxon

Public Class Methods

paired(d1, d2, alpha = 0.05, **options) click to toggle source
# File lib/rust-tests.rb, line 166
 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["wilcox.a"] = d1
        Rust["wilcox.b"] = d2
        
        _, warnings = Rust._eval("wilcox.result = wilcox.test(wilcox.a, wilcox.b, alternative='two.sided', paired=T)", true)
        result = Rust::StatisticalTests::Result.new
        result.name       = "Wilcoxon Signed-Rank test"
        result.pvalue     = Rust._pull("wilcox.result$p.value")
        result[:w]        = Rust._pull("wilcox.result$statistic")
        result.exact      = !warnings.include?("cannot compute exact p-value with zeroes")
        result.alpha      = alpha
        result.hypothesis = Rust::StatisticalTests::Hypothesis.find(options[:hypothesis])
    
        return result
    end
end
unpaired(d1, d2, alpha = 0.05, **options) click to toggle source
# File lib/rust-tests.rb, line 188
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["wilcox.a"] = d1
        Rust["wilcox.b"] = d2
        
        _, warnings = Rust._eval("wilcox.result = wilcox.test(wilcox.a, wilcox.b, alternative='two.sided', paired=F)", true)
        result = Rust::StatisticalTests::Result.new
        result.name       = "Wilcoxon Ranked-Sum test (a.k.a. Mann–Whitney U test)"
        result.pvalue     = Rust._pull("wilcox.result$p.value")
        result[:w]        = Rust._pull("wilcox.result$statistic")
        result.exact      = !warnings.include?("cannot compute exact p-value with ties")
        result.alpha      = alpha
        result.hypothesis = Rust::StatisticalTests::Hypothesis.find(options[:hypothesis])
        
        return result
    end
end