-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathideal_justice_replication.R
133 lines (95 loc) · 3.91 KB
/
ideal_justice_replication.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# IDEAL JUSTICE REPLICATION
# Johan Lindholm, Umeå University
# 24 October 2021
#
# This script can be used to replicate the sequence analysis
# used for the paper 'The Ideal Justice'.
library(TraMineR)
library(WeightedCluster)
library(tidyverse)
# setup
par(mar = c(1,1,1,1)) # to ensure correct figure plotting
current_year <- as.integer(format(Sys.Date(), "%Y")) # current year used as variable in plotting
# load data
load("judges_info.RData") # load Justices' basic information
load("judges_seq.RData") # load Justices' backgrounds as sequences
# compute pairwise distances
judges_om <- seqdist(judges_seq, method = "OM", sm = "TRATE")
# generate cluster models
ward_cluster <- agnes(judges_om, diss = TRUE, method = "ward") # creates cluster object
# compare range of clusters
ward_range <- as.clustrange(ward_cluster, diss=judges_om, ncluster = 8) # creates cluster quality information on differetn number cluster solutions, up to 8 clusters
summary(ward_range, max.rank=5)
plot(ward_range,
stat=c("ASWw", "HG", "PBC", "HC"),
norm = "zscore")
ward_range <- as.clustrange(ward_cluster, diss=judges_om, ncluster = 10) # creates cluster quality information on different number cluster solutions, up to 8 clusters
# calculate transition probabilities and costs
trans_prob <- seqtrate(judges_seq) %>%
as_tibble() %>%
mutate(from = c("acad", "ct", "dep", "pol", "priv", "publ"),
.before = 1)
cost <- seqcost(judges_seq, method = "TRATE")
# plot clusters
seqplot(judges_seq,
group = ward_range$clustering$cluster6,
type = "I",
sortv = "from.end",
border = NA,
# cpal=brewer.pal(6, "Greys"),
xtlab = c(-100:-1))
# plot two-dimensional mds
judges_mds <- cmdscale(judges_om, 2)
mds <- tibble(x = judges_mds[,1],
y = judges_mds[,2],
community = ward_range$clustering$cluster6)
ggplot(mds,
aes(x = x,
y = y,
color = community)) +
geom_count(alpha = 0.35) +
labs(x = "",
y = "",
color = "Community")
# add cluster membership to Justices info
judges_info$membership <- ward_range$clustering$cluster6
mem_labels <- c("Ministry Judge", "Professor", "Public Servant Judge", "Practising Lawyer", "Career Judge", "Politician Judge")
judges_info$mem_labels <- mem_labels[judges_info$membership]
# plot types in Supreme Court over time
ggplot(filter(judges_info, court == "hd") %>%
group_by(start_decade, mem_labels) %>%
tally() %>%
mutate(all_n = sum(n)) %>%
mutate(per = n/all_n),
aes(y = per * 100,
x = start_decade)) +
lapply(c(1800, 1850, 1900, 1950, 2000), function(xint) geom_vline(aes(xintercept = xint), lty = 2, col = "grey")) +
scale_x_continuous(limits = c(1780, current_year)) +
scale_y_continuous(limits = c(0, 100)) +
# scale_fill_grey() +
geom_col(aes(fill = mem_labels)) +
facet_wrap(~mem_labels, nrow = 3) +
labs(y = "Percent of appointments",
x = "Appointment decade") +
theme(legend.position = "none",
axis.text.x = element_text(angle = 90),
panel.background = element_blank())
# plot types in Supreme Administrative Court over time
ggplot(filter(judges_info, court == "hfd") %>%
group_by(start_decade, mem_labels) %>%
tally() %>%
mutate(all_n = sum(n)) %>%
mutate(per = n/all_n),
aes(y = per * 100,
x = start_decade)) +
lapply(c(1800, 1850, 1900, 1950, 2000), function(xint) geom_vline(aes(xintercept = xint), lty = 2, col = "grey")) +
scale_x_continuous(limits = c(1780, current_year)) +
scale_y_continuous(limits = c(0, 100)) +
# scale_fill_grey() +
geom_col(aes(fill = mem_labels)) +
facet_wrap(~mem_labels, nrow = 3) +
labs(y = "Percent of appointments",
x = "Appointment decade") +
theme(legend.position = "none",
axis.text.x = element_text(angle = 90),
panel.background = element_blank())