Skip to content

Instantly share code, notes, and snippets.

@paulosuzart
Created August 15, 2010 23:38
Show Gist options
  • Save paulosuzart/526090 to your computer and use it in GitHub Desktop.
Save paulosuzart/526090 to your computer and use it in GitHub Desktop.
(ns lemo
(:use (incanter core io charts stats)))
(def lemo (read-dataset "lemo.txt"
:header true
:delim \;))
(defn bar [data title]
(bar-chart ["p" "a" "m" "c"]
data
:title title
:x-label "Motivational Style"
:y-label "Degree"))
(defn line [n p]
(doto (line-chart ["Normal" "Pressure"]
[(sd n) (sd p)]
:title "Standard Deviation"
:y-label "Deviation"
:x-label "Condition")
(add-subtitle "From Normal to Pressure Conditions")))
(let [[norm press] (->> lemo
to-matrix
(partition-all 9)
(map trans)
(map #(map sum %)))]
(view (bar norm "Normal Conditions"))
(view (bar press "Under Pressure"))
(view (line norm press)))
;;lemo test can be loaded from http://gist.github.com/526089
@paulosuzart
Copy link
Author

I could avoid the trans before sum if the data were already transposed. But it would force me sum columns with offset, say 6.

@citizen428
Copy link

If I just download your dataset the program chokes on the comment in the fist line.

Some suggestions:

(use '(incanter core io))
(def lemo (read-dataset "lemo.txt"
           :header true
           :delim \;))

(let [calc #(map sum (trans (to-matrix (sel lemo % (range 9)))))
      norm (calc :rows) 
      press (calc :except-rows)]
  (view (map - norm press)))

I basically removed unnecessary Incanter libs, put the repetitive code in a stupidly named helper and cleaned up the map calls (no need for anonymous functions there).

@paulosuzart
Copy link
Author

oh my gosh! Now I see FP. I still have a imperative root that will go away soon! Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment