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
(use '(incanter core stats charts)) | |
;; Overlay a xy-plot on a histogram | |
;; Plot a histogram of a normal sample of size 1000, using the :density option | |
;; so that the y-axis represents density instead of the default frequency. | |
;; Then plot a pdf curve for the normal distribution on the same chart. | |
(def x (range -3 3 0.01)) | |
(doto (histogram (sample-normal 1000) :density true) |
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
(use '(incanter core stats charts datasets)) | |
;; load the iris dataset | |
(def iris (to-matrix (get-dataset :iris))) | |
;; run the pca on the first four columns only | |
(def pca (principal-components (sel iris :cols (range 4)))) | |
;; extract the first two principal components | |
(def pc1 (sel (:rotation pca) :cols 0)) | |
(def pc2 (sel (:rotation pca) :cols 1)) | |
;; project the first four dimension of the iris data onto the first |
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
(use '(incanter stats charts)) | |
;; plot the normal pdf function | |
(def x (range -3 3 0.1)) | |
(view (xy-plot x (pdf-normal x))) |
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
(use '(incanter core stats charts)) | |
;; generate a sample from a bi-variate normal distribution | |
(def mvn-samp (sample-mvn 1000 :mean [7 5] :sigma (matrix [[2 1.5] [1.5 3]]))) | |
(def x (sel mvn-samp :cols 0)) | |
(def y (sel mvn-samp :cols 1)) | |
;; add regression line to scatter plot | |
(def lm (linear-model y x)) |
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
(use '(incanter core datasets stats bayes charts)) | |
(def survey-data (to-matrix (get-dataset :survey))) | |
(def x (sel survey-data (range 0 2313) (range 1 10))) | |
(def y (sel survey-data (range 0 2313) 10)) | |
(def sample-params (sample-model-params 5000 (linear-model y x :intercept false))) | |
(view (trace-plot (:var sample-params))) | |
(view (trace-plot (sel (:coefs sample-params) :cols 0))) |
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
(use '(incanter stats charts)) | |
;; qq-plot of normal distributed sample data | |
(view (qq-plot (sample-normal 100))) | |
;; qq-plot of exponential distributed sample data | |
(view (qq-plot (sample-exp 100))) | |
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
(use '(incanter core datasets charts io)) | |
(def flow-meter (to-matrix (get-dataset :flow-meter))) | |
(def x1 (sel flow-meter :cols 1)) | |
(def x2 (sel flow-meter :cols 3)) | |
(doto (bland-altman-plot x1 x2) | |
view | |
clear-background | |
(save "/tmp/bland_altman_plot.png")) |
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
;; Examples of plots from the Gamma Distribution page at | |
;; Wikipedia (http://en.wikipedia.org/wiki/Gamma_distribution) | |
(use '(incanter stats charts io)) | |
(def x (range 0 20 0.1)) | |
(def gamma-plot (xy-plot x (pdf-gamma x :shape 1 :rate 2) | |
:legend true | |
:title "Gamma PDF" | |
:y-label "Density")) |
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
(use '(incanter core stats charts io)) | |
;; make a histogram of a sample of 1000 Gamma deviates | |
(doto (histogram (sample-gamma 1000 :shape 1 :rate 2) | |
:title "Gamma Histogram") | |
view | |
clear-background | |
(save "/tmp/gamma_hist.png")) |
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
(use '(incanter stats charts io)) | |
(doto (box-plot (sample-gamma 1000 :shape 1 :rate 2) | |
:title "Gamma Boxplot" | |
:legend true) | |
(add-box-plot (sample-gamma 1000 :shape 2 :rate 2)) | |
(add-box-plot (sample-gamma 1000 :shape 3 :rate 2)) | |
(add-box-plot (sample-gamma 1000 :shape 5 :rate 1)) | |
(add-box-plot (sample-gamma 1000 :shape 9 :rate 0.5)) | |
clear-background |