Class: Rust::EffectSize::CliffDelta

Inherits:
Object
  • Object
show all
Defined in:
lib/rust/stats/effsize.rb

Overview

Cliff delta effect size statistics.

Class Method Summary collapse

Class Method Details

.compute(d1, d2) ⇒ Object

Computes and returns the effect size for d1 and d2.

Raises:

  • (TypeError)


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/rust/stats/effsize.rb', line 33

def self.compute(d1, d2)
    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) }
    
    if d1.size <= 1 || d2.size <= 1
        return Rust::EffectSize::Result.new
    end
    
    Rust.exclusive do
        Rust['effsize.a'] = d1
        Rust['effsize.b'] = d2
        
        Rust._eval("effsize.result = cliff.delta(effsize.a, effsize.b)")
        
        result = Rust::EffectSize::Result.new
        result.name                 = "Cliff's delta"
        result.estimate             = Rust._pull("effsize.result$estimate")                         rescue Float::NAN
        result.confidence_interval  = Range.new(*Rust._pull("effsize.result$conf.int"))             rescue nil
        result.confidence_level     = Rust._pull("effsize.result$conf.level")                       rescue Float::NAN
        result.magnitude            = Rust._pull("as.character(effsize.result$magnitude)").to_sym   rescue nil
        
        return result
    end
end