Class: Quant::Statistics::Correlation
- Inherits:
-
Object
- Object
- Quant::Statistics::Correlation
- Defined in:
- lib/quant/statistics/correlation.rb
Instance Attribute Summary collapse
-
#length ⇒ Object
Returns the value of attribute length.
-
#sx ⇒ Object
Returns the value of attribute sx.
-
#sxx ⇒ Object
Returns the value of attribute sxx.
-
#sxy ⇒ Object
Returns the value of attribute sxy.
-
#sy ⇒ Object
Returns the value of attribute sy.
-
#syy ⇒ Object
Returns the value of attribute syy.
Instance Method Summary collapse
- #add(x, y) ⇒ Object
- #coefficient ⇒ Object
- #devisor ⇒ Object
-
#initialize ⇒ Correlation
constructor
A new instance of Correlation.
Constructor Details
#initialize ⇒ Correlation
Returns a new instance of Correlation.
6 7 8 9 10 11 12 13 |
# File 'lib/quant/statistics/correlation.rb', line 6 def initialize @length = 0.0 @sx = 0.0 @sy = 0.0 @sxx = 0.0 @sxy = 0.0 @syy = 0.0 end |
Instance Attribute Details
#length ⇒ Object
Returns the value of attribute length.
4 5 6 |
# File 'lib/quant/statistics/correlation.rb', line 4 def length @length end |
#sx ⇒ Object
Returns the value of attribute sx.
4 5 6 |
# File 'lib/quant/statistics/correlation.rb', line 4 def sx @sx end |
#sxx ⇒ Object
Returns the value of attribute sxx.
4 5 6 |
# File 'lib/quant/statistics/correlation.rb', line 4 def sxx @sxx end |
#sxy ⇒ Object
Returns the value of attribute sxy.
4 5 6 |
# File 'lib/quant/statistics/correlation.rb', line 4 def sxy @sxy end |
#sy ⇒ Object
Returns the value of attribute sy.
4 5 6 |
# File 'lib/quant/statistics/correlation.rb', line 4 def sy @sy end |
#syy ⇒ Object
Returns the value of attribute syy.
4 5 6 |
# File 'lib/quant/statistics/correlation.rb', line 4 def syy @syy end |
Instance Method Details
#add(x, y) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/quant/statistics/correlation.rb', line 15 def add(x, y) @length += 1 @sx += x @sy += y @sxx += x * x @sxy += x * y @syy += y * y end |
#coefficient ⇒ Object
29 30 31 32 33 |
# File 'lib/quant/statistics/correlation.rb', line 29 def coefficient (length * sxy - sx * sy) / Math.sqrt(devisor) rescue Math::DomainError 0.0 end |
#devisor ⇒ Object
24 25 26 27 |
# File 'lib/quant/statistics/correlation.rb', line 24 def devisor value = (length * sxx - sx**2) * (length * syy - sy**2) value.zero? ? 1.0 : value end |