Class: Rust::StatisticalTests::Wilcoxon
- Defined in:
- lib/rust/stats/tests.rb
Class Method Summary collapse
- .paired(d1, d2, alpha = 0.05, **options) ⇒ Object
- .unpaired(d1, d2, alpha = 0.05, **options) ⇒ Object
Class Method Details
.paired(d1, d2, alpha = 0.05, **options) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/rust/stats/tests.rb', line 90 def self.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 result.hypothesis = Rust::StatisticalTests::Hypothesis.find([:hypothesis]) return result end end |
.unpaired(d1, d2, alpha = 0.05, **options) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/rust/stats/tests.rb', line 112 def self.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 result.hypothesis = Rust::StatisticalTests::Hypothesis.find([:hypothesis]) return result end end |