Module: Rust::StatisticalTests::Wilcoxon

Defined in:
lib/rust-tests.rb

Class Method Summary collapse

Class Method Details

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

Raises:

  • (TypeError)


38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/rust-tests.rb', line 38

def paired(d1, d2, alpha = 0.05)
    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
    
        return result
    end
end

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

Raises:

  • (TypeError)


59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/rust-tests.rb', line 59

def unpaired(d1, d2, alpha = 0.05)
    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
        
        return result
    end
end