Skip to content

Instantly share code, notes, and snippets.

@strongh
Created January 22, 2014 04:00
Show Gist options
  • Save strongh/8553277 to your computer and use it in GitHub Desktop.
Save strongh/8553277 to your computer and use it in GitHub Desktop.
;; http://www.johndcook.com/standard_deviation.html
(defn online-var
[x]
(loop [xs x
k 1
m (first x)
s 0]
(let [x (first xs)
mk (+ m (float (/ (- x m) k)))]
(if (empty? (rest xs))
(/ s (- k 1))
(recur (rest xs)
(inc k)
mk
(+ s (* (- x m) (- x mk))))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment