Did I suggest, at the end of my last post, that I should do something a little more advanced? With Clojure that is! Well, I decided that I wished to play with a little data and display it. So, would this be easy or would the next step up, on the Clojure learning curve, leave me a little bewildered?
I happened to have a copy of “Statistics without Tears” by Derek Rowntree (not my original copy, that I parted with back in the UK many years ago, but the same version that I would have owned at the beginning of the 1980′s), which I think I bought before going to college, as I was a tad nervous about what I actually understood about statistics. Anyway, I flicked through and by about page 42 I spied a nice set of data that I could use. Purportedly a list of student heart rates.
Well, next step was to discover what tool to use with Clojure. I chose Incanter. It’s R like, for statistical computing and graphics! I don’t know R but I’ve used SAS, so how hard could it be?
I downloaded Incanter and used the REPL it supplied, as I am using Clojure 1.1 and this came with 1.2. Well I’m game, didn’t even know there was a 1.2.
The data set is simple, an array of heart rates. I immediately got to work making a quick vector, and the rest is as you see in the code.
;------
; pulse rates of 50 students
(def x [89 68 92 74 76 65 77 83 75 87 85 64 79 77 96 80 70 85 80 80 82 81 86 71 90 87 71 72 62 78 77 90 83 81 73 80 78 81 81 75 82 88 79 79 94 82 66 78 74 72])
(use '(incanter core stats charts))
; (with-data x (view $data)) ; yep, pops up a nice list of the data
; and just like that
(view (histogram x
:nbins 20
:title "Pulse rates of 50 students"
:x-label "Pulse rate (beats per minute)"
:y-label "Frequency (# of students in each grp)"))
(median x) ; 79.5
It is so little to do and yet the output is pretty much what is in my Rowntree book. Here is the main graphical result.
Wish I had done my first degree in the age of modern computing. Ah, home micros, peek and poke. My little brother’s ZX Spectrum and the Forth I acquired for it. How far we have come!




Pingback: Statistics and R | LEXECORP