module Nuggets::Array::VarianceMixin
Public Instance Methods
Alias for: covariance
Calculates the covariance of the {x,y}
pairs in array. If array only contains values instead of pairs, y
will be the value and x
will be each value's position (rank) in array.
# File lib/nuggets/array/variance_mixin.rb 60 def covariance 61 sx, sy, sp = 0.0, 0.0, 0.0 62 63 return sx if empty? 64 65 target = first.respond_to?(:to_ary) ? self : 66 self.class.new(size) { |i| [i + 1, at(i)] } 67 68 target.each { |x, y| 69 sx += x 70 sy += y 71 sp += x * y 72 } 73 74 (sp - sx * sy / size) / size 75 end
Also aliased as: cov
Alias for: variance