This repository has been archived by the owner on Sep 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sentence-by-race-pdf.Rmd
159 lines (124 loc) · 3.55 KB
/
sentence-by-race-pdf.Rmd
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
---
header-includes:
- \input{preamble.tex}
fontsize: 10pt
output: pdf_document
sansfont: RobotoCondensed
font: RobotoCondensed
geometry: "left=1in,right=1in,top=0.35in,bottom=0.6in"
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE,
warning = FALSE,
message = FALSE,
dev = "cairo_pdf")
library(ojodb)
last_quarter_end <- (floor_date(Sys.Date(), "quarter") - days(1)) %>%
as.character
connect_ojo()
sd <- ojo_tbl("doc_sentences") %>%
filter(js_date >= "2009-07-01",
js_date <= last_quarter_end,
!is.na(doc_incarcerated_term_yrs)) %>%
left_join(ojo_tbl("doc_offense")) %>%
collect()
pd <- ojo_tbl("doc_profile") %>%
filter(doc_num %in% !!sd$doc_num) %>%
collect()
disconnect_ojo()
race_pop <- read_csv("County populations by race, 2010-2018.csv")
sents <- sd %>%
mutate(doc_num = as.integer(doc_num),
fy = date_to_fy(js_date),
county = str_remove(doc_sentencing_county, " COUNTY.*") %>%
str_trim) %>%
group_by(doc_num, county, fy) %>%
arrange(desc(doc_incarcerated_term_yrs)) %>%
slice(1) %>%
left_join(pd %>%
mutate(doc_num = as.integer(doc_num)) %>%
select(doc_num,
sex,
race))
```
\ojologo{}
\ojotitle{Oklahoma DOC Equity Report}
# Male and female sentences
## Sentences by race and fiscal year, all counties
```{r}
sent_table <- function(county_filter = unique(sents$county), sex_filter = c("M", "F")) {
t <- sents %>%
filter(county %in% county_filter, sex %in% sex_filter) %>%
ungroup %>%
count(year = fy, race) %>%
pivot_wider(names_from = year, values_from = n) %>%
arrange(race)
return(t)
}
perc_table <- function(d) {
t <- {{d}} %>%
pivot_longer(cols = matches("\\d"), values_to = "n") %>%
group_by(year = name) %>%
summarize(`Percent White` = sum(n[which(race == "WHITE")])/sum(n, na.rm = TRUE),
`Percent Black` = sum(n[which(race == "BLACK")])/sum(n, na.rm = TRUE)) %>%
pivot_longer(matches("perc")) %>%
mutate(value = paste0(round(value*100, 1), "%")) %>%
pivot_wider(names_from = year, values_from = value)
return(t)
}
amf <- sent_table()
knitr::kable(amf)
knitr::kable(perc_table(amf))
```
## Sentences by race and fiscal year, Tulsa County
```{r}
tmf <- sent_table("TULSA")
knitr::kable(tmf)
knitr::kable(perc_table(tmf))
```
## Sentences by race and fiscal year, Oklahoma County
```{r}
omf <- sent_table("OKLAHOMA")
knitr::kable(omf)
knitr::kable(perc_table(omf))
```
\pagebreak
# Female sentences
## Female sentences by race and fiscal year, all counties
```{r}
af <- sent_table(sex_filter = "F")
knitr::kable(af)
knitr::kable(perc_table(af))
```
## Female sentences by race and fiscal year, Tulsa County
```{r}
tf <- sent_table("TULSA", sex_filter = "F")
knitr::kable(tf)
knitr::kable(perc_table(tf))
```
## Female sentences by race and fiscal year, Oklahoma County
```{r}
of <- sent_table("OKLAHOMA", sex_filter = "F")
knitr::kable(of)
knitr::kable(perc_table(of))
```
\pagebreak
# Male sentences
## Male sentences by race and fiscal year, all counties
```{r}
am <- sent_table(sex_filter = "M")
knitr::kable(am)
knitr::kable(perc_table(am))
```
## Male sentences by race and fiscal year, Tulsa County
```{r}
tm <- sent_table("TULSA", sex_filter = "M")
knitr::kable(tm)
knitr::kable(perc_table(tm))
```
## Male sentences by race and fiscal year, Oklahoma County
```{r}
om <- sent_table("OKLAHOMA", sex_filter = "M")
knitr::kable(om)
knitr::kable(perc_table(om))
```