Class: Rust::Correlation::Pearson
- Defined in:
- lib/rust/stats/correlation.rb
Overview
Pearson correlation utility methods.
Class Method Summary collapse
-
.estimate(d1, d2) ⇒ Object
Returns the Pearson correlation index between
d1
andd2
. -
.test(d1, d2) ⇒ Object
Runs the Pearson correlation test between
d1
andd2
.
Class Method Details
.estimate(d1, d2) ⇒ Object
Returns the Pearson correlation index between d1
and d2
40 41 42 |
# File 'lib/rust/stats/correlation.rb', line 40 def self.estimate(d1, d2) self.test(d1, d2).correlation end |
.test(d1, d2) ⇒ Object
Runs the Pearson correlation test between d1
and d2
.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rust/stats/correlation.rb', line 16 def self.test(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) } Rust.exclusive do Rust['correlation.a'] = d1 Rust['correlation.b'] = d2 _, warnings = Rust._eval("correlation.result <- cor.test(correlation.a, correlation.b, method='p')", true) result = Result.new result.name = "Pearson's product-moment correlation" result.statistics['t'] = Rust._pull('correlation.result$statistic') result.pvalue = Rust._pull('correlation.result$p.value') result.correlation = Rust._pull('correlation.result$estimate') result.exact = !warnings.include?("Cannot compute exact p-value with ties") return result end end |