Module: Rust::StatisticalTests::Wilcoxon

Defined in:
lib/rust-tests.rb

Class Method Summary collapse

Class Method Details

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

Raises:

  • (TypeError)


166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# 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) ⇒ Object

Raises:

  • (TypeError)


188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# 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