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 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 charts)) | |
;; plot the sine and cosine functions with | |
;; the function-plot and add-function functions | |
(doto (function-plot sin (- Math/PI) Math/PI) | |
(add-function cos (- Math/PI) Math/PI) | |
view) |
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
;; plot a user defined function and its derivative | |
(use '(incanter core charts optimize)) | |
;; define the function, x^3 + 2x^2 + 2x + 3 | |
(defn cubic [x] (+ (* x x x) (* 2 x x) (* 2 x) 3)) | |
;; use the derivative function to get a function | |
;; that approximates the derivative of cubic | |
(def deriv-cubic (derivative cubic)) |
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
;; example of performing PCA on Fisher's iris data | |
(use '(incanter core stats charts datasets)) | |
(def iris (to-matrix (get-dataset :iris))) | |
(view iris) | |
(def X (sel iris :cols (range 4))) | |
(def species (sel iris :cols 4)) | |
(def pca (principal-components 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
;; example of testing the significance of a correlation | |
;; value with a permutation test | |
(use '(incanter core stats charts datasets)) | |
;; load the data | |
(def data (to-matrix (get-dataset :us-arrests))) | |
(def assault (sel data :cols 2)) | |
(def urban-pop (sel data :cols 3)) |
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
;; compare the means of different treatments in the plant-growth data set | |
(use '(incanter core stats charts datasets)) | |
;; load the plant-growth data | |
(def plant-growth (to-matrix (get-dataset :plant-growth))) | |
;; create box-plots of the three treatment groups | |
(view (box-plot (sel plant-growth :cols 0) | |
:group-by (sel plant-growth :cols 1))) |
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
;; load the necessary libraries | |
(use '(incanter core stats charts datasets)) | |
;; load the NIST filip data set | |
;; see information on this data set at http://www.itl.nist.gov/div898/strd/lls/data/Filip.shtml | |
(def data (to-matrix (get-dataset :filip))) | |
(def y (sel data :cols 0)) | |
;; use the sweep function to center the x values to reduce collinearity of the polynomial terms |
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 optimize datasets charts)) | |
;; Chwirut data set from NIST | |
;; http://www.itl.nist.gov/div898/strd/nls/data/LINKS/DATA/Chwirut1.dat | |
(def data (to-matrix (get-dataset :chwirut))) | |
(def x (sel data :cols 1)) | |
(def y (sel data :cols 0)) | |
;; define model function: y = exp(-b1*x)/(b2+b3*x) + e | |
(defn f [theta 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 charts)) | |
(def x (range (* -2 Math/PI) (* 2 Math/PI) 0.01)) | |
(def plot (xy-plot x (sin x))) | |
(view plot) | |
;; annotate the plot | |
(doto plot | |
(add-pointer (- Math/PI) (sin (- Math/PI)) | |
:text "(-pi, (sin -pi))") |