Created
January 20, 2017 14:20
-
-
Save jeroenvandijk/d897fc90a406cab204a01be1178cd9bf to your computer and use it in GitHub Desktop.
Sample log normal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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