• incanter

1.2.3-SNAPSHOT

# covariance

## incanter.stats

• (covariance x y)
• (covariance mat)

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

### Source incanter/stats.clj:1476 top

```(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))))```
Vars in incanter.stats/covariance: defn double-array for let
Used in 0 other vars