Judicial Analytics
An Exploration of the Influence of Partisan Politics on the US Circuit Judges from 1927 to 2010
Carp-Manning U.S. District Court Database
Robert A. Carp and Kenneth L. Manning. 2016. “U.S. District Court Database.” 2016 version n=110977. URL: http://districtcourtdatabase.org
Team challenges: We have very limited coding experience.
Team accomplishments: We improved our comfort levels in R and Python by diving into the analysis of an unknown dataset.
R code
mydata <- hackathon #csv file
install.packages("remotes")
library('devtools') install_github('brooksandrew/Rsenal')
library('Rsenal')
install.packages("devtools")
remotes::install_github("brooksandrew/Rsenal")
??Rsenal
install.packages("ggplot2")
library(ggplot2) library(gridExtra) library(grid) library(cluster) library(data.table)
ave_dec <- aggregate(mydata[, 9:10], list(mydata$year), mean)
st.err <- function(x) { sd(x)/sqrt(length(x)) }
ste <- aggregate(mydata[, 9:10], list(mydata$year), st.err)
ave_dec
dec_yr_cir <- aggregate(mydata[, 9:10], list(mydata$year), mean)
dec_yr_cir1 <- aggregate(mydata[, 9:10], list(mydata$year, mydata$circuit), mean)
dec_yr_cir_typ <- aggregate(mydata[, 9:10], list(mydata$year, mydata$circuit, mydata$casetype), mean)
dec_yr_cir_typ
dec_yr_cir_gen <- aggregate(mydata[, 9:10], list(mydata$year, mydata$circuit, mydata$gender), mean)
nrow(dec_yr_cir1)
lvl <- levels(as.factor(mydata$year)) mydata <- cbind(mydata, "avg" = rep(NA, nrow(mydata))) for (i in 1:nrow(mydata)) { for ( l in lvl ) { if (mydata$year[i] == l) { mydata$avg[i] <- ave_dec$libcon[which(ave_dec$year == l)] }}} times <- c(1927, 2010) subst_times <- NULL for ( i in 1:nrow(mydata)) { if ( mydata$year[i] > times[1] & mydata$year[i] < times[2] ){ subst_times <- rbind(subst_times, mydata[i,]) } } breaks <- NULL i <- 1928 while ( i <= 2010){ breaks <- c(breaks, i) i <- i + 4 }
lvl <- levels(as.factor(mydata$year))
mydata <- cbind(mydata, "ste" = rep(NA, nrow(mydata)))
for (i in 1:nrow(mydata)) {
for ( l in lvl ) {
if (mydata$year[i] == l) {
mydata$avg[i] <- ste$libcon[which(ste$year == l)]
}}}
times <- c(1927, 2010)
subst_times <- NULL
for ( i in 1:nrow(mydata)) {
if ( mydata$year[i] > times[1] & mydata$year[i] < times[2] ){
subst_times <- rbind(subst_times, mydata[i,])
}
}
breaks <- NULL
i <- 1928
while ( i <= 2010){
breaks <- c(breaks, i)
i <- i + 4
}
mydata <- mydata[,-c(20:21)]
ggplot() + geom_point(data=mydata, mapping=aes(x = mydata$year, y = mydata$avg)) + theme_classic() + geom_hline(yintercept = .5, color = "red") #+ geom_vline(xintercept = breaks)
mydata2 <- mydata2[,-c(20:21)] ggplot() + geom_point(data=mydata2, mapping=aes(x = mydata2$year, y = mydata2$avg)) + theme_classic() + geom_hline(yintercept = .5, color = "red") #+ geom_vline(xintercept = breaks)
ggplot() + geom_smooth(data=dec_yr_cir1, mapping=aes(x = dec_yr_cir1$year, y = dec_yr_cir1$libcon, colour=factor(dec_yr_cir1$Group.2)), se = F) + theme_classic() + geom_hline(yintercept = .5, color = "red")
ggplot() + geom_smooth(data=dec_yr_cir1, mapping=aes(x = dec_yr_cir1$year, y = dec_yr_cir1$libcon), se = T) + theme_classic() + geom_hline(yintercept = .5, color = "red") + facet_grid(rows=vars(Group.2))
ggplot() + geom_smooth(data=dec_yr_cir_gen, mapping=aes(x = dec_yr_cir_gen$year, y = dec_yr_cir_gen$libcon, colour=factor(dec_yr_cir_gen$Group.3)), se = T) + theme_classic() + geom_hline(yintercept = .5, color = "red") #keep female vs male US judges, period where female judges were significantly
ggplot() + geom_smooth(data=dec_yr_cir_gen, mapping=aes(x = dec_yr_cir_gen$year, y = dec_yr_cir_gen$libcon, colour=factor(dec_yr_cir_gen$Group.3)), se = T) + theme_classic() + geom_hline(yintercept = .5, color = "red") + facet_grid(cols =vars(Group.2))
dec_party_typ <- aggregate(mydata[, 10:11], list(mydata$casetype, mydata$party), mean)
dec_party_typ
party ratio per year
repcount <- aggregate(mydata[, 9:10], tally(mydata$party), )
repcount <- mydata %>%
group_by(year, mydata$party="2") %>%
summarise(rep_judges=n()) #%>%
#arrange(desc(year))
repcount
colnames(repcount)[colnames(repcount)=="party"] <- "repJs"
demcount <- mydata %>%
group_by(year, party="1") %>%
summarise(dem_judges=n()) #%>%
arrange(desc(year))
repcount <- mydata repcount <- mydata[ which(mydata$party=='2' & mydata$age > 65), ]
demcount colnames(demcount)[colnames(demcount)=="party"] <- "demJs"
hackathon.tjl
poltrendA <- merge(ave_dec, repcount) poltrend <- merge(poltrendA, demcount)
write.csv(mydata, file = "MyData.csv")
ratiorepdem <- aggregate(mydata[, 9:10], list(mydata$year, mydata$circuit), mean)
ggplot() + geom_line(data=mydata, mapping=aes(x =mydata$year, y=dec_party_typ$libcon, color=(dec_party_typ$Group.2))) + theme_classic()+ coord_flip()
Log in or sign up for Devpost to join the conversation.