View Lib.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE OverloadedStrings #-} | |
{-# LANGUAGE DeriveGeneric #-} | |
-- needed for creating [Char] instances | |
{-# LANGUAGE FlexibleInstances #-} | |
-- Use the following to allow records to have name field names. | |
-- {-# LANGUAGE DuplicateRecordFields #-} | |
module Lib |
View incanter-excel.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use '(incanter core charts excel)) | |
;; read .xls file of Australian airline passenger data from the 1950s. | |
(with-data (read-xls "http://incanter.org/data/aus-airline-passengers.xls") | |
(view $data) | |
;; time-series-plot needs time in millisecs | |
;; create a function, to-millis, to convert a sequence of Date objects | |
;; to a sequence of milliseconds | |
(let [to-millis (fn [dates] (map #(.getTime %) dates))] | |
(view (time-series-plot (to-millis ($ :date)) ($ :passengers))))) |
View infix_examples.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use 'incanter.core) | |
;; basic arithmetic | |
($= 7 + 8 - 2 * 6 / 2) ; => 9 | |
;; add 5 to each element of the vector [1 2 3] | |
($= [1 2 3] + 5) ; => (6 7 8) |
View repl.bat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
setLocal EnableDelayedExpansion | |
set CLASSPATH=" | |
for /R ./lib %%a in (*.jar) do ( | |
set CLASSPATH=!CLASSPATH!;%%a | |
) | |
set CLASSPATH=!CLASSPATH!" | |
set CLASSPATH=%CLASSPATH%;src;test;config;data | |
echo CLASSPATH=%CLASSPATH% | |
java -Xmx1G -cp %CLASSPATH% jline.ConsoleRunner clojure.main -e "(use '[clojure.contrib.duck-streams :only (spit read-lines reader writer)] '[clojure.contrib def ns-utils pprint repl-utils shell-out]) (require '[clojure.contrib.str-utils2 :as s])" -r |
View simple_interaction.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use '(incanter core processing)) | |
;; simple interactive Processing example taken from processingjs.org website: | |
;; http://processingjs.org/source/basic-example/processingjs_basic-example.html | |
;; set up variable references to use in the sketch object | |
(let [radius (ref 50.0) | |
X (ref nil) | |
Y (ref nil) |
View bootstrap_median.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; example with smoothing | |
;; Newcomb's speed of light data | |
(use '(incanter core stats charts)) | |
;; A numeric vector giving the Third Series of measurements of the | |
;; passage time of light recorded by Newcomb in 1882. The given | |
;; values divided by 1000 plus 24 give the time in millionths of a | |
;; second for light to traverse a known distance. The 'true' value is |
View bayes_multinomial.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Bayesian inference of multinomial distribution parameters | |
(use '(incanter core stats bayes charts)) | |
(def y [727 583 137]) | |
(div y 1447.) ;; (0.502 0.403 0.095) | |
View monty_hall.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Monty Hall problem (Let's Make a Deal gameshow) | |
;; http://www.marilynvossavant.com/articles/gameshow.html | |
(use '(incanter core stats charts)) | |
;; set a simulation sample size | |
(def n 10000) | |
;; generate samples of initial-guesses, prize-doors, and switch decisions | |
(def initial-guesses (sample [1 2 3] :size n)) | |
(def prize-doors (sample [1 2 3] :size n)) |
View benford_iran.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Chi-square goodness-of-fit analysis of 2009 Iranian election and Benford's law | |
(use '(incanter core stats charts io)) | |
(def votes (read-dataset "data/iran_election_2009.csv" | |
:header true)) | |
(view votes) | |
(def regions (sel votes :cols "Region")) | |
View means_permutation.clj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; significance testing with randomization | |
(use '(incanter core stats datasets charts)) | |
(def data (to-matrix (get-dataset :plant-growth))) | |
;; Break the first column of the data into groups based on | |
;; treatment type (second column) using the group-by function. | |
(def groups (group-by data 1 :cols 0)) | |
(t-test (first groups) :y (second groups)) |
NewerOlder