1.2.3-SNAPSHOT permalink Arrow_down_16x16

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

0 Examples top

Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 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

Comments top

No comments for covariance. Log in to add a comment.