-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhillyBail.R
More file actions
44 lines (35 loc) · 1.34 KB
/
PhillyBail.R
File metadata and controls
44 lines (35 loc) · 1.34 KB
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
setwd('~/Downloads/OwlHacks\ 2020\ Submission/OwlHacks\ Proj')
# Call install.packages(<package string>) if not installed
library(purrr)
library(predictrace)
library(dplyr)
data <- read.csv('all.csv')
# Thx Wikipedia
phila_race_dem <- data.frame(
'race' = c('Black', 'White', 'Hispanic', 'Asian', 'Islander', 'Native American', '2+'),
'percentage' = c(0.426, 0.416, 0.141, 0.071, 0.0005, 0.004, 0.028))
# x is column of names, u is unique bool
nameProbs <- function (x, u) {
retVals <- vector()
looper <- strsplit(x, ',')
if (u) {
looper <- unique(looper)
}
for (name in looper) {
retVals <- append(unlist(name)[1], retVals)
}
return(predict_race(retVals) %>% filter(!is.na(likely_race)))
}
# Predicted race of ppl setting bail unweighted
bail_unw <- colSums(nameProbs(data$bail_set_by, TRUE)[4:9])
# Predicted race of ppl setting bail weighted by # of occurances
bail_w <- colSums(nameProbs(data$bail_set_by, FALSE)[4:9])
# Predicted race of arresting officer unweighted
off_unw <-colSums(nameProbs(data$arresting_officer, TRUE)[4:9])
# Predicted race of arresting officer weighted by occurances
off_w <- colSums(nameProbs(data$arresting_officer, FALSE)[4:9])
write.csv(bail_unw, 'bail_unw.csv')
write.csv(bail_w, 'bail_w.csv')
write.csv(off_unw, 'off_unw.csv')
write.csv(off_w, 'off_w.csv')
write.csv(phila_race_dem, 'phila_race_dem.csv')