Database Reference
In-Depth Information
Getting ready
We'll need these dependencies:
(defproject statim "0.1.0"
:dependencies [[org.clojure/clojure "1.6.0"]
[incanter "1.5.5"]])
We'll also use these requirements:
(require
'[incanter.core :as i]
'incanter.io
'[incanter.stats :as s])
For data, we'll use the Virginia census race data ile that we can download from http://
www.ericrochester.com/clj-data-analysis/data/all_160_in_51.P35.csv .
How to do it…
Bendford's law has been observed in many other places, including population numbers. In this
recipe, we'll look at using it on the Virginia census data:
1.
First, of course, we'll load the data:
(def data-file "data/all_160_in_51.P35.csv")
(def data (incanter.io/read-dataset data-file :header true))
2.
Now we perform the analysis using the function incanter.stats/benford-
test . It returns a map containing some interesting tests and values for determining
whether the collection conforms to Benford's test. We can also use it to view a bar
chart of the distribution:
(def bt (s/benford-test (i/sel data :cols :POP100)))
3.
In the map that's returned, : X-sq is the value for the Χ² test, :df is the degrees of
freedom for the test, and :p-value is the p value for the test statistic:
user=> (:X-sq bt)
15.74894048668777
user=> (:df bt)
8
user=> (:p-value bt)
0.046117795289705776
 
Search WWH ::




Custom Search