(defn covariance
"
Returns the sample covariance of x and y.
Examples:
;; create some data that covaries
(def x (sample-normal 100))
(def err (sample-normal 100))
(def y (plus (mult 5 x) err))
;; estimate the covariance of x and y
(covariance x y)
References:
http://incanter.org/docs/parallelcolt/api/cern/jet/stat/tdouble/DoubleDescriptive.html
http://en.wikipedia.org/wiki/Covariance
"
([x y]
(let [
xx (to-list x)
yy (to-list y)
]
(DoubleDescriptive/covariance
(DoubleArrayList. (double-array xx))
(DoubleArrayList. (double-array yy)))))
([mat]
(let [n (ncol mat)]
(matrix
(for [i (range n) j (range n)]
(covariance (sel mat true i) (sel mat true j))) n))))
Used in 0 other vars
Comments top
No comments for covariance. Log in to add a comment.