- Getting started with Clojure
- Getting started with Incanter
- Documentation and examples
- Building Incanter
Overview and motivation
Incanter is a Clojure-based, R-like statistical computing and graphics environment for the JVM. At the core of Incanter are the Parallel Colt numerics library, a multithreaded version of Colt, and the JFreeChart charting library, as well as several other Java and Clojure libraries.
The motivation for creating Incanter is to provide a JVM-based statistical computing and graphics platform with R-like semantics and interactive-programming environment. Running on the JVM provides access to the large number of existing Java libraries for data access, data processing, and presentation. Clojure’s seamless integration with Java makes leveraging these libraries much simpler than is possible in R, and Incanter’s R-like semantics makes statistical programming much simpler than is possible in pure Java.
Motivation for a Lisp-based R-like statistical environment can be found in the paper Back to the Future: Lisp as a Base for a Statistical Computing System by Ihaka and Lang (2008). Incanter is also inspired by the now dormant Lisp-Stat (see the special volume in the Journal of Statistical Software on Lisp-Stat: Past, Present, and Future from 2005).
Getting started with Clojure
For a great introduction to programming in Clojure, read Clojure – Functional Programming for the JVM. by R. Mark Volkmann. For an even more extensive introduction, get one of the books on Clojure Programming Clojure, 2ed by Stuart Halloway and Aaron Bedra, “The Joy of Clojure” by Michael Fogus and Chris Houser, “Clojure in Action” by Amit Rathore, “Practical Clojure” by Luke VanderHart and Stuart Sierra.
Other Clojure resources
- Clojure website
- Getting Started with Clojure
- Clojure Google group
- Disclojure blog
- Full Disclojure screencasts
Getting started with Incanter
Start by visiting the Incanter website for an overview, checkout the documentation page for a listing of HOW-TOs and examples, and then download either an Incanter executable or a pre-built version of the latest build of Incanter, which includes all the necessary dependencies, and unpack the file (if you would like to build it from source, read Building Incanter). You also might need to install libgfortran3 library that is required for jblas that is powering matrix operations (see jblas wiki for more details).
Start the Clojure REPL (aka the shell) by double-clicking on the downloaded executable or, if you downloaded the pre-built distribution, running one of the scripts in the Incanter directory:
script\repl.bat on Windows.
From the Clojure REPL, load the Incanter libraries:
user=> (use '(incanter core stats charts))
Try an example: sample 1,000 values from a standard-normal distribution and view a histogram:
user=> (view (histogram (sample-normal 1000)))
Try another simple example, a plot of the sine function over the range -4 to 4:
user=> (view (function-plot sin -10 10))
The online documentation for most Incanter functions contain usage examples. The documentation can be viewed using Clojure’s
doc function. For example, to view the documentation and usage examples for the
linear-model function, call
(doc linear-model) from the Clojure shell. Use
(find-doc "search term") to search the online documentation from the Clojure shell. The API documentation can also be found at http://liebke.github.com/incanter.
The Clojure Data Analysis Cookbook (published by Packt Publishing) contains several chapters dedicated to Incanter, including work with datasets, charting, etc. You can read the sample chapter that describes Incanter’s datasets.
There is dedicated mailing list for discussions about Incater. It’s hosted on Google Groups.
More Incanter examples
The following documentation covers the Incanter and Clojure APIs and the APIs of the underlying java libraries.
Related API documentation
1. Clone the repository with git:
git clone git://github.com/liebke/incanter.git
2. Install Leiningen (version 2.x)
a. Download the lein script:
(use lein.bat on Windows)
b. Place it on your path and chmod it to be executable:
chmod +x lein
script/install staying in the incanter directory – this will download all necessary dependencies, compile & install all Incanter’s modules into local Maven repository. The use of separate script is required because Incanter consists of several modules, and development versions are usually not available in official repositories.
4. Start a REPL:
lein repl (it also starts nRepl server), or start a Swank server:
lein ritz 4005
- If you want to run the tests for each of Incanter’s modules, use
- Each of Incanter’s modules are independent Leiningen projects. Just cd into modules/incanter-* and use Leiningen to build each one as a stand-alone library.
script/installuses Leiningen to build all the modules and install them in your local ~/.m2 repository.