Database Reference
In-Depth Information
We'll also use these requirements:
(require
'[incanter.core :as i]
'incanter.io
'[incanter.bayes :as b]
'[incanter.stats :as s])
For data, we'll use the census race table for Virginia, just as we did in the Differencing
Variables to Show Changes recipe.
How to do it…
For this recipe, we'll irst load the data, perform the Bayesian analysis, and inally summarize
the values from the distribution returned. We'll get the median, standard deviation, and
conidence interval:
1. First, we need to load the data. When we do, we'll rename the ields to make them
easier to work with. We'll also pull out a sample to work with, so we can compare our
results against the population when we're done:
(def census-race
(i/col-names
(incanter.io/read-dataset
"data/all_160_in_51.P3.csv"
:header true)
[:geoid :sumlev :state :county :cbsa :csa :necta
:cnecta :name :pop :pop2k :housing :housing2k :total
:total2k :white :white2k :black :black2k :indian
:indian2k :asian :asian2k :hawaiian :hawaiian2k
:other :other2k :multiple :multiple2k]))
(def census-sample (s/sample census-race :size 60))
2.
We'll now pull out the race columns and total them:
(def race-keys
[:white :black :indian :asian :hawaiian :other :multiple])
(def race-totals
(into {}
(map #(vector % (i/sum (i/$ % census-sample)))
race-keys)))
3.
Next, we'll pull out just the sums from the totals map:
(def y (map second (sort race-totals)))
 
Search WWH ::




Custom Search