Skip to content

Instantly share code, notes, and snippets.

@jeroenvandijk
Created January 20, 2017 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeroenvandijk/d897fc90a406cab204a01be1178cd9bf to your computer and use it in GitHub Desktop.
Save jeroenvandijk/d897fc90a406cab204a01be1178cd9bf to your computer and use it in GitHub Desktop.
Sample log normal
(require '[incanter.core :as incanter])
;; From http://stats.stackexchange.com/questions/95498/how-to-calculate-log-normal-parameters-using-the-mean-and-std-of-the-given-distr#95506
(defn sample-log-normal [n & {:keys [mean sd]}]
(let [sd-log-part (incanter/log (+ 1.0 (/ (* sd sd) (* mean mean))))
mu (- (incanter/log mean) (* 0.5 sd-log-part))
sigma (incanter/sqrt sd-log-part)]
(incanter/exp (incanter.stats/sample-normal n :mean mu :sd sigma))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment