Created
October 14, 2011 14:45
-
-
Save mjul/1287314 to your computer and use it in GitHub Desktop.
Plot the distribution of a set of measurements in a histogram and the corresponding normal distribution (Clojure Incanter)
This file contains 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
(defn histogram-with-normal-distribution [ds] | |
"Produce a histgoram of the single-dimensional dataset ds and the corresponding normal distribution." | |
(with-data ds | |
(let [x-mean (mean ds) | |
x-sd (sd ds) | |
x-min (apply min ds) | |
x-max (apply max ds) | |
h (doto (histogram ds :nbins 100 :density true) | |
(set-stroke-color java.awt.Color/blue) | |
(set-title "Distribution of latencies") | |
(add-subtitle (format "Mean = %4.1f ms, Std.dev. = %4.2f" x-mean x-sd)) | |
(set-x-label "latency (ms)") | |
(set-y-label "share of messages") | |
(add-function (fn [x] (pdf-normal x :mean x-mean :sd x-sd)) x-min x-max :series-label "PDF-normal") | |
(add-histogram (sample-normal 1000 :mean x-mean :sd x-sd) :nbins 100 :series-label "normal distribution"))] | |
(view h) | |
h))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment