Liking cljdoc? Tell your friends :D

incanter.core

This is the core numerics library for Incanter. It provides functions for vector- and matrix-based mathematical operations and the core data manipulation functions for Incanter.

This library is built on core.matrix (https://github.com/mikera/core.matrix) and Parallel Colt (http://sites.google.com/site/piotrwendykier/software/parallelcolt) an extension of the Colt numerics library (http://acs.lbl.gov/~hoschek/colt/).

This is the core numerics library for Incanter.
It provides functions for vector- and matrix-based
mathematical operations and the core data manipulation
functions for Incanter.

This library is built on core.matrix (https://github.com/mikera/core.matrix)
and Parallel Colt
(http://sites.google.com/site/piotrwendykier/software/parallelcolt)
an extension of the Colt numerics library
(http://acs.lbl.gov/~hoschek/colt/).
raw docstring

$clj

($ cols)
($ arg1 arg2)
($ rows cols data)

An alias to (sel (second args) :cols (first args)). If given only a single argument, it will use the $data binding for the first argument, which is set with the with-data macro.

Examples: (use '(incanter core stats charts datasets))

(def cars (get-dataset :cars)) ($ :speed cars)

(with-data cars (def lm (linear-model ($ :dist) ($ :speed))) (doto (scatter-plot ($ :speed) ($ :dist)) view (add-lines ($ :speed) (:fitted lm))))

;; standardize speed and dist and append the standardized variables to the original dataset (with-data (get-dataset :cars) (view (conj-cols $data (sweep (sweep ($ :speed)) :stat sd :fun div) (sweep (sweep ($ :dist)) :stat sd :fun div))))

(with-data (get-dataset :iris) (view $data) (view ($ [:Sepal.Length :Sepal.Width :Species])) (view ($ [:not :Petal.Width :Petal.Length])) (view ($ 0 [:not :Petal.Width :Petal.Length])))

(use 'incanter.core) (def mat (matrix (range 9) 3)) (view mat) ($ 2 2 mat) ($ [0 2] 2 mat) ($ :all 1 mat) ($ 1 mat) ($ [:not 1] mat) ($ 0 :all mat) ($ [0 2] [0 2] mat) ($ [:not 1] [:not 1] mat) ($ [:not 1] :all mat) ($ [0 2] [:not 1] mat) ($ [0 2] [:not 1 2] mat) ($ [0 2] [:not (range 2)] mat) ($ [:not (range 2)] [0 2] mat)

(with-data mat ($ 0 0)) (with-data mat ($ [0 2] 2 mat)) (with-data mat ($ :all 1)) (with-data mat ($ [0 2] [0 2])) (with-data mat ($ [:not 1] :all)) (with-data mat ($ [0 2] [:not 1]))

(use 'incanter.datasets) (view (get-dataset :cars)) ($ (range 5) 0 (get-dataset :cars)) ($ (range 5) :all (get-dataset :cars)) ($ :all (range 2) (get-dataset :cars))

($ (range 5) :dist (get-dataset :cars)) ($ [:not (range 5)] 0 (get-dataset :cars)) ($ [:not 0 1 2 3 4] 0 (get-dataset :cars)) (with-data (get-dataset :cars) ($ 0 :dist))

(with-data (get-dataset :hair-eye-color) (view $data) (view ($ [:not :gender])))

An alias to (sel (second args) :cols (first args)). If given only a single argument,
it will use the $data binding for the first argument, which is set with
the with-data macro.

Examples:
  (use '(incanter core stats charts datasets))

  (def cars (get-dataset :cars))
  ($ :speed cars)


  (with-data cars
    (def lm (linear-model ($ :dist) ($ :speed)))
    (doto (scatter-plot ($ :speed) ($ :dist))
      view
      (add-lines ($ :speed) (:fitted lm))))

  ;; standardize speed and dist and append the standardized variables to the original dataset
  (with-data (get-dataset :cars)
    (view (conj-cols $data
                     (sweep (sweep ($ :speed)) :stat sd :fun div)
                     (sweep (sweep ($ :dist)) :stat sd :fun div))))

  (with-data (get-dataset :iris)
    (view $data)
    (view ($ [:Sepal.Length :Sepal.Width :Species]))
    (view ($ [:not :Petal.Width :Petal.Length]))
    (view ($ 0 [:not :Petal.Width :Petal.Length])))


   (use 'incanter.core)
   (def mat (matrix (range 9) 3))
   (view mat)
   ($ 2 2 mat)
   ($ [0 2] 2 mat)
   ($ :all 1 mat)
   ($ 1 mat)
   ($ [:not 1] mat)
   ($ 0 :all mat)
   ($ [0 2] [0 2] mat)
   ($ [:not 1] [:not 1] mat)
   ($ [:not 1] :all mat)
   ($ [0 2] [:not 1] mat)
   ($ [0 2] [:not 1 2] mat)
   ($ [0 2] [:not (range 2)] mat)
   ($ [:not (range 2)] [0 2] mat)

   (with-data mat
     ($ 0 0))
   (with-data mat
     ($ [0 2] 2 mat))
   (with-data mat
     ($ :all 1))
   (with-data mat
     ($ [0 2] [0 2]))
   (with-data mat
     ($ [:not 1] :all))
   (with-data mat
     ($ [0 2] [:not 1]))


   (use 'incanter.datasets)
   (view (get-dataset :cars))
   ($ (range 5) 0 (get-dataset :cars))
   ($ (range 5) :all (get-dataset :cars))
   ($ :all (range 2) (get-dataset :cars))

   ($ (range 5) :dist (get-dataset :cars))
   ($ [:not (range 5)] 0 (get-dataset :cars))
   ($ [:not 0 1 2 3 4] 0 (get-dataset :cars))
   (with-data (get-dataset :cars)
     ($ 0 :dist))

   (with-data (get-dataset :hair-eye-color)
     (view $data)
     (view ($ [:not :gender])))
sourceraw docstring

$=clj/smacro

($= & equation)

Formula macro translates from infix to prefix

Examples:

(use 'incanter.core) ($= 7 + 8) ($= [1 2 3] + [4 5 6]) ($= [1 2 3] + (sin [4 5 6])) ($= [1 2 3] <*> (trans [1 2 3])) ($= [1 2 3] * [1 2 3]) ($= [1 2 3] <x> [1 2 3]) ($= 9 * 8 ** 3) ($= (sin Math/PI) * 10)

($= 10 + 20 * (4 - 5) / 6)

($= 20 * (4 - 5) / 6)

(let [x 10 y -5] ($= x + y / -10))

($= 3 ** 3)

($= [1 2 3] * [1 2 3]) ($= [1 2 3] / (sq [1 2 3]) + [5 6 7])

($= (sqrt 5 * 5 + 3 * 3)) ($= (sq [1 2 3] + [1 2 3])) ($= ((5 + 4) * 5)) ($= ((5 + 4 * (3 - 4)) / (5 + 8) * 6)) ($= [1 2 3] + 5) ($= (matrix [[1 2] [4 5]]) + 6) ($= (trans [[1 2] [4 5]]) + 6)

($= (trans [[1 2] [4 5]]) <*> (matrix [[1 2] [4 5]]))

(use '(incanter core charts)) (defn f [x] ($= x ** 2 + 3 * x + 5)) (f 5) (view (function-plot f -10 10)) (view (function-plot #($= % ** 2 + 3 * % + 5) -10 10)) (view (function-plot (fn [x] ($= x ** 2 + 3 * x + 5)) -10 10)) (let [x (range -10 10 0.1)] (view (xy-plot x ($= x ** 3 - 5 * x ** 2 + 3 * x + 5))))

($= (5 + 7)) ($= (trans [1 2 3 4]) <> [1 2 3 4]) ($= [1 2 3 4] <> (trans [1 2 3 4]))

($= [1 2 3 4] <*> (trans [1 2 3 4])) ($= [1 2 3 4] <x> (trans [1 2 3 4]))

;; kronecker product example ($= (matrix [[1 2] [3 4] [5 6]]) <x> 4) ($= (matrix [[1 2] [3 4] [5 6]]) <x> (matrix [[1 2] [3 4]])) ($= [1 2 3 4] <x> 4)

($= 3 > (5 * 2/7))

(use '(incanter core datasets charts)) (with-data (get-dataset :cars) (doto (scatter-plot :speed :dist :data ($where ($fn [speed dist] ($= dist / speed < 2)))) (add-points :speed :dist :data ($where ($fn [speed dist] ($= dist / speed >= 2)))) (add-lines ($ :speed) ($= 2 * ($ :speed))) view))

Formula macro translates from infix to prefix


Examples:

  (use 'incanter.core)
  ($= 7 + 8)
  ($= [1 2 3] + [4 5 6])
  ($= [1 2 3] + (sin [4 5 6]))
  ($= [1 2 3] <*> (trans [1 2 3]))
  ($= [1 2 3] * [1 2 3])
  ($= [1 2 3] <x> [1 2 3])
  ($= 9 * 8 ** 3)
  ($= (sin Math/PI) * 10)

  ($= 10 + 20 * (4 - 5) / 6)

  ($= 20 * (4 - 5) / 6)

  (let [x 10
        y -5]
    ($= x + y / -10))

  ($= 3 ** 3)

  ($= [1 2 3] * [1 2 3])
  ($= [1 2 3] / (sq [1 2 3]) + [5 6 7])

  ($= (sqrt 5 * 5 + 3 * 3))
  ($= (sq [1 2 3] + [1 2 3]))
  ($= ((5 + 4) * 5))
  ($= ((5 + 4 * (3 - 4)) / (5 + 8) * 6))
  ($= [1 2 3] + 5)
  ($= (matrix [[1 2] [4 5]]) + 6)
  ($= (trans [[1 2] [4 5]]) + 6)

  ($= (trans [[1 2] [4 5]]) <*> (matrix [[1 2] [4 5]]))


  (use '(incanter core charts))
  (defn f [x] ($= x ** 2 + 3 * x + 5))
  (f 5)
  (view (function-plot f -10 10))
  (view (function-plot #($= % ** 2 + 3 * % + 5) -10 10))
  (view (function-plot (fn [x] ($= x ** 2 + 3 * x + 5)) -10 10))
  (let [x (range -10 10 0.1)]
    (view (xy-plot x ($= x ** 3 - 5 * x ** 2 + 3 * x + 5))))

  ($= (5 + 7))
  ($= (trans [1 2 3 4]) <*> [1 2 3 4])
  ($= [1 2 3 4] <*> (trans [1 2 3 4]))

  ($= [1 2 3 4] <*> (trans [1 2 3 4]))
  ($= [1 2 3 4] <x> (trans [1 2 3 4]))


  ;; kronecker product example
  ($= (matrix [[1 2] [3 4] [5 6]]) <x> 4)
  ($= (matrix [[1 2] [3 4] [5 6]]) <x> (matrix [[1 2] [3 4]]))
  ($= [1 2 3 4] <x> 4)

  ($= 3 > (5 * 2/7))

  (use '(incanter core datasets charts))
  (with-data (get-dataset :cars)
    (doto (scatter-plot :speed :dist :data ($where ($fn [speed dist] ($= dist / speed < 2))))
      (add-points :speed :dist :data ($where ($fn [speed dist] ($= dist / speed >= 2))))
      (add-lines ($ :speed) ($= 2 * ($ :speed)))
      view))

sourceraw docstring

$dataclj

This variable is bound to a dataset when the with-data macro is used. functions like $ and $where can use $data as a default argument.

This variable is bound to a dataset when the with-data macro is used.
functions like $ and $where can use $data as a default argument.
sourceraw docstring

$fnclj/smacro

($fn col-bindings body)

A simple macro used as syntactic sugar for defining predicate functions to be used in the $where function. The supplied arguments should be column names of a dataset. This macro performs map destructuring on the arguments.

For instance, ($fn [speed] (< speed 10)) => (fn [{:keys [speed]}] (< speed 10))

Examples: (use '(incanter core datasets)) (view ($where ($fn [speed dist] (or (> speed 20) (< dist 10))) (get-dataset :cars)))

(view ($where ($fn [speed dist] (< (/ dist speed) 2)) (get-dataset :cars)))

(use '(incanter core datasets charts)) (with-data (get-dataset :cars) (doto (scatter-plot :speed :dist :data ($where ($fn [speed dist] (< (/ dist speed) 2)))) (add-points :speed :dist :data ($where ($fn [speed dist] (>= (/ dist speed) 2)))) (add-lines ($ :speed) (mult 2 ($ :speed))) view))

(let [passed? ($fn [speed dist] (< (/ dist speed) 2)) failed? (complement passed?)] (with-data (get-dataset :cars) (doto (scatter-plot :speed :dist :data ($where passed?)) (add-points :speed :dist :data ($where failed?)) (add-lines ($ :speed) (mult 2 ($ :speed))) view)))

(use '(incanter core stats charts)) (let [above-sine? ($fn [col-0 col-1] (> col-1 (sin col-0))) below-sine? (complement above-sine?)] (with-data (conj-cols (sample-uniform 1000 :min -5 :max 5) (sample-uniform 1000 :min -1 :max 1)) (doto (function-plot sin -5 5) (add-points :col-0 :col-1 :data ($where above-sine?)) (add-points :col-0 :col-1 :data ($where below-sine?)) view)))

(view ($where ($fn [] (> (rand) 0.9)) (get-dataset :cars)))

(view ($where ($fn [Species] ($in Species #{"virginica" "setosa"})) (get-dataset :iris)))

A simple macro used as syntactic sugar for defining predicate functions to be used
in the $where function. The supplied arguments should be column names of a dataset.
This macro performs map destructuring on the arguments.

For instance,
($fn [speed] (< speed 10)) => (fn [{:keys [speed]}] (< speed 10))

Examples:
  (use '(incanter core datasets))
  (view ($where ($fn [speed dist] (or (> speed 20) (< dist 10))) (get-dataset :cars)))

  (view ($where ($fn [speed dist] (< (/ dist speed) 2)) (get-dataset :cars)))

  (use '(incanter core datasets charts))
  (with-data (get-dataset :cars)
    (doto (scatter-plot :speed :dist :data ($where ($fn [speed dist] (< (/ dist speed) 2))))
      (add-points :speed :dist :data ($where ($fn [speed dist] (>= (/ dist speed) 2))))
      (add-lines ($ :speed) (mult 2 ($ :speed)))
      view))


  (let [passed? ($fn [speed dist] (< (/ dist speed) 2))
        failed? (complement passed?)]
    (with-data (get-dataset :cars)
      (doto (scatter-plot :speed :dist :data ($where passed?))
        (add-points :speed :dist :data ($where failed?))
        (add-lines ($ :speed) (mult 2 ($ :speed)))
        view)))


  (use '(incanter core stats charts))
  (let [above-sine? ($fn [col-0 col-1] (> col-1 (sin col-0)))
        below-sine? (complement above-sine?)]
    (with-data (conj-cols (sample-uniform 1000 :min -5 :max 5)
                          (sample-uniform 1000 :min -1 :max 1))
      (doto (function-plot sin -5 5)
        (add-points :col-0 :col-1 :data ($where above-sine?))
        (add-points :col-0 :col-1 :data ($where below-sine?))
        view)))


  (view ($where ($fn [] (> (rand) 0.9)) (get-dataset :cars)))

  (view ($where ($fn [Species] ($in Species #{"virginica" "setosa"})) (get-dataset :iris)))
sourceraw docstring

$group-byclj

($group-by cols)
($group-by cols data)

Returns a map of datasets keyed by a query-map corresponding the group.

Examples:

(use '(incanter core datasets)) ($group-by :Species (get-dataset :iris))

($group-by [:hair :eye] (get-dataset :hair-eye-color))

(with-data (get-dataset :hair-eye-color) ($group-by [:hair :eye]))

Returns a map of datasets keyed by a query-map corresponding the group.

Examples:

  (use '(incanter core datasets))
  ($group-by :Species (get-dataset :iris))

  ($group-by [:hair :eye] (get-dataset :hair-eye-color))

  (with-data (get-dataset :hair-eye-color)
    ($group-by [:hair :eye]))
sourceraw docstring

$joinclj

($join [left-keys right-keys] left-data)
($join [left-keys right-keys] left-data right-data)

Returns a dataset created by right-joining two datasets. The join is based on one or more columns in the datasets. If used within the body of the with-data macro, the second dataset is optional, defaulting the the dataset bound to $data.

Examples: (use '(incanter core stats datasets charts)) (def iris (get-dataset :iris))

(def lookup (dataset [:species :species-key] [["setosa" :setosa] ["versicolor" :versicolor] ["virginica" :virginica]])) (view ($join [:species :Species] lookup iris))

(def hair-eye-color (get-dataset :hair-eye-color)) (def lookup2 (conj-cols ($ [:hair :eye :gender] hair-eye-color) (range (nrow hair-eye-color)))) (view ($join [[:col-0 :col-1 :col-2] [:hair :eye :gender]] lookup2 hair-eye-color))

(with-data hair-eye-color (view ($join [[:col-0 :col-1 :col-2] [:hair :eye :gender]] lookup2)))

(def lookup3 (dataset [:gender :hair :hair-gender] [["male" "black" :male-black] ["male" "brown" :male-brown] ["male" "red" :male-red] ["male" "blond" :male-blond] ["female" "black" :female-black] ["female" "brown" :female-brown] ["female" "red" :female-red] ["female" "blond" :female-blond]]))

(view ($join [[:gender :hair] [:gender :hair]] lookup3 hair-eye-color))

(use 'incanter.charts) (with-data (->> (get-dataset :hair-eye-color) ($where {:hair {:in #{"brown" "blond"}}}) ($rollup :sum :count [:hair :gender]) ($join [[:gender :hair] [:gender :hair]] lookup3) ($order :count :desc)) (view $data) (view (bar-chart :hair :count :group-by :gender :legend true)))

Returns a dataset created by right-joining two datasets.
The join is based on one or more columns in the datasets.
If used within the body of the with-data macro, the second
dataset is optional, defaulting the the dataset bound to $data.


Examples:
  (use '(incanter core stats datasets charts))
  (def iris (get-dataset :iris))



  (def lookup (dataset [:species :species-key] [["setosa" :setosa]
                                                ["versicolor" :versicolor]
                                                ["virginica" :virginica]]))
  (view ($join [:species :Species] lookup iris))

  (def hair-eye-color (get-dataset :hair-eye-color))
  (def lookup2 (conj-cols ($ [:hair :eye :gender] hair-eye-color) (range (nrow hair-eye-color))))
  (view ($join [[:col-0 :col-1 :col-2] [:hair :eye :gender]] lookup2 hair-eye-color))

  (with-data hair-eye-color
    (view ($join [[:col-0 :col-1 :col-2] [:hair :eye :gender]] lookup2)))


  (def lookup3 (dataset [:gender :hair :hair-gender] [["male" "black" :male-black]
                                                      ["male" "brown" :male-brown]
                                                      ["male" "red" :male-red]
                                                      ["male" "blond" :male-blond]
                                                      ["female" "black" :female-black]
                                                      ["female" "brown" :female-brown]
                                                      ["female" "red" :female-red]
                                                      ["female" "blond" :female-blond]]))

  (view ($join [[:gender :hair] [:gender :hair]] lookup3 hair-eye-color))

  (use 'incanter.charts)
  (with-data (->>  (get-dataset :hair-eye-color)
                   ($where {:hair {:in #{"brown" "blond"}}})
                   ($rollup :sum :count [:hair :gender])
                   ($join [[:gender :hair] [:gender :hair]] lookup3)
                   ($order :count :desc))
      (view $data)
      (view (bar-chart :hair :count :group-by :gender :legend true)))
sourceraw docstring

$mapclj

($map fun col-keys)
($map fun col-keys data)

This function returns a sequence resulting from mapping the given function over the value(s) for the given column key(s) of the given dataset. Like other '$*' functions, it will use $data as the default dataset if none is provided, where $data is set using the with-data macro.

Examples:

(use '(incanter core datasets)) (def cars (get-dataset :cars))

($map (fn [s] (/ s)) :speed cars) ($map (fn [s d] (/ s d)) [:speed :dist] cars)

(with-data (get-dataset :cars) (view ($map (fn [s] (/ s)) :speed)) (view ($map (fn [s d] (/ s d)) [:speed :dist])))

;; calculate the speed to dist ratio and append as new column to dataset (with-data (get-dataset :cars) (conj-cols $data ($map (fn [s d] (/ s d)) [:speed :dist])))

This function returns a sequence resulting from mapping the given function over
the value(s) for the given column key(s) of the given dataset.
Like other '$*' functions, it will use $data as the default dataset
if none is provided, where $data is set using the with-data macro.

Examples:

  (use '(incanter core datasets))
  (def cars (get-dataset :cars))

  ($map (fn [s] (/ s)) :speed cars)
  ($map (fn [s d] (/ s d)) [:speed :dist] cars)

  (with-data (get-dataset :cars)
    (view ($map (fn [s] (/ s)) :speed))
    (view ($map (fn [s d] (/ s d)) [:speed :dist])))

  ;; calculate the speed to dist ratio and append as new column to dataset
  (with-data (get-dataset :cars)
    (conj-cols $data ($map (fn [s d] (/ s d)) [:speed :dist])))
sourceraw docstring

$orderclj

($order cols order)
($order cols order data)

Sorts a dataset by the given columns in either ascending (:asc) or descending (:desc) order. If used within a the body of the with-data macro, the data argument is optional, defaulting to the dataset bound to the variable $data.

Examples:

(use '(incanter core charts datasets)) (def iris (get-datset :iris)) (view ($order :Sepal.Length :asc iris)) (view ($order [:Sepal.Width :Sepal.Length] :desc iris))

(with-data (get-dataset :iris) (view ($order [:Petal.Length :Sepal.Length] :desc)))

Sorts a dataset by the given columns in either ascending (:asc)
or descending (:desc) order. If used within a the body of
the with-data macro, the data argument is optional, defaulting
to the dataset bound to the variable $data.

Examples:

  (use '(incanter core charts datasets))
  (def iris (get-datset :iris))
  (view ($order :Sepal.Length :asc iris))
  (view ($order [:Sepal.Width :Sepal.Length] :desc iris))

  (with-data (get-dataset :iris)
    (view ($order [:Petal.Length :Sepal.Length] :desc)))

sourceraw docstring

$rollupclj

($rollup summary-fun col-name group-by)
($rollup summary-fun col-name group-by data)

Returns a dataset that uses the given summary function (or function identifier keyword) to rollup the given column based on a set of group-by columns. The summary function should accept a single sequence of values and return a single summary value. Alternatively, you can provide a keyword identifier of a set of built-in functions including:

:max -- the maximum value of the data in each group :min -- the minimum value of the data in each group :sum -- the sum of the data in each group :count -- the number of elements in each group :mean -- the mean of the data in each group

Like the other '$' dataset functions, $rollup will use the dataset bound to $data (see the with-data macro) if a dataset is not provided as an argument.

Examples:

(use '(incanter core datasets))

(def iris (get-dataset :iris)) ($rollup :mean :Sepal.Length :Species iris) ($rollup :count :Sepal.Length :Species iris) ($rollup :max :Sepal.Length :Species iris) ($rollup :min :Sepal.Length :Species iris)

;; The following is an example using a custom function, but since all the ;; iris measurements are positive, the built-in mean function could have ;; been used instead.

(use 'incanter.stats) ($rollup #(mean (abs %)) :Sepal.Width :Species iris)

($rollup sd :Sepal.Length :Species iris) ($rollup variance :Sepal.Length :Species iris) ($rollup median :Sepal.Length :Species iris)

(def hair-eye-color (get-dataset :hair-eye-color)) ($rollup :mean :count [:hair :eye] hair-eye-color)

(use 'incanter.charts) (with-data ($rollup :mean :Sepal.Length :Species iris) (view (bar-chart :Species :Sepal.Length)))

;; the following examples use the built-in data set called hair-eye-color.

(with-data ($rollup :mean :count [:hair :eye] hair-eye-color) (view (bar-chart :hair :count :group-by :eye :legend true)))

(with-data (->> (get-dataset :hair-eye-color) ($where {:hair {:in #{"brown" "blond"}}}) ($rollup :sum :count [:hair :eye]) ($order :count :desc)) (view $data) (view (bar-chart :hair :count :group-by :eye :legend true)))

Returns a dataset that uses the given summary function (or function identifier keyword)
to rollup the given column based on a set of group-by columns. The summary function
should accept a single sequence of values and return a single summary value. Alternatively,
you can provide a keyword identifier of a set of built-in functions including:

:max -- the maximum value of the data in each group
:min -- the minimum value of the data in each group
:sum -- the sum of the data in each group
:count -- the number of elements in each group
:mean -- the mean of the data in each group


Like the other '$' dataset functions, $rollup will use the dataset bound to $data
(see the with-data macro) if a dataset is not provided as an argument.

Examples:

  (use '(incanter core datasets))

  (def iris (get-dataset :iris))
  ($rollup :mean :Sepal.Length :Species iris)
  ($rollup :count :Sepal.Length :Species iris)
  ($rollup :max :Sepal.Length :Species iris)
  ($rollup :min :Sepal.Length :Species iris)

  ;; The following is an example using a custom function, but since all the
  ;; iris measurements are positive, the built-in mean function could have
  ;; been used instead.

  (use 'incanter.stats)
  ($rollup #(mean (abs %)) :Sepal.Width :Species iris)

  ($rollup sd :Sepal.Length :Species iris)
  ($rollup variance :Sepal.Length :Species iris)
  ($rollup median :Sepal.Length :Species iris)

  (def hair-eye-color (get-dataset :hair-eye-color))
  ($rollup :mean :count [:hair :eye] hair-eye-color)

  (use 'incanter.charts)
  (with-data ($rollup :mean :Sepal.Length :Species iris)
    (view (bar-chart :Species :Sepal.Length)))

   ;; the following examples use the built-in data set called hair-eye-color.

   (with-data ($rollup :mean :count [:hair :eye] hair-eye-color)
     (view (bar-chart :hair :count :group-by :eye :legend true)))

   (with-data (->>  (get-dataset :hair-eye-color)
                    ($where {:hair {:in #{"brown" "blond"}}})
                    ($rollup :sum :count [:hair :eye])
                    ($order :count :desc))
     (view $data)
     (view (bar-chart :hair :count :group-by :eye :legend true)))
sourceraw docstring

$whereclj

($where query-map)
($where query-map data)

An alias to (query-dataset (second args) (first args)). If given only a single argument, it will use the $data binding for the first argument, which is set with the with-data macro.

Examples:

(use '(incanter core datasets))

(def cars (get-dataset :cars)) ($where {:speed 10} cars)

;; use the with-data macro and the one arg version of $where (with-data cars (view ($where {:speed {:$gt -10 :$lt 10}})) (view ($where {:dist {:$in #{10 12 16}}})) (view ($where {:dist {:$nin #{10 12 16}}})))

;; create a dataset where :speed greater than 10 or less than -10 (with-data (get-dataset :cars) (view (-> ($where {:speed {:$gt 20}}) (conj-rows ($where {:speed {:$lt 10}})))))

An alias to (query-dataset (second args) (first args)). If given only a single argument,
it will use the $data binding for the first argument, which is set with
the with-data macro.

Examples:

  (use '(incanter core datasets))

  (def cars (get-dataset :cars))
  ($where {:speed 10} cars)

  ;; use the with-data macro and the one arg version of $where
  (with-data cars
    (view ($where {:speed {:$gt -10 :$lt 10}}))
    (view ($where {:dist {:$in #{10 12 16}}}))
    (view ($where {:dist {:$nin #{10 12 16}}})))

  ;; create a dataset where :speed greater than 10 or less than -10
  (with-data (get-dataset :cars)
    (view (-> ($where {:speed {:$gt 20}})
                    (conj-rows ($where {:speed {:$lt 10}})))))
sourceraw docstring

absclj

(abs A)

Returns the absolute value of the elements in the given matrix, sequence or number. Equivalent to R's abs function.

Returns the absolute value of the elements in the given matrix, sequence or number.
Equivalent to R's abs function.
sourceraw docstring

acosclj

(acos A)

Returns the arc cosine of the elements in the given matrix, sequence or number. Equivalent to R's acos function.

Returns the arc cosine of the elements in the given matrix, sequence or number.
Equivalent to R's acos function.
sourceraw docstring

add-columnclj

(add-column column-name values)
(add-column column-name values data)

Adds a column, with given values, to a dataset.

Adds a column, with given values, to a dataset.
sourceraw docstring

add-derived-columnclj

(add-derived-column column-name from-columns f)
(add-derived-column column-name from-columns f data)

This function adds a column to a dataset that is a function of existing columns. If no dataset is provided, $data (bound by the with-data macro) will be used. f should be a function of the from-columns, with arguments in that order.

Examples: (use '(incanter core datasets)) (def cars (get-dataset :cars))

(add-derived-column :dist-over-speed [:dist :speed] (fn [d s] (/ d s)) cars)

(with-data (get-dataset :cars) (view (add-derived-column :speed**-1 [:speed] #(/ 1.0 %))))

This function adds a column to a dataset that is a function of
existing columns. If no dataset is provided, $data (bound by the
with-data macro) will be used. f should be a function of the
from-columns, with arguments in that order.

Examples:
  (use '(incanter core datasets))
  (def cars (get-dataset :cars))

  (add-derived-column :dist-over-speed [:dist :speed] (fn [d s] (/ d s)) cars)

  (with-data (get-dataset :cars)
    (view (add-derived-column :speed**-1 [:speed] #(/ 1.0 %))))
sourceraw docstring

aggregateclj

(aggregate fields group-by & {:keys [dataset rollup-fun] :or {rollup-fun :sum}})

Performs the aggregation of the data in given dataset using the specified rollup function. The fields parameter defines column(s) on which the rollup will happen, and group-by specifies the column(s) for joining the results. The fields & group-by parameters could be single values or collections. The dataset is provided by the :dataset parameter, if it's not provided, then the $data is used. The rollup function is provided by :rollup-fun parameter, if it's not provided, then the :sum is used.

(aggregate [:uptake :conc] :Type :dataset (get-dataset :co2)) (aggregate [:uptake :conc] [:Type] :dataset (get-dataset :co2) :rollup-fun :min)

Performs the aggregation of the data in given dataset using the specified rollup function.
The fields parameter defines column(s) on which the rollup will happen, and group-by
specifies the column(s) for joining the results.  The fields & group-by parameters could be
single values or collections.  The dataset is provided by the :dataset parameter, if it's not
provided, then the $data is used.  The rollup function is provided by :rollup-fun parameter,
if it's not provided, then the :sum is used.

  (aggregate [:uptake :conc] :Type :dataset (get-dataset :co2))
  (aggregate [:uptake :conc] [:Type] :dataset (get-dataset :co2) :rollup-fun :min)
sourceraw docstring

asinclj

(asin A)

Returns the arc sine of the elements in the given matrix, sequence or number. Equivalent to R's asin function.

Returns the arc sine of the elements in the given matrix, sequence or number.
Equivalent to R's asin function.
sourceraw docstring

atanclj

(atan A)

Returns the arc tangent of the elements in the given matrix, sequence or number. Equivalent to R's atan function.

Returns the arc tangent of the elements in the given matrix, sequence or number.
Equivalent to R's atan function.
sourceraw docstring

atan2clj

(atan2 & args)

Returns the atan2 of the elements in the given matrices, sequences or numbers. Equivalent to R's atan2 function.

Returns the atan2 of the elements in the given matrices, sequences or numbers.
Equivalent to R's atan2 function.
sourceraw docstring

betaclj

(beta a b)
Equivalent to R's beta function.

References:
  http://incanter.org/docs/parallelcolt/api/cern/jet/stat/tdouble/Gamma.html
sourceraw docstring

bind-columnsclj

(bind-columns & args)

Returns the matrix resulting from concatenating the given matrices and/or sequences by their columns. Equivalent to R's cbind.

Examples: (def A (matrix [[1 2 3] [4 5 6] [7 8 9]]))

(def B (matrix [10 11 12]))

(bind-columns A B)

(bind-columns [1 2 3 4] [5 6 7 8])

Returns the matrix resulting from concatenating the given matrices
and/or sequences by their columns. Equivalent to R's cbind.

Examples:
(def A (matrix [[1 2 3]
                [4 5 6]
                [7 8 9]]))

(def B (matrix [10 11 12]))

(bind-columns A B)

(bind-columns [1 2 3 4] [5 6 7 8])
sourceraw docstring

bind-rowsclj

(bind-rows & args)

Returns the matrix resulting from concatenating the given matrices and/or sequences by their rows. Equivalent to R's rbind.

Examples: (def A (matrix [[1 2 3] [4 5 6] [7 8 9]]))

(def B (matrix [[10 11 12] [13 14 15]]))

(bind-rows A B)

(bind-rows [1 2 3 4] [5 6 7 8])

Returns the matrix resulting from concatenating the given matrices
and/or sequences by their rows. Equivalent to R's rbind.

Examples:
(def A (matrix [[1 2 3]
                [4 5 6]
                [7 8 9]]))

(def B (matrix [[10 11 12]
                [13 14 15]]))

(bind-rows A B)

(bind-rows [1 2 3 4] [5 6 7 8])
sourceraw docstring

categorical-varclj

(categorical-var & {:keys [data ordered? labels levels] :or {ordered? false}})

Returns a categorical variable based on the values in the given collection. Equivalent to R's factor function.

Options: :data (default nil) factors will be extracted from the given data. :ordered? (default false) indicates that the variable is ordinal. :labels (default (sort (into #{} data))) :levels (range (count labels))

Examples: (categorical-var :data [:a :a :c :b :a :c :c]) (categorical-var :labels [:a :b :c]) (categorical-var :labels [:a :b :c] :levels [10 20 30]) (categorical-var :levels [1 2 3])

Returns a categorical variable based on the values in the given collection.
Equivalent to R's factor function.

Options:
  :data (default nil) factors will be extracted from the given data.
  :ordered? (default false) indicates that the variable is ordinal.
  :labels (default (sort (into #{} data)))
  :levels (range (count labels))

Examples:
  (categorical-var :data [:a :a :c :b :a :c :c])
  (categorical-var :labels [:a :b :c])
  (categorical-var :labels [:a :b :c] :levels [10 20 30])
  (categorical-var :levels [1 2 3])

sourceraw docstring

chooseclj

(choose n k)

Returns number of k-combinations (each of size k) from a set S with n elements (size n), which is the binomial coefficient (also known as the 'choose function') [wikipedia] choose = n!/(k!(n - k)!)

Equivalent to R's choose function.

Examples: (choose 25 6) ; => 177,100

References: http://incanter.org/docs/parallelcolt/api/cern/jet/math/tdouble/DoubleArithmetic.html http://en.wikipedia.org/wiki/Combination

Returns number of k-combinations (each of size k) from a set S with
n elements (size n), which is the binomial coefficient (also known
as the 'choose function') [wikipedia]
      choose = n!/(k!(n - k)!)

Equivalent to R's choose function.

Examples:
  (choose 25 6) ; => 177,100

References:
  http://incanter.org/docs/parallelcolt/api/cern/jet/math/tdouble/DoubleArithmetic.html
  http://en.wikipedia.org/wiki/Combination
sourceraw docstring

col-namescljdeprecated

(col-names data)

If given a dataset, it returns its column names. If given a dataset and a sequence of column names, it returns a dataset with the given column names.

Examples: (use '(incanter core datasets)) (def data (get-dataset :cars)) (col-names data)

Deprecated. Please use clojure.core.matrix.dataset/column-names instead.

If given a dataset, it returns its column names. If given a dataset and a sequence
of column names, it returns a dataset with the given column names.

Examples:
  (use '(incanter core datasets))
  (def data (get-dataset :cars))
  (col-names data)

Deprecated. Please use clojure.core.matrix.dataset/column-names instead.
sourceraw docstring

conditionclj

(condition mat)

Returns the two norm condition number, which is max(S) / min(S), where S is the diagonal matrix of singular values from an SVD decomposition.

Examples: (use 'incanter.core) (def foo (matrix (range 9) 3)) (condition foo)

References: http://en.wikipedia.org/wiki/Condition_number

Returns the two norm condition number, which is max(S) / min(S), where S is the diagonal matrix of singular values from an SVD decomposition.


Examples:
  (use 'incanter.core)
  (def foo (matrix (range 9) 3))
  (condition foo)

References:
  http://en.wikipedia.org/wiki/Condition_number
sourceraw docstring

conj-colsclj

(conj-cols & args)

Returns a dataset created by merging the given datasets and/or collections. There must be the same number of rows in each dataset and/or collections. Column names may be changed in order to prevent naming conflicts in the conjed dataset.

Examples: (use '(incanter core datasets)) (def cars (get-dataset :cars)) (def x (sel cars :cols 0)) (view (conj-cols cars cars)) (view (conj-cols cars x)) (view (conj-cols (range (nrow cars)) cars)) (view (conj-cols (range 10) (range 10))) (view (conj-cols {:a 1 :b 2} {:c 1 :d 2}))

Returns a dataset created by merging the given datasets and/or collections.
There must be the same number of rows in each dataset and/or
collections.  Column names may be changed in order to prevent
naming conflicts in the conjed dataset.

Examples:
  (use '(incanter core datasets))
  (def cars (get-dataset :cars))
  (def x (sel cars :cols 0))
  (view (conj-cols cars cars))
  (view (conj-cols cars x))
  (view (conj-cols (range (nrow cars)) cars))
  (view (conj-cols (range 10) (range 10)))
  (view (conj-cols {:a 1 :b 2} {:c 1 :d 2}))
sourceraw docstring

conj-rowscljdeprecated

(conj-rows & args)

Returns a dataset created by combining the rows of the given datasets and/or collections.

Examples:

(use '(incanter core datasets)) (def cars (get-dataset :cars)) (view (conj-rows (to-dataset (range 5)) (to-dataset (range 5 10)))) (view (conj-rows cars cars)) (view (conj-rows [[1 2] [3 4]] [[5 6] [7 8]])) (view (conj-rows [{:a 1 :b 2} {:a 3 :b 4}] [[5 6] [7 8]])) (view (conj-rows (to-dataset [{:a 1 :b 2} {:a 3 :b 4}]) [[5 6] [7 8]])) (conj-rows (range 5) (range 5 10))

Deprecated. Please use clojure.core.matrix/conj-rows instead.

Returns a dataset created by combining the rows of the given datasets and/or collections.

Examples:

  (use '(incanter core datasets))
  (def cars (get-dataset :cars))
  (view (conj-rows (to-dataset (range 5)) (to-dataset (range 5 10))))
  (view (conj-rows cars cars))
  (view (conj-rows [[1 2] [3 4]] [[5 6] [7 8]]))
  (view (conj-rows [{:a 1 :b 2} {:a 3 :b 4}] [[5 6] [7 8]]))
  (view (conj-rows (to-dataset [{:a 1 :b 2} {:a 3 :b 4}]) [[5 6] [7 8]]))
  (conj-rows (range 5) (range 5 10))

Deprecated. Please use clojure.core.matrix/conj-rows instead.
sourceraw docstring

copycljdeprecated

(copy mat)

Deprecated. Please use clojure.core.matrix/clone instead.

Deprecated. Please use clojure.core.matrix/clone instead.
sourceraw docstring

cosclj

(cos A)

Returns the cosine of the elements in the given matrix, sequence or number. Equivalent to R's cos function.

Returns the cosine of the elements in the given matrix, sequence or number.
Equivalent to R's cos function.
sourceraw docstring

cumulative-sumclj

(cumulative-sum coll)

Returns a sequence of cumulative sum for the given collection. For instance The first value equals the first value of the argument, the second value is the sum of the first two arguments, the third is the sum of the first three arguments, etc.

Examples: (use 'incanter.core) (cumulative-sum (range 100))

Returns a sequence of cumulative sum for the given collection. For instance
The first value equals the first value of the argument, the second value is
the sum of the first two arguments, the third is the sum of the first three
arguments, etc.

Examples:
  (use 'incanter.core)
  (cumulative-sum (range 100))
sourceraw docstring

data-tablecljmultimethod

Creates javax.swing.JTable from dataset or matrix.

JTable column names for datasets will be the datset's column names. For matrices, an optional argument :column-names can be used to set the resulting column names. Otherweise incrementing indices are used (0,1,2,..).

Example:

(data-table (clojure.core.matrix/matrix [[1 2 3][4 5 6]]) :column-names ["first col" "second col" "third col"])

Creates javax.swing.JTable from dataset or matrix.

JTable column names for datasets will be the datset's column names. For
matrices, an optional argument :column-names can be used to set the resulting
column names. Otherweise incrementing indices are used (0,1,2,..).

Example:

(data-table (clojure.core.matrix/matrix [[1 2 3][4 5 6]])
  :column-names ["first col" "second col" "third col"])
sourceraw docstring

datasetclj

(dataset m)
(dataset column-names m)

Returns a record of type clojure.core.matrix.impl.dataset.DataSet. Creates dataset from: column names and seq of rows column names and seq of row maps map of columns with associated list of values. matrix - its columns will be used as dataset columns and incrementing Long values starting from 0, i.e. 0, 1, 2, etc will be used as column names. seq of maps

Deprecated. Please use clojure.core.matrix.dataset/dataset instead.

Returns a record of type clojure.core.matrix.impl.dataset.DataSet.
 Creates dataset from:
  column names and seq of rows
  column names and seq of row maps
  map of columns with associated list of values.
  matrix - its columns will be used as dataset columns and incrementing Long values starting from 0, i.e. 0, 1, 2, etc will be used as column names.
  seq of maps

Deprecated. Please use clojure.core.matrix.dataset/dataset instead.
sourceraw docstring

dataset?cljdeprecated

(dataset? obj)

Determines if obj is of type clojure.core.matrix.impl.dataset.Dataset.

Deprecated. Please use clojure.core.matrix.dataset/dataset? instead.

Determines if obj is of type clojure.core.matrix.impl.dataset.Dataset.

Deprecated. Please use clojure.core.matrix.dataset/dataset? instead.
sourceraw docstring

decomp-choleskycljdeprecated

(decomp-cholesky mat)
(decomp-cholesky mat options)

Returns the Cholesky decomposition of the given matrix. Equivalent to R's chol function.

Returns: a map containing two matrices with the keys [:L :L*] such that

Such that: M = L.L*

Where

  • M must be a hermitian, positive definite matrix
  • L is a lower triangular matrix
  • L* is the conjugate transpose of L

If :return parameter is specified in options map, it returns only specified keys.

Examples: (use '(incanter core stats charts datasets)) ;; load the iris dataset (def iris (to-matrix (get-dataset :iris))) ;; take the Cholesky decomposition of the correlation matrix of the iris data. (let [{:keys [L L*]} (decomp-cholesky (correlation iris))]) (let [{:keys [L*]} (decomp-cholesky (correlation iris {:return [:L*]}))])

References: http://en.wikipedia.org/wiki/Cholesky_decomposition

Deprecated. Please use clojure.core.matrix.linear/cholesky instead.

Returns the Cholesky decomposition of the given matrix. Equivalent to R's
chol function.

Returns:
a map containing two matrices with the keys [:L :L*] such that

Such that:
    M = L.L*

Where
   - M must be a hermitian, positive definite matrix
   - L is a lower triangular matrix
   - L* is the conjugate transpose of L

If :return parameter is specified in options map, it returns only specified keys.

Examples:
(use '(incanter core stats charts datasets))
;; load the iris dataset
(def iris (to-matrix (get-dataset :iris)))
;; take the Cholesky decomposition of the correlation matrix of the iris data.
(let [{:keys [L L*]} (decomp-cholesky (correlation iris))])
(let [{:keys [L*]} (decomp-cholesky (correlation iris {:return [:L*]}))])

References:
  http://en.wikipedia.org/wiki/Cholesky_decomposition

Deprecated. Please use clojure.core.matrix.linear/cholesky instead.
sourceraw docstring

decomp-eigenvaluecljdeprecated

(decomp-eigenvalue mat)
(decomp-eigenvalue mat options)

Returns a map containing matrices for each of the the keys [:Q :rA :iA] such that:

M = Q.A.Q-1

Where:

  • Q is a matrix where each column is the ith normalised eigenvector of M
  • rA is a vector whose elements are the real numbers of eigenvalues.
  • iA is a vector whose elements are the imaginary units of eigenvalues.
  • Q⁻-1 is the inverse of Q

If :return parameter is specified in options map, it returns only specified keys. if :symmetric parameter is true in options map, symmetric eigenvalue decomposition will be performed.

Examples:

(use 'incanter.core) (def foo (matrix (range 9) 3)) (let [{:keys [Q rA iA]} (decomp-eigenvalue M)]) (let [{:keys [Q rA iA]} (decomp-eigenvalue M {:symmetric true})]) (let [{:keys [Q rA]} (decomp-eigenvalue M {:return [:Q :rA]})])

References: http://en.wikipedia.org/wiki/Eigenvalue_decomposition

Deprecated. Please use clojure.core.matrix.linear/eigen instead.

Returns a map containing matrices for each of the the keys [:Q :rA :iA] such that:

    M = Q.A.Q-1

 Where:
   - Q is a matrix where each column is the ith normalised eigenvector of M
   - rA is a vector whose elements are the real numbers of eigenvalues.
   - iA is a vector whose elements are the imaginary units of eigenvalues.
   - Q⁻-1 is the inverse of Q

 If :return parameter is specified in options map, it returns only specified keys.
 if :symmetric parameter is true in options map, symmetric eigenvalue decomposition will be performed.

Examples:

(use 'incanter.core)
(def foo (matrix (range 9) 3))
(let [{:keys [Q rA iA]} (decomp-eigenvalue M)])
(let [{:keys [Q rA iA]} (decomp-eigenvalue M {:symmetric true})])
(let [{:keys [Q rA]} (decomp-eigenvalue M {:return [:Q :rA]})])

References:
http://en.wikipedia.org/wiki/Eigenvalue_decomposition

Deprecated. Please use clojure.core.matrix.linear/eigen instead.
sourceraw docstring

decomp-lucljdeprecated

(decomp-lu mat)
(decomp-lu mat options)

Computes the LU(P) decomposition of a matrix with partial row pivoting. Returns a map containing the keys [:L :U :P], such that:

 P.A = L.U

Where

  • L is a lower triangular matrix
  • U is an upper triangular matrix
  • P is a permutation matrix

Examples:

(use 'incanter.core) (def foo (matrix (range 9) 3)) (let [{:keys [L U P]} (decomp-lu A)])

References: http://en.wikipedia.org/wiki/LU_decomposition http://mikiobraun.github.io/jblas/javadoc/org/jblas/Decompose.LUDecomposition.html

Deprecated. Please use clojure.core.matrix.linear/lu instead.

Computes the LU(P) decomposition of a matrix with partial row pivoting.
Returns a map containing the keys [:L :U :P], such that:

     P.A = L.U

 Where
   - L is a lower triangular matrix
   - U is an upper triangular matrix
   - P is a permutation matrix

Examples:

(use 'incanter.core)
(def foo (matrix (range 9) 3))
(let [{:keys [L U P]} (decomp-lu A)])

References:
  http://en.wikipedia.org/wiki/LU_decomposition
  http://mikiobraun.github.io/jblas/javadoc/org/jblas/Decompose.LUDecomposition.html

Deprecated. Please use clojure.core.matrix.linear/lu instead.
sourceraw docstring

decomp-qrcljdeprecated

(decomp-qr mat)
(decomp-qr mat options)

Returns the QR decomposition of the given matrix. Equivalent to R's qr function. Returns a map containing matrices with the keys [:Q :R] such that:

  M = Q.R

Where: - Q is an orthogonal matrix - R is an upper triangular matrix (= right triangular matrix)

If :return parameter is specified in options map, it returns only specified keys. If :compact parameter is specified in options map, compact versions of matrices are returned.

Examples:

(use 'incanter.core) (def foo (matrix (range 9) 3)) (let [{:keys [Q R]} (qr M)]) (let [{:keys [R]} (qr M {:return [:R]})])

References: http://en.wikipedia.org/wiki/QR_decomposition

Deprecated. Please use clojure.core.matrix.linear/qr instead.

Returns the QR decomposition of the given matrix. Equivalent to R's qr function.
Returns a map containing matrices with the keys [:Q :R] such that:

      M = Q.R

Where:
      - Q is an orthogonal matrix
      - R is an upper triangular matrix (= right triangular matrix)

If :return parameter is specified in options map, it returns only specified keys.
If :compact parameter is specified in options map, compact versions of matrices are returned.

Examples:

(use 'incanter.core)
(def foo (matrix (range 9) 3))
(let [{:keys [Q R]} (qr M)])
(let [{:keys [R]} (qr M {:return [:R]})])

References:
http://en.wikipedia.org/wiki/QR_decomposition

Deprecated. Please use clojure.core.matrix.linear/qr instead.
sourceraw docstring

decomp-svdcljdeprecated

(decomp-svd mat)
(decomp-svd mat options)

Returns the Singular Value Decomposition (SVD) of the given matrix. Equivalent to R's svd function.

If :return parameter is specified in options map, it returns only specified keys. By default returns a map containing: :S -- the diagonal matrix of singular values S (the diagonal in vector form) :U -- the left singular vectors U :V* -- the right singular vectors V

Examples:

(use 'incanter.core) (def foo (matrix (range 9) 3)) (let [{:keys [U S V*]} (decomp-svd foo)] ....) (let [{:keys [S]} (decomp-svd foo {:return [:S]})] ....)

References: http://en.wikipedia.org/wiki/Singular_value_decomposition

Deprecated. Please use clojure.core.matrix.linear/svd instead.

Returns the Singular Value Decomposition (SVD) of the given matrix. Equivalent to
R's svd function.

If :return parameter is specified in options map, it returns only specified keys.
By default returns a map containing:
:S -- the diagonal matrix of singular values S (the diagonal in vector form)
:U -- the left singular vectors U
:V* -- the right singular vectors V

Examples:

(use 'incanter.core)
(def foo (matrix (range 9) 3))
(let [{:keys [U S V*]} (decomp-svd foo)] ....)
(let [{:keys [S]} (decomp-svd foo {:return [:S]})] ....)

References:
http://en.wikipedia.org/wiki/Singular_value_decomposition

Deprecated. Please use clojure.core.matrix.linear/svd instead.
sourceraw docstring

deshapeclj

(deshape & {:keys [data remove-na group-by merge] :or {remove-na true}})

Returns a dataset where the columns identified by :merge are collapsed into two columns called :variable and :value. The values in these columns are grouped by the columns identified by :group-by.

Examples:

(use '(incanter core charts datasets)) (with-data (->> (deshape :merge [:Ahmadinejad :Rezai :Karrubi :Mousavi] :group-by :Region :data (get-dataset :iran-election)) ($order :value :desc)) (view $data) (view (bar-chart :variable :value :group-by :Region :legend true))

(view (bar-chart :Region :value :group-by :variable
                 :legend true :vertical false))

(view (bar-chart :Region :value :legend true :vertical false
                 :data ($order :value :desc ($rollup :sum :value :Region)))))



(def data (to-dataset [{:subject "John Smith" :time 1 :age 33 :weight 90 :height 1.87}
                       {:subject "Mary Smith" :time 1 :height 1.54}]))
(view data)
(view (deshape :group-by [:subject :time] :merge [:age :weight :height] :data data))
(view (deshape :merge [:age :weight :height] :data data))
(view (deshape :group-by [:subject :time] :data data))

(view (deshape :merge [:age :weight :height] :remove-na false :data data))
Returns a dataset where the columns identified by :merge are collapsed into
two columns called :variable and :value. The values in these columns are grouped
by the columns identified by :group-by.

Examples:

  (use '(incanter core charts datasets))
  (with-data (->> (deshape :merge [:Ahmadinejad :Rezai :Karrubi :Mousavi]
                            :group-by :Region
                            :data (get-dataset :iran-election))
                  ($order :value :desc))
    (view $data)
    (view (bar-chart :variable :value :group-by :Region :legend true))

    (view (bar-chart :Region :value :group-by :variable
                     :legend true :vertical false))

    (view (bar-chart :Region :value :legend true :vertical false
                     :data ($order :value :desc ($rollup :sum :value :Region)))))



    (def data (to-dataset [{:subject "John Smith" :time 1 :age 33 :weight 90 :height 1.87}
                           {:subject "Mary Smith" :time 1 :height 1.54}]))
    (view data)
    (view (deshape :group-by [:subject :time] :merge [:age :weight :height] :data data))
    (view (deshape :merge [:age :weight :height] :data data))
    (view (deshape :group-by [:subject :time] :data data))

    (view (deshape :merge [:age :weight :height] :remove-na false :data data))
sourceraw docstring

detcljdeprecated

(det mat)

Returns the determinant of the given matrix. Equivalent to R's det function.

References: http://en.wikipedia.org/wiki/LU_decomposition

Deprecated. Please use clojure.core.matrix/det instead.

Returns the determinant of the given matrix. Equivalent
to R's det function.

 References:
  http://en.wikipedia.org/wiki/LU_decomposition

Deprecated. Please use clojure.core.matrix/det instead.
sourceraw docstring

diagcljdeprecated

(diag m)

If given a matrix, diag returns a sequence of its diagonal elements. If given a sequence, it returns a matrix with the sequence's elements on its diagonal. Equivalent to R's diag function.

Examples: (diag [1 2 3 4]) ; produces diagonal matrix

(def A (matrix [[1 2 3] [4 5 6] [7 8 9]])) (diag A) ;; returns elements on main diagonal

Deprecated. Please use clojure.core.matrix/main-diagonal for getting elements on main diagonal and clojure.core.matrix/diagonal-matrix for creating diagonal matrix instead.

If given a matrix, diag returns a sequence of its diagonal elements.
If given a sequence, it returns a matrix with the sequence's elements
on its diagonal. Equivalent to R's diag function.

Examples:
(diag [1 2 3 4]) ; produces diagonal matrix

(def A (matrix [[1 2 3]
[4 5 6]
[7 8 9]]))
(diag A) ;; returns elements on main diagonal

Deprecated. Please use clojure.core.matrix/main-diagonal for getting elements on main diagonal
and clojure.core.matrix/diagonal-matrix for creating diagonal matrix instead.
sourceraw docstring

dimcljdeprecated

(dim mat)

Returns a vector with the number of rows and columns of the given matrix.

Deprecated. Please use clojure.core.matrix/dimensionality instead.

Returns a vector with the number of rows and columns of the given matrix.

Deprecated. Please use clojure.core.matrix/dimensionality instead.
sourceraw docstring

dispatchclj

(dispatch obj)

Dispatch function for multimethods

Dispatch function for multimethods
sourceraw docstring

divcljdeprecated

(div & args)

Performs element-by-element division on multiple matrices, sequences and/or numbers. Equivalent to R's / operator. Examples:

(def A (matrix [[1 2 3] [4 5 6] [7 8 9]])) (div A A A) (div A 2) (div 2 A) (div [1 2 3] [1 2 3]) (div [1 2 3] 2) (div 2 [1 2 3])

(div [1 2 3]) ; returns [1 1/2 13]

Deprecated. Please use clojure.core.matrix/div or clojure.core.matrix.operators// instead.

Performs element-by-element division on multiple matrices, sequences
and/or numbers. Equivalent to R's / operator.
Examples:

(def A (matrix [[1 2 3]
                [4 5 6]
                [7 8 9]]))
(div A A A)
(div A 2)
(div 2 A)
(div [1 2 3] [1 2 3])
(div [1 2 3] 2)
(div 2 [1 2 3])

(div [1 2 3]) ; returns [1 1/2 13]

Deprecated. Please use clojure.core.matrix/div or
clojure.core.matrix.operators// instead.
sourceraw docstring

expclj

(exp A)

Returns the exponential of the elements in the given matrix, sequence or number. Equivalent to R's exp function.

Returns the exponential of the elements in the given matrix, sequence or number.
Equivalent to R's exp function.
sourceraw docstring

factorialclj

(factorial k)

Returns the factorial of k (k must be a positive integer). Equivalent to R's factorial function.

Examples: (factorial 6)

References: http://incanter.org/docs/parallelcolt/api/cern/jet/math/tdouble/DoubleArithmetic.html http://en.wikipedia.org/wiki/Factorial

Returns the factorial of k (k must be a positive integer). Equivalent to R's
factorial function.

Examples:
  (factorial 6)

References:
  http://incanter.org/docs/parallelcolt/api/cern/jet/math/tdouble/DoubleArithmetic.html
  http://en.wikipedia.org/wiki/Factorial

sourceraw docstring

fill-missingclj

(fill-missing maps)
source

gammaclj

(gamma x)
Equivalent to R's gamma function.

References:
  http://incanter.org/docs/parallelcolt/api/cern/jet/stat/tdouble/Gamma.html
sourceraw docstring

get-categoriesclj

(get-categories cols data)

Given a dataset and one or more column keys, returns the set of categories for them.

Examples:

(use '(incanter core datasets)) (get-categories :eye (get-dataset :hair-eye-color)) (get-categories [:eye :hair] (get-dataset :hair-eye-color))

Given a dataset and one or more column keys, returns the set of categories for them.

Examples:

  (use '(incanter core datasets))
  (get-categories :eye (get-dataset :hair-eye-color))
  (get-categories [:eye :hair] (get-dataset :hair-eye-color))
sourceraw docstring

grid-applyclj

(grid-apply f x-min x-max y-min y-max)
(grid-apply f x-min x-max y-min y-max x-res y-res)

Applies the given function f, that accepts two arguments, to a grid defined by rectangle bounded x-min, y-min, x-max, y-max and returns a sequence of three sequences representing the cartesian product of x and y and z calculated by applying f to the combinations of x and y.

Defaults to a 100x100 'grid', where the x and y axes are sampled evenly accorinding to the grid. Callers may supply their own horizontal and vertical sampling resolutions via x-res and y-res. In cases where the sampling resolution is lower than the range of actual values, a sparse response surface will result.

Applies the given function f, that accepts two arguments, to a grid
defined by rectangle bounded x-min, y-min, x-max, y-max and returns a
sequence of three sequences representing the cartesian product of x and y
and z calculated by applying f to the combinations of x and y.

Defaults to a 100x100 'grid', where the x and y axes are sampled
evenly accorinding to the grid.  Callers may supply their own
horizontal and vertical sampling resolutions via x-res and
y-res.  In cases where the sampling resolution is lower
than the range of actual values, a sparse response
surface will result.
sourceraw docstring

group-onclj

(group-on mat on-cols & {:keys [cols except-cols]})

Groups the given matrix by the values in the columns indicated by the 'on-cols' argument, returning a sequence of matrices. The returned matrices are sorted by the value of the group column ONLY when there is only a single (non-vector) on-col argument.

Examples:

(use '(incanter core datasets)) (def plant-growth (to-matrix (get-dataset :plant-growth))) (group-on plant-growth 1) ;; only return the first column (group-on plant-growth 1 :cols 0) ;; don't return the second column (group-on plant-growth 1 :except-cols 1)

(def plant-growth-dummies (to-matrix (get-dataset :plant-growth) :dummies true)) (group-on plant-growth-dummies [1 2]) ;; return only the first column (group-on plant-growth-dummies [1 2] :cols 0) ;; don't return the last two columns (group-on plant-growth-dummies [1 2] :except-cols [1 2])

;; plot the plant groups (use 'incanter.charts) ;; can use destructuring if you know the number of groups ;; groups are sorted only if the group is based on a single column value (let [[ctrl trt1 trt2] (group-on plant-growth 1 :cols 0)] (doto (box-plot ctrl) (add-box-plot trt1) (add-box-plot trt2) view))

Groups the given matrix by the values in the columns indicated by the
'on-cols' argument, returning a sequence of matrices. The returned
matrices are sorted by the value of the group column ONLY when there
is only a single (non-vector) on-col argument.

Examples:

  (use '(incanter core datasets))
  (def plant-growth (to-matrix (get-dataset :plant-growth)))
  (group-on plant-growth 1)
  ;; only return the first column
  (group-on plant-growth 1 :cols 0)
  ;; don't return the second column
  (group-on plant-growth 1 :except-cols 1)

  (def plant-growth-dummies (to-matrix (get-dataset :plant-growth) :dummies true))
  (group-on plant-growth-dummies [1 2])
  ;; return only the first column
  (group-on plant-growth-dummies [1 2] :cols 0)
  ;; don't return the last two columns
  (group-on plant-growth-dummies [1 2] :except-cols [1 2])

  ;; plot the plant groups
  (use 'incanter.charts)
  ;; can use destructuring if you know the number of groups
  ;; groups are sorted only if the group is based on a single column value
  (let [[ctrl trt1 trt2] (group-on plant-growth 1 :cols 0)]
    (doto (box-plot ctrl)
          (add-box-plot trt1)
          (add-box-plot trt2)
          view))
sourceraw docstring

half-vectorizeclj

(half-vectorize mat)

Returns the half-vectorization (i.e. vech) of the given matrix. The half-vectorization, vech(A), of a symmetric nxn matrix A is the n(n+1)/2 x 1 column vector obtained by vectorizing only the upper triangular part of A.

For instance: (= (half-vectorize (matrix [[a b] [b d]])) (matrix [a b d]))

Examples: (def A (matrix [[1 2] [2 4]])) (half-vectorize A)

References: http://en.wikipedia.org/wiki/Vectorization_(mathematics)

Returns the half-vectorization (i.e. vech) of the given matrix.
The half-vectorization, vech(A), of a symmetric nxn matrix A
is the n(n+1)/2 x 1 column vector obtained by vectorizing only
the upper triangular part of A.

For instance:
  (= (half-vectorize (matrix [[a b] [b d]])) (matrix [a b d]))

Examples:
  (def A (matrix [[1 2] [2 4]]))
  (half-vectorize A)

References:
  http://en.wikipedia.org/wiki/Vectorization_(mathematics)
sourceraw docstring

(head mat)
(head len mat)

Returns the head of the dataset. 10 or full dataset by default.

Returns the head of the dataset. 10 or full dataset by default.
sourceraw docstring

identity-matrixcljdeprecated

(identity-matrix n)

Returns an n-by-n identity matrix.

Examples: (identity-matrix 4)

Deprecated. Please use clojure.core.matrix/identity-matrix instead.

Returns an n-by-n identity matrix.

Examples:
(identity-matrix 4)

Deprecated. Please use clojure.core.matrix/identity-matrix instead.
sourceraw docstring

incomplete-betaclj

(incomplete-beta x a b)

Returns the non-regularized incomplete beta value.

References: http://incanter.org/docs/parallelcolt/api/cern/jet/stat/tdouble/Gamma.html

Returns the non-regularized incomplete beta value.

References:
  http://incanter.org/docs/parallelcolt/api/cern/jet/stat/tdouble/Gamma.html
sourceraw docstring

inner-productcljdeprecated

(inner-product u v)
source

kroneckerclj

(kronecker & args)

Returns the Kronecker product of the given arguments.

Examples:

(def x (matrix (range 6) 2)) (def y (matrix (range 4) 2)) (kronecker 4 x) (kronecker x 4) (kronecker x y)

Returns the Kronecker product of the given arguments.

Examples:

  (def x (matrix (range 6) 2))
  (def y (matrix (range 4) 2))
  (kronecker 4 x)
  (kronecker x 4)
  (kronecker x y)
sourceraw docstring

lengthcljdeprecated

(length coll)

A version of count that works on collections, matrices, and numbers. The length of a number is one, the length of a collection is its count and the length of a matrix is the number of elements it contains (nrow*ncol). Equivalent to R's length function.

Deprecated. Please use clojure.core.matrix/ecount instead.

A version of count that works on collections, matrices, and numbers.
The length of a number is one, the length of a collection is its count
and the length of a matrix is the number of elements it contains (nrow*ncol).
Equivalent to R's length function.

Deprecated. Please use clojure.core.matrix/ecount instead.
sourceraw docstring

logclj

(log A)

Returns the natural log of the elements in the given matrix, sequence or number. Equivalent to R's log function.

Returns the natural log of the elements in the given matrix, sequence or number.
Equivalent to R's log function.
sourceraw docstring

log10clj

(log10 A)

Returns the log base 10 of the elements in the given matrix, sequence or number. Equivalent to R's log10 function.

Returns the log base 10 of the elements in the given matrix, sequence or number.
Equivalent to R's log10 function.
sourceraw docstring

log2clj

(log2 A)

Returns the log base 2 of the elements in the given matrix, sequence or number. Equivalent to R's log2 function.

Returns the log base 2 of the elements in the given matrix, sequence or number.
Equivalent to R's log2 function.
sourceraw docstring

matrixclj

(matrix data)
(matrix data ncol)
(matrix init-val rows cols)

Returns a matrix or vector, in a valid core.matrix format. You can use the slices function to access the rows.

Equivalent to R's matrix function.

Examples: (def A (matrix [[1 2 3] [4 5 6] [7 8 9]])) ; produces a 3x3 matrix (def A2 (matrix [1 2 3 4 5 6 7 8 9] 3)) ; produces the same 3x3 matrix (def B (matrix [1 2 3 4 5 6 7 8 9])) ; produces a vector with 9 elements

; since (plus row1 row2) adds the two rows element-by-element (reduce plus A) ; produces the sums of the columns

; and since (sum row1) sums the elements of the row (map sum A) ; produces the sums of the rows

Returns a matrix or vector, in a valid core.matrix format. You can use the slices function to
access the rows.

Equivalent to R's matrix function.

Examples:
  (def A (matrix [[1 2 3] [4 5 6] [7 8 9]])) ; produces a 3x3 matrix
  (def A2 (matrix [1 2 3 4 5 6 7 8 9] 3)) ; produces the same 3x3 matrix
  (def B (matrix [1 2 3 4 5 6 7 8 9])) ; produces a vector with 9 elements

  ; since (plus row1 row2) adds the two rows element-by-element
  (reduce plus A) ; produces the sums of the columns

  ; and since (sum row1) sums the elements of the row
  (map sum A) ; produces the sums of the rows

sourceraw docstring

matrix-mapcljdeprecated

(matrix-map f m)
(matrix-map f m & ms)

Like clojure.core/map, but will work on matrices of any dimension: 1 x 1 (like e.g. a Double), 1 x n, n x 1, and n x m

Examples: (use '(incanter core)) (def mat (matrix (range 9) 3)) (matrix-map #(mod % 2) mat) (matrix-map #(mod % 2) (first mat)) (matrix-map #(mod % 2) ($ 1 0 mat)) (matrix-map #(mod % 2) [1 2 3 4]) (matrix-map #(mod % 2) 9)

Deprecated. Please use clojure.core.matrix/emap instead.

Like clojure.core/map, but will work on matrices of any dimension:
1 x 1 (like e.g. a Double), 1 x n, n x 1, and n x m

Examples:
  (use '(incanter core))
  (def mat (matrix (range 9) 3))
  (matrix-map #(mod % 2) mat)
  (matrix-map #(mod % 2) (first mat))
  (matrix-map #(mod % 2) ($ 1 0 mat))
  (matrix-map #(mod % 2) [1 2 3 4])
  (matrix-map #(mod % 2) 9)

Deprecated. Please use clojure.core.matrix/emap instead.
sourceraw docstring

matrix?clj

(matrix? obj)

Tests if obj is core.matrix matrix

Tests if obj is core.matrix matrix
sourceraw docstring

meltclj

(melt dataset pivot-key)

Melt an object into a form suitable for easy casting, like a melt function in R. Only accepts one pivot key for now. e.g.

(use '(incanter core charts datasets)) (view (with-data (melt (get-dataset :flow-meter) :Subject) (line-chart :Subject :value :group-by :variable :legend true)))

See http://www.statmethods.net/management/reshape.html for more examples.

Melt an object into a form suitable for easy casting, like a melt function in R.
Only accepts one pivot key for now. e.g.

  (use '(incanter core charts datasets))
  (view (with-data (melt (get-dataset :flow-meter) :Subject)
            (line-chart :Subject :value :group-by :variable :legend true)))

See http://www.statmethods.net/management/reshape.html for more examples.
sourceraw docstring

minuscljdeprecated

(minus & args)

Performs element-by-element subtraction on multiple matrices, sequences and/or numbers. If only a single argument is provided, returns the negative of the given matrix, sequence, or number. Equivalent to R's - operator.

Examples: (def A (matrix [[1 2 3] [4 5 6] [7 8 9]])) (minus A) (minus A A A) (minus A 2) (minus 2 A) (minus [1 2 3] [1 2 3]) (minus [1 2 3] 2) (minus 2 [1 2 3]) (minus [1 2 3])

Deprecated. Please use clojure.core.matrix/sub or clojure.core.matrix.operators/- instead.

Performs element-by-element subtraction on multiple matrices, sequences
and/or numbers. If only a single argument is provided, returns the negative
of the given matrix, sequence, or number. Equivalent to R's - operator.

Examples:
  (def A (matrix [[1 2 3]
                  [4 5 6]
                  [7 8 9]]))
  (minus A)
  (minus A A A)
  (minus A 2)
  (minus 2 A)
  (minus [1 2 3] [1 2 3])
  (minus [1 2 3] 2)
  (minus 2 [1 2 3])
  (minus [1 2 3])

Deprecated. Please use clojure.core.matrix/sub or
clojure.core.matrix.operators/- instead.
sourceraw docstring

mmultcljdeprecated

(mmult & args)

Returns the matrix resulting from the matrix multiplication of the the given arguments. Equivalent to R's %*% operator.

Examples:

(def A (matrix [[1 2 3] [4 5 6] [7 8 9]])) (mmult A (trans A)) (mmult A (trans A) A)

References: http://en.wikipedia.org/wiki/Matrix_multiplication

Deprecated. Please use clojure.core.matrix/mmul instead.

Returns the matrix resulting from the matrix multiplication of the
the given arguments. Equivalent to R's %*% operator.

Examples:

  (def A (matrix [[1 2 3]
                  [4 5 6]
                  [7 8 9]]))
  (mmult A (trans A))
  (mmult A (trans A) A)

References:
  http://en.wikipedia.org/wiki/Matrix_multiplication

Deprecated. Please use clojure.core.matrix/mmul instead.
sourceraw docstring

multcljdeprecated

(mult & args)

Performs element-by-element multiplication on multiple matrices, sequences and/or numbers. Equivalent to R's * operator.

Examples:

(def A (matrix [[1 2 3] [4 5 6] [7 8 9]])) (mult A A A) (mult A 2) (mult 2 A) (mult [1 2 3] [1 2 3]) (mult [1 2 3] 2) (mult 2 [1 2 3])

Deprecated. Please use clojure.core.matrix/emul or clojure.core.matrix.operators/* instead.

Performs element-by-element multiplication on multiple matrices, sequences
and/or numbers. Equivalent to R's * operator.

Examples:

(def A (matrix [[1 2 3]
                [4 5 6]
                [7 8 9]]))
(mult A A A)
(mult A 2)
(mult 2 A)
(mult [1 2 3] [1 2 3])
(mult [1 2 3] 2)
(mult 2 [1 2 3])

Deprecated. Please use clojure.core.matrix/emul or
clojure.core.matrix.operators/* instead.
sourceraw docstring

ncolcljmultimethod

Returns the number of columns in the given matrix. Equivalent to R's ncol function.

Returns the number of columns in the given matrix. Equivalent to R's ncol function.
sourceraw docstring

nrowcljmultimethod

Returns the number of rows in the given matrix. Equivalent to R's nrow function.

Returns the number of rows in the given matrix. Equivalent to R's nrow function.
sourceraw docstring

pluscljdeprecated

(plus & args)

Performs element-by-element addition on multiple matrices, sequences and/or numbers. Equivalent to R's + operator.

Examples:

(def A (matrix [[1 2 3] [4 5 6] [7 8 9]])) (plus A A A) (plus A 2) (plus 2 A) (plus [1 2 3] [1 2 3]) (plus [1 2 3] 2) (plus 2 [1 2 3])

Deprecated. Please use clojure.core.matrix/add or clojure.core.matrix.operators/+ instead.

Performs element-by-element addition on multiple matrices, sequences
and/or numbers. Equivalent to R's + operator.

Examples:

(def A (matrix [[1 2 3]
                [4 5 6]
                [7 8 9]]))
(plus A A A)
(plus A 2)
(plus 2 A)
(plus [1 2 3] [1 2 3])
(plus [1 2 3] 2)
(plus 2 [1 2 3])

Deprecated. Please use clojure.core.matrix/add or
clojure.core.matrix.operators/+ instead.
sourceraw docstring

powclj

(pow & args)

This is an element-by-element exponent function, raising the first argument by the exponents in the remaining arguments. Equivalent to R's ^ operator.

This is an element-by-element exponent function, raising the first argument
by the exponents in the remaining arguments. Equivalent to R's ^ operator.
sourceraw docstring

prodclj

(prod x)

Returns the product of the given sequence.

Returns the product of the given sequence.
sourceraw docstring

projclj

(proj u v)
source

query-datasetclj

(query-dataset data query-map)

Queries the given dataset using the query-map, returning a new dataset. The query-map uses the the dataset's column-names as keys and a simple variant of the MongoDB query language.

For instance, given a dataset with two columns, :x and :category, to query for rows where :x equals 10, use the following query-map: {:x 10}.

To indicate that :x should be between 10 and 20, use {:x {:$gt 10 :$lt 20}}.

To indicate that :category should also be either :red, :green, or :blue, use :$in {:x {:$gt 10 :$lt 20} :y {:$in #{:green :blue :red}}}

And to indicate that :category should not include :red, :green, or :blue, use :$nin {:x {:$gt 10 :$lt 20} :y {:$nin #{:green :blue :red}}}

The available query terms include :$gt, :$lt, :$gte, :$lte, :$eq, :$ne, :$in, :$nin, $fn.

A row predicate function can be used instead of a query-map. The function must accept a map, representing a row of the dataset, and return a boolean value indicating whether the row should be included in the new dataset.

Examples: (use '(incanter core datasets)) (def cars (get-dataset :cars))

(view (query-dataset cars {:speed 10})) (view (query-dataset cars {:speed {:$in #{17 14 19}}})) (view (query-dataset cars {:speed {:$lt 20 :$gt 10}})) (view (query-dataset cars {:speed {:$fn #(> (log %) 3)}}))

;; use a row predicate function instead of a query map. (view (query-dataset cars (fn [row] (> (/ (row "speed") (row "dist")) 1/2)))) (assoc data :rows (for [row (:rows data) :when (query-map row)] row))

Queries the given dataset using the query-map, returning a new dataset.
The query-map uses the the dataset's column-names as keys and a
simple variant of the MongoDB query language.

For instance, given a dataset with two columns, :x and :category,  to query
for rows where :x equals 10, use the following query-map: {:x 10}.

To indicate that :x should be between 10 and 20, use {:x {:$gt 10 :$lt 20}}.

To indicate that :category should also be either :red, :green, or :blue, use :$in
{:x {:$gt 10 :$lt 20} :y {:$in #{:green :blue :red}}}

And to indicate that :category should not include :red, :green, or :blue, use :$nin
{:x {:$gt 10 :$lt 20} :y {:$nin #{:green :blue :red}}}

The available query terms include :$gt, :$lt, :$gte, :$lte, :$eq, :$ne, :$in, :$nin, $fn.

A row predicate function can be used instead of a query-map. The function must accept
a map, representing a row of the dataset, and return a boolean value indicating whether
the row should be included in the new dataset.

Examples:
  (use '(incanter core datasets))
  (def cars (get-dataset :cars))

  (view (query-dataset cars {:speed 10}))
  (view (query-dataset cars {:speed {:$in #{17 14 19}}}))
  (view (query-dataset cars {:speed {:$lt 20 :$gt 10}}))
  (view (query-dataset cars {:speed {:$fn #(> (log %) 3)}}))

  ;; use a row predicate function instead of a query map.
  (view (query-dataset cars (fn [row] (> (/ (row "speed") (row "dist")) 1/2))))
   (assoc data :rows
           (for [row (:rows data) :when (query-map row)] row))
sourceraw docstring

query-to-predclj

(query-to-pred query-map)

Given a query-map, it returns a function that accepts a hash-map and returns true if it satisfies the conditions specified in the provided query-map.

Examples:

(use 'incanter.core) (def pred (query-to-pred {:x 5 :y 7})) (pred {:x 5 :y 7 :z :d})

(def pred (query-to-pred {:x 5 :y {:$gt 5 :$lt 10}})) (pred {:x 5 :y 7 :z :d})

(def pred (query-to-pred {:z {:$in #{:a :b}}})) (pred {:x 5 :y 7 :z :d})

Given a query-map, it returns a function that accepts a hash-map and returns true if it
satisfies the conditions specified in the provided query-map.

Examples:

  (use 'incanter.core)
  (def pred (query-to-pred {:x 5 :y 7}))
  (pred {:x 5 :y 7 :z :d})

  (def pred (query-to-pred {:x 5 :y {:$gt 5 :$lt 10}}))
  (pred {:x 5 :y 7 :z :d})

  (def pred (query-to-pred {:z {:$in #{:a :b}}}))
  (pred {:x 5 :y 7 :z :d})
sourceraw docstring

quitclj

(quit)

Exits the Clojure shell.

Exits the Clojure shell.
sourceraw docstring

rankcljdeprecated

(rank mat)

Returns the effective numerical matrix rank, which is the number of nonnegligible singular values.

Examples:

(use 'incanter.core) (def foo (matrix (range 9) 3)) (rank foo)

References: http://en.wikipedia.org/wiki/Matrix_rank

Deprecated. Please use clojure.core.matrix.linear/rank instead.

Returns the effective numerical matrix rank, which is the number of nonnegligible singular values.

Examples:

(use 'incanter.core)
(def foo (matrix (range 9) 3))
(rank foo)

References:
http://en.wikipedia.org/wiki/Matrix_rank

Deprecated. Please use clojure.core.matrix.linear/rank instead.
sourceraw docstring

regularized-betaclj

(regularized-beta x a b)
Returns the regularized incomplete beta value. Equivalent to R's pbeta function.

References:
  http://incanter.org/docs/parallelcolt/api/cern/jet/stat/tdouble/Gamma.html
  http://en.wikipedia.org/wiki/Regularized_incomplete_beta_function
  http://mathworld.wolfram.com/RegularizedBetaFunction.html
sourceraw docstring

rename-colsclj

(rename-cols col-map)
(rename-cols col-map data)

Rename columns based on col-map of old-col new-col-name pairs. If old-col is a number it is taken as a 0 based index for the column to replace

Example: (use '(incanter core datasets)) (rename-cols {:Sepal.Length :s.length 3 :p.width} (get-dataset :iris))

Rename columns based on col-map of old-col new-col-name pairs.  If
old-col is a number it is taken as a 0 based index for the column to
replace

Example:
 (use '(incanter core datasets))
 (rename-cols {:Sepal.Length :s.length 3 :p.width} (get-dataset :iris))
sourceraw docstring

reorder-columnscljdeprecated

(reorder-columns ds cols)

Produce a new dataset with the columns in the specified order. Returns nil if no valid column names are given.

Deprecated. Please use clojure.core.matrix.dataset/select-columns instead

Produce a new dataset with the columns in the specified order.
Returns nil if no valid column names are given.

Deprecated. Please use clojure.core.matrix.dataset/select-columns instead
sourceraw docstring

replace-columnclj

(replace-column column-name values)
(replace-column column-name values data)

Replaces a column in a dataset with new values.

Replaces a column in a dataset with new values.
sourceraw docstring

safe-divclj

(safe-div x)
(safe-div x y)
(safe-div x y & more)

DivideByZero safe alternative to clojures / function, detects divide by zero and returns Infinity, -Infinity or NaN as appropriate.

DivideByZero safe alternative to clojures / function,
detects divide by zero and returns Infinity, -Infinity or NaN as appropriate.
sourceraw docstring

savecljmultimethod

Save is a multi-function that is used to write matrices, datasets and charts (in png format) to a file.

Arguments: obj -- is a matrix, dataset, or chart object filename -- the filename to create.

Matrix and dataset options: :delim (default ,) column delimiter :header (default nil) an sequence of strings to be used as header line for matrices the default value is nil, for datasets, the default is the dataset's column-names array. :append (default false) determines whether this given file should be appended to. If true, a header will not be written to the file again. If the filename is exactly "-" then out the matrix/dataset will be written to out

Chart options: :width (default 500) :height (default 400)

Matrix Examples:

(use '(incanter core io)) (def A (matrix (range 12) 3)) ; creates a 3x4 matrix (save A "A.dat") ; writes A to the file A.dat, with no header and comma delimited (save A "A.dat" :delim \tab) ; writes A to the file A.dat, with no header and tab delimited

;; writes A to the file A.dat, with a header and tab delimited (save A "A.dat" :delim , :header ["col1" "col2" "col3"])

Dataset Example:

(use '(incanter core io datasets)) ;; read the iris sample dataset, and save it to a file. (def iris (get-dataset :iris)) (save iris "iris.dat")

Chart Example:

(use '(incanter core io stats charts)) (save (histogram (sample-normal 1000)) "hist.png")

;; chart example using java.io.OutputStream instead of filename (use '(incanter core stats charts)) (import 'java.io.FileOutputStream) (def fos (FileOutputStream. "/tmp/hist.png")) (def hist (histogram (sample-normal 1000))) (save hist fos) (.close fos)

(view "file:///tmp/hist.png")

Save is a multi-function that is used to write matrices, datasets and
charts (in png format) to a file.

Arguments:
  obj -- is a matrix, dataset, or chart object
  filename -- the filename to create.

Matrix and dataset options:
  :delim (default \,) column delimiter
  :header (default nil) an sequence of strings to be used as header line
      for matrices the default value is nil, for datasets, the default is
      the dataset's column-names array.
  :append (default false) determines whether this given file should be
      appended to. If true, a header will not be written to the file again.
  If the filename is exactly "-" then *out* the matrix/dataset will be
      written to *out*

Chart options:
  :width (default 500)
  :height (default 400)


Matrix Examples:

  (use '(incanter core io))
  (def A (matrix (range 12) 3)) ; creates a 3x4 matrix
  (save A "A.dat") ; writes A to the file A.dat, with no header and comma delimited
  (save A "A.dat" :delim \tab) ; writes A to the file A.dat, with no header and tab delimited

  ;; writes A to the file A.dat, with a header and tab delimited
  (save A "A.dat" :delim \, :header ["col1" "col2" "col3"])


Dataset Example:

  (use '(incanter core io datasets))
  ;; read the iris sample dataset, and save it to a file.
  (def iris (get-dataset :iris))
  (save iris "iris.dat")


Chart Example:

  (use '(incanter core io stats charts))
  (save (histogram (sample-normal 1000)) "hist.png")

  ;; chart example using java.io.OutputStream instead of filename
  (use '(incanter core stats charts))
  (import 'java.io.FileOutputStream)
  (def fos (FileOutputStream. "/tmp/hist.png"))
  (def hist (histogram (sample-normal 1000)))
  (save hist fos)
  (.close fos)

  (view "file:///tmp/hist.png")


sourceraw docstring

selcljmultimethod

Returns an element or subset of the given matrix, dataset, or list. If the column or row is specified as an atomic object (index or name), then the result will be returned as a list (only values from selected column or row).

Argument: a matrix object, dataset, or list.

Options: :rows (default true) returns all rows by default, can pass a row index or sequence of row indices :cols (default true) returns all columns by default, can pass a column index or sequence of column indices :except-rows (default nil) can pass a row index or sequence of row indices to exclude :except-cols (default nil) can pass a column index or sequence of column indices to exclude :filter-fn (default nil) a function can be provided to filter the rows of the matrix

Examples: (use 'incanter.datasets) (def iris (to-matrix (get-dataset :iris))) (sel iris 0 0) ; first element (sel iris :rows 0 :cols 0) ; also first element (sel iris :cols 0) ; first column of all rows (sel iris :cols [0 2]) ; first and third column of all rows (sel iris :rows (range 10) :cols (range 2)) ; first two columns of the first 10 rows (sel iris :rows (range 10)) ; all columns of the first 10 rows

;; exclude rows or columns (sel iris :except-rows (range 10)) ; all columns of all but the first 10 rows (sel iris :except-cols 1) ; all columns except the second

;; return only the first 10 even rows (sel iris :rows (range 10) :filter-fn #(even? (int (nth % 0)))) ;; select rows where distance (third column) is greater than 50 (sel iris :filter #(> (nth % 2) 4))

;; examples with datasets (use 'incanter.datasets) (def us-arrests (get-dataset :us-arrests)) (sel us-arrests :cols "State") (sel us-arrests :cols :State)

(sel us-arrests :cols ["State" "Murder"]) (sel us-arrests :cols [:State :Murder])

Returns an element or subset of the given matrix, dataset, or list.
If the column or row is specified as an atomic object (index or name), then
the result will be returned as a list (only values from selected column or row).

Argument:
  a matrix object, dataset, or list.

Options:
  :rows (default true)
    returns all rows by default, can pass a row index or sequence of row indices
  :cols (default true)
    returns all columns by default, can pass a column index or sequence of column indices
  :except-rows (default nil) can pass a row index or sequence of row indices to exclude
  :except-cols (default nil) can pass a column index or sequence of column indices to exclude
  :filter-fn (default nil)
    a function can be provided to filter the rows of the matrix

Examples:
  (use 'incanter.datasets)
  (def iris (to-matrix (get-dataset :iris)))
  (sel iris 0 0) ; first element
  (sel iris :rows 0 :cols 0) ; also first element
  (sel iris :cols 0) ; first column of all rows
  (sel iris :cols [0 2]) ; first and third column of all rows
  (sel iris :rows (range 10) :cols (range 2)) ; first two columns of the first 10 rows
  (sel iris :rows (range 10)) ; all columns of the first 10 rows

  ;; exclude rows or columns
  (sel iris :except-rows (range 10)) ; all columns of all but the first 10 rows
  (sel iris :except-cols 1) ; all columns except the second

  ;; return only the first 10 even rows
  (sel iris :rows (range 10) :filter-fn #(even? (int (nth % 0))))
  ;; select rows where distance (third column) is greater than 50
  (sel iris :filter #(> (nth % 2) 4))

  ;; examples with datasets
  (use 'incanter.datasets)
  (def us-arrests (get-dataset :us-arrests))
  (sel us-arrests :cols "State")
  (sel us-arrests :cols :State)

  (sel us-arrests :cols ["State" "Murder"])
  (sel us-arrests :cols [:State :Murder])
sourceraw docstring

set-current-implementationclj

(set-current-implementation imp)
source

set-datacljmultimethod

Examples:

(use '(incanter core charts datasets))

(def data (get-dataset :iris)) (def table (data-table data)) (view table) ;; now view only a subset of the data (set-data table ($where {:Petal.Length {:gt 6}} data))

;; use sliders to dynamically select the query values (let [data (get-dataset :iris) table (data-table data)] (view table) (sliders [species ["setosa" "virginica" "versicolor"] min-petal-length (range 0 8 0.1)] (set-data table ($where {:Species species :Petal.Length {:gt min-petal-length}} data))))

Examples:

  (use '(incanter core charts datasets))

  (def data (get-dataset :iris))
  (def table (data-table data))
  (view table)
  ;; now view only a subset of the data
  (set-data table ($where {:Petal.Length {:gt 6}} data))


  ;; use sliders to dynamically select the query values
  (let [data (get-dataset :iris)
        table (data-table data)]
    (view table)
    (sliders [species ["setosa" "virginica" "versicolor"]
              min-petal-length (range 0 8 0.1)]
      (set-data table ($where {:Species species
                               :Petal.Length {:gt min-petal-length}}
                              data))))

sourceraw docstring

sinclj

(sin A)

Returns the sine of the elements in the given matrix, sequence or number. Equivalent to R's sin function.

Returns the sine of the elements in the given matrix, sequence or number.
Equivalent to R's sin function.
sourceraw docstring

solvecljdeprecated

(solve A)
(solve A B)

Returns a matrix solution if A is square, least squares solution otherwise. Equivalent to R's solve function.

Examples: (solve (matrix [[2 0 0] [0 2 0] [0 0 2]]))

References: http://en.wikipedia.org/wiki/Matrix_inverse

Deprecated. Please use clojure.core.matrix/inverse for matrix inverse, clojure.core.matrix.linear/solve for solving system of linear equations and clojure.core.matrix.linear/least-squares for least-squares solution.

Returns a matrix solution if A is square, least squares solution otherwise.
Equivalent to R's solve function.

Examples:
  (solve (matrix [[2 0 0] [0 2 0] [0 0 2]]))

References:
  http://en.wikipedia.org/wiki/Matrix_inverse

Deprecated. Please use clojure.core.matrix/inverse for matrix inverse,
clojure.core.matrix.linear/solve for solving system of linear equations and
clojure.core.matrix.linear/least-squares for least-squares solution.

sourceraw docstring

solve-quadraticclj

(solve-quadratic a b c)

Returns a vector with the solution to x from the quadratic equation, ax^2 + bx + c.

Arguments: a, b, c: coefficients of a qaudratic equation.

Examples: ;; -2x^2 + 7x + 15 (quadratic-formula -2 7 15) ;; x^2 + -2*x + 1 (quadratic-formula 1 -2 1)

References: http://en.wikipedia.org/wiki/Quadratic_formula

Returns a vector with the solution to x from the quadratic
equation, a*x^2 + b*x + c.

Arguments:
  a, b, c: coefficients of a qaudratic equation.

Examples:
  ;; -2*x^2 + 7*x + 15
  (quadratic-formula -2 7 15)
  ;; x^2 + -2*x + 1
  (quadratic-formula 1 -2 1)

References:
  http://en.wikipedia.org/wiki/Quadratic_formula

sourceraw docstring

sqclj

(sq A)

Returns the square of the elements in the given matrix, sequence or number. Equivalent to R's sq function.

Returns the square of the elements in the given matrix, sequence or number.
Equivalent to R's sq function.
sourceraw docstring

sqrtclj

(sqrt A)

Returns the square-root of the elements in the given matrix, sequence or number. Equivalent to R's sqrt function.

Returns the square-root of the elements in the given matrix, sequence or number.
Equivalent to R's sqrt function.
sourceraw docstring

string-to-categoricalclj

(string-to-categorical dataset column-idx dummies?)
source

sumcljdeprecated

(sum x)

Returns the sum of the given sequence.

Deprecated. Please use clojure.core.matrix/esum instead.

Returns the sum of the given sequence.

Deprecated. Please use clojure.core.matrix/esum instead.
sourceraw docstring

sum-of-squarescljdeprecated

(sum-of-squares x)

Returns the sum-of-squares of the given sequence.

Deprecated. Please use clojure.core.matrix/length-squared instead.

Returns the sum-of-squares of the given sequence.

Deprecated. Please use clojure.core.matrix/length-squared instead.
sourceraw docstring

symmetric-matrixclj

(symmetric-matrix data & {:keys [lower] :or {lower true}})

Returns a symmetric matrix from the given data, which represents the lower triangular elements ordered by row. This is not the inverse of half-vectorize which returns a vector of the upper-triangular values, unless the :lower option is set to false.

Options: :lower (default true) -- lower-triangular. Set :lower to false to reverse the half-vectorize function.

Examples:

(use 'incanter.core) (symmetric-matrix [1 2 3 4 5 6 7 8 9 10])

(half-vectorize (symmetric-matrix [1 2 3 4 5 6 7 8 9 10] :lower false))

Returns a symmetric matrix from the given data, which represents the lower triangular elements
ordered by row. This is not the inverse of half-vectorize which returns a vector of the upper-triangular
values, unless the :lower option is set to false.

Options:
  :lower (default true) -- lower-triangular. Set :lower to false to reverse the half-vectorize function.

Examples:

  (use 'incanter.core)
  (symmetric-matrix [1
                     2 3
                     4 5 6
                     7 8 9 10])


  (half-vectorize
    (symmetric-matrix [1
                       2 3
                       4 5 6
                       7 8 9 10] :lower false))
sourceraw docstring

tailclj

(tail mat)
(tail len mat)

Returns the tail of the dataset. 10 or full dataset by default.

Returns the tail of the dataset. 10 or full dataset by default.
sourceraw docstring

tanclj

(tan A)

Returns the tangent of the elements in the given matrix, sequence or number. Equivalent to R's tan function.

Returns the tangent of the elements in the given matrix, sequence or number.
Equivalent to R's tan function.
sourceraw docstring

to-datasetclj

(to-dataset obj & {:keys [transpose]})

Returns a dataset containing the given values.

Examples:

(use 'incanter.core) (to-dataset 1) (to-dataset :a) (to-dataset [:a]) (to-dataset (range 10)) (to-dataset (range 10) :transpose true) (to-dataset [[1 2] [3 4] [5 6]]) (to-dataset {:a 1 :b 2 :c 3}) (to-dataset {"a" 1 "b" 2 "c" 3}) (to-dataset [{:a 1 :b 2} {:a 1 :b 2}]) (to-dataset [{"a" 1 "b" 2 "c" 3} {"a" 1 "b" 2 "c" 3}])

Returns a dataset containing the given values.

Examples:

  (use 'incanter.core)
  (to-dataset 1)
  (to-dataset :a)
  (to-dataset [:a])
  (to-dataset (range 10))
  (to-dataset (range 10) :transpose true)
  (to-dataset [[1 2] [3 4] [5 6]])
  (to-dataset {:a 1 :b 2 :c 3})
  (to-dataset {"a" 1 "b" 2 "c" 3})
  (to-dataset [{:a 1 :b 2} {:a 1 :b 2}])
  (to-dataset [{"a" 1 "b" 2 "c" 3} {"a" 1 "b" 2 "c" 3}])
  
sourceraw docstring

to-dummiesclj

(to-dummies coll)
source

to-labelsclj

(to-labels coll cat-var)
source

to-levelsclj

(to-levels coll & options)
source

to-listcljmultimethod

Returns a list-of-vectors if the given matrix is two-dimensional and a flat list if the matrix is one-dimensional.

Returns a list-of-vectors if the given matrix is two-dimensional
and a flat list if the matrix is one-dimensional.
sourceraw docstring

to-mapcljmultimethod

Takes a dataset or matrix and returns a hash-map where the keys are keyword versions of the column names, for datasets, or numbers, for matrices, and the values are sequence of the column values.

Examples: (use '(incanter core datasets))

(to-map (get-dataset :cars))

(to-map (matrix (range 9) 3))

Takes a dataset or matrix and returns a hash-map where the keys are
keyword versions of the column names, for datasets, or numbers, for
matrices, and the values are sequence of the column values.

Examples:
  (use '(incanter core datasets))

  (to-map (get-dataset :cars))

  (to-map (matrix (range 9) 3))

sourceraw docstring

to-matrixclj

(to-matrix dataset & {:keys [dummies] :or {dummies false}})

Converts a dataset into a matrix. Equivalent to R's as.matrix function for datasets.

Options: :dummies (default false) -- if true converts non-numeric variables into sets of binary dummy variables, otherwise converts them into numeric codes.

Converts a dataset into a matrix. Equivalent to R's as.matrix function
for datasets.

Options:
  :dummies (default false) -- if true converts non-numeric variables into sets
                              of binary dummy variables, otherwise converts
                              them into numeric codes.
sourceraw docstring

to-vectclj

(to-vect a)

Converts an array into nested Clojure vectors.

Returns a vector-of-vectors if the given matrix is two-dimensional and a flat vector if the matrix is one-dimensional. This is a bit slower than the to-list function

Converts an array into nested Clojure vectors. 

Returns a vector-of-vectors if the given matrix is two-dimensional
and a flat vector if the matrix is one-dimensional. This is a bit
slower than the to-list function
sourceraw docstring

to-vectorclj

source

toeplitzclj

(toeplitz x)

Returns the Toeplitz matrix for the given vector, which form the first row of the matrix

Returns the Toeplitz matrix for the given vector, which form the first row of the matrix
sourceraw docstring

tracecljdeprecated

(trace mat)

Returns the trace of the given matrix.

References: http://en.wikipedia.org/wiki/Matrix_trace

Deprecated. Please use clojure.core.matrix/trace instead.

Returns the trace of the given matrix.

References:
http://en.wikipedia.org/wiki/Matrix_trace

Deprecated. Please use clojure.core.matrix/trace instead.
sourceraw docstring

transcljdeprecated

(trans mat)

Returns the transpose of the given matrix. Equivalent to R's t function

Examples: (def A (matrix [[1 2 3] [4 5 6] [7 8 9]])) (trans A)

Deprecated. Please use clojure.core.matrix/transpose instead.

Returns the transpose of the given matrix. Equivalent to R's t function

Examples:
  (def A (matrix [[1 2 3]
                  [4 5 6]
                  [7 8 9]]))
  (trans A)

Deprecated. Please use clojure.core.matrix/transpose instead.
sourceraw docstring

transform-colcljdeprecated

(transform-col dataset column f & args)

Apply function f & args to the specified column of dataset and replace the column with the resulting new values.

Deprecated. Please use clojure.core.matrix.dataset/update-column instead.

Apply function f & args to the specified column of dataset and replace the column
with the resulting new values.

Deprecated. Please use `clojure.core.matrix.dataset/update-column` instead.
sourceraw docstring

vec?clj

(vec? obj)

Tests if obj is core.matrix vector

Tests if obj is core.matrix vector
sourceraw docstring

vector-lengthcljdeprecated

(vector-length u)
source

vectorizeclj

(vectorize mat)

Returns the vectorization (i.e. vec) of the given matrix. The vectorization of an m-by-n matrix A, denoted by vec(A) is the m*n-by-1 column vector obtain by stacking the columns of the matrix A on top of one another.

For instance: (= (vectorize (matrix [[a b] [c d]])) (matrix [a c b d]))

Examples: (def A (matrix [[1 2] [3 4]])) (vectorize A)

References: http://en.wikipedia.org/wiki/Vectorization_(mathematics)

Returns the vectorization (i.e. vec) of the given matrix.
The vectorization of an m-by-n matrix A, denoted by vec(A)
is the m*n-by-1 column vector obtain by stacking the columns
of the matrix A on top of one another.

For instance:
  (= (vectorize (matrix [[a b] [c d]])) (matrix [a c b d]))

Examples:
  (def A (matrix [[1 2] [3 4]]))
  (vectorize A)

References:
  http://en.wikipedia.org/wiki/Vectorization_(mathematics)
sourceraw docstring

viewcljmultimethod

This is a general 'view' function. When given an Incanter matrix/dataset or a Clojure numeric collection, it will display it in a Java Swing JTable. When given an Incanter chart object, it will display it in a new window. When given a URL string, it will open the location with the platform's default web browser.

When viewing charts, a :width (default 500) and :height (default 400) option can be provided.

When viewing an incanter.processing sketch, set the :exit-on-close option to true (default is false) to kill the animation processes when you close the window (this will also kill your REPL or Swank server), otherwise those processing will continue to run in the background.

Examples:

(use '(incanter core stats datasets charts))

;; view matrices (def rand-mat (matrix (sample-normal 100) 4)) (view rand-mat)

;; view numeric collections (view [1 2 3 4 5]) (view (sample-normal 100))

;; view Incanter datasets (view (get-dataset :iris))

;; convert dataset to matrix, changing Species names to numeric codes (view (to-matrix (get-dataset :iris)))

;; convert dataset to matrix, changing Species names to dummy variables (view (to-matrix (get-dataset :iris) :dummies true))

;; view a chart (view (histogram (sample-normal 1000)) :width 700 :height 700)

;; view a URL (view "http://incanter.org")

;; view a PNG file (save (histogram (sample-normal 1000)) "/tmp/norm_hist.png") (view "file:///tmp/norm_hist.png")

This is a general 'view' function. When given an Incanter matrix/dataset
or a Clojure numeric collection, it will display it in a Java Swing
JTable. When given an Incanter chart object, it will display it in a new
window. When given a URL string, it will open the location with the
platform's default web browser.

When viewing charts, a :width (default 500) and :height (default 400)
option can be provided.

When viewing an incanter.processing sketch, set the :exit-on-close option
to true (default is false) to kill the animation processes when you
close the window (this will also kill your REPL or Swank server),
otherwise those processing will continue to run in the background.



Examples:

  (use '(incanter core stats datasets charts))

  ;; view matrices
  (def rand-mat (matrix (sample-normal 100) 4))
  (view rand-mat)

  ;; view numeric collections
  (view [1 2 3 4 5])
  (view (sample-normal 100))

  ;; view Incanter datasets
  (view (get-dataset :iris))

  ;; convert dataset to matrix, changing Species names to numeric codes
  (view (to-matrix (get-dataset :iris)))

  ;; convert dataset to matrix, changing Species names to dummy variables
  (view (to-matrix (get-dataset :iris) :dummies true))

  ;; view a chart
  (view (histogram (sample-normal 1000)) :width 700 :height 700)

  ;; view a URL
  (view "http://incanter.org")

  ;; view a PNG file
  (save (histogram (sample-normal 1000)) "/tmp/norm_hist.png")
  (view "file:///tmp/norm_hist.png")
sourceraw docstring

with-dataclj/smacro

(with-data data-binding & body)

Binds the given data to $data and executes the body. Typically used with the $ and $where functions.

Examples: (use '(incanter core stats charts datasets))

(with-data (get-dataset :cars) (def lm (linear-model ($ :dist) ($ :speed))) (doto (scatter-plot ($ :speed) ($ :dist)) (add-lines ($ :speed) (:fitted lm)) view))

;; create a dataset where :speed greater than 10 or less than -10 (with-data (get-dataset :cars) (view (-> ($where {:speed {:$gt 20}}) (conj-rows ($where {:speed {:$lt 10}})))))

Binds the given data to $data and executes the body.
Typically used with the $ and $where functions.

Examples:
  (use '(incanter core stats charts datasets))

  (with-data  (get-dataset :cars)
    (def lm (linear-model ($ :dist) ($ :speed)))
    (doto (scatter-plot ($ :speed) ($ :dist))
              (add-lines ($ :speed) (:fitted lm))
               view))

   ;; create a dataset where :speed greater than 10 or less than -10
   (with-data (get-dataset :cars)
     (view (-> ($where {:speed {:$gt 20}})
                     (conj-rows ($where {:speed {:$lt 10}})))))
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close