Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 49 lines (43 sloc) 1.594 kb
8938087 Adam Ashenfelter Porting project
authored
1 (ns partisanship.metrics
2 (:import (java.lang Math))
3 (:require (partisanship.data [vote :as vote])))
4
5 (defn approval
6 "Returns the approval ratio of the vote, either overall or for the given
7 party."
8 ([vote]
9 (let [votes (vals (select-keys (:outcome vote) [:D :R]))
10 yeas (reduce + 0 (remove nil? (map :yea votes)))
11 total (double (reduce + 0 (flatten (map vals votes))))]
12 (when (pos? total)
13 (/ yeas total))))
14 ([party vote]
15 (let [outcome (party (:outcome vote))
16 total (double (reduce + 0 (vals outcome)))]
17 (when (pos? total)
18 (/ (:yea outcome 0) total)))))
19
20 (defn partisanship
21 "The partisanship score for a vote. 1 indicates maximum partisanship
22 (Reps and Dems voting completely opposite). 0 indicates no difference
23 in voting behavior between parties."
24 [vote]
25 (let [dem-approval (approval :D vote)
26 rep-approval (approval :R vote)]
27 (when (and dem-approval rep-approval)
28 (Math/abs (- dem-approval rep-approval)))))
29
30 (defn- contest [vote-approval]
31 (when vote-approval
32 (* 2 (Math/abs (- 0.5 vote-approval)))))
33
34 (defn unity
35 "The overall unity for a vote. 1 indicates complete agreement and 0
36 indicates total disagreement (50/50 split). If a party is given, the
37 unity score represents party unity on the vote."
38 ([vote]
39 (contest (approval vote)))
40 ([party vote]
41 (contest (approval party vote))))
42
43 (defn contested?
44 "Returns true if more than 10% of the votes are against the majority
45 opinion."
46 [vote]
47 (when-let [score (unity vote)]
48 (> 0.80 score)))
Something went wrong with that request. Please try again.