-
Notifications
You must be signed in to change notification settings - Fork 0
/
factcheck.qmd
268 lines (196 loc) · 8.75 KB
/
factcheck.qmd
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
# IMPORT
```{r}
library(tidyverse)
library(janitor)
library(lubridate)
library(readxl)
grouper <- function(input_df, group_by_column, new_column_name = "n()"){
output_df <- input_df %>%
group_by(.data[[group_by_column]]) %>%
summarise(temp_count = n()) %>%
mutate(percent = temp_count/sum(temp_count)*100) %>%
arrange(desc(percent)) %>%
rename(!!new_column_name := temp_count)
return(output_df)
}
group_count <- function(input_df, group_column_name='n()', state_filter=NA, start_col = 1){
column_names <- colnames(input_df)
if(!is.na(state_filter)){
input_df <- input_df %>%
filter(state == state_filter)
}
for (column in column_names[start_col:length(column_names)]){
output <- grouper(input_df, column, group_column_name)
print(output)
}
}
round_df <- function(x, digits) {
# round all numeric variables
# x: data frame
# digits: number of digits to round
numeric_columns <- sapply(x, mode) == 'numeric'
x[numeric_columns] <- round(x[numeric_columns], digits)
x
}
```
```{r}
#this code shows how the original was cleaned before unstructured text responses were classified
convert_column_to_logical <- function(input_df, column_name) {
column_name <- enquo(column_name)
output_df <- input_df %>%
mutate({{ column_name }} := case_when(
{{ column_name }} == "X" ~ TRUE,
is.na({{ column_name }}) ~ FALSE
))
return(output_df)
}
survey <- read_excel("data/permits_survey results.xlsx")
col_names <- paste(survey[1, ], survey[2, ], sep = "_")
col_names <- gsub("NA", "", col_names)
survey <- survey %>%
set_names(col_names) %>%
clean_names() %>%
slice(3:nrow(survey)) %>%
select(-submission_details_submitted_time) %>%
rename(property_owner = are_you_a_property_owner_contractor_or_professional_permit_processor_property_owner) %>%
convert_column_to_logical(property_owner) %>%
convert_column_to_logical(contractor) %>%
convert_column_to_logical(professional_permit_processor) %>%
mutate(overall_experience_obtaining_a_permit = case_when(
how_would_you_rate_your_overall_experience_obtaining_a_permit_from_the_city_of_baltimore_very_easy == "X" ~ "very easy",
easy == "X" ~ "easy",
somewhat_difficult == "X" ~ "somewhat difficult",
difficult == "X" ~ "difficult",
very_difficult == "X" ~ "very difficult"
)) %>%
select(-c(how_would_you_rate_your_overall_experience_obtaining_a_permit_from_the_city_of_baltimore_very_easy, easy, somewhat_difficult, difficult, very_difficult)) %>%
relocate(property_owner, contractor, professional_permit_processor, overall_experience_obtaining_a_permit) %>%
rename(use_permit = what_type_of_work_were_you_seeking_a_permit_to_perform_what_permit_service_did_you_apply_check_all_that_apply_use_permit) %>%
convert_column_to_logical(use_permit) %>%
convert_column_to_logical(demo_permit) %>%
convert_column_to_logical(construction_permit_building_inspection) %>%
convert_column_to_logical(construction_permit_construction) %>%
convert_column_to_logical(construction_permit_encroachment_plan_planning) %>%
convert_column_to_logical(construction_permit_encroachment_plan_fire) %>%
convert_column_to_logical(construction_permit_permit_extensions) %>%
convert_column_to_logical(construction_permit_demolition) %>%
convert_column_to_logical(construction_permit_electrical) %>%
convert_column_to_logical(construction_permit_gas_hvac) %>%
mutate(were_you_aware_that_dhcd_provides_online_tutorials_and_training_session_on_the_permitting_process = case_when(
were_you_aware_that_dhcd_provides_online_tutorials_and_training_session_on_the_permitting_process_yes == "X" ~ "yes",
no == "X" ~ "no"
)) %>%
select(-c(were_you_aware_that_dhcd_provides_online_tutorials_and_training_session_on_the_permitting_process_yes, no)) %>%
mutate(have_you_ever_utilized_an_of_the_online_tutorials_available_on_the_dhcd_website_to_assist_in_obtaining_your_permit = case_when(
have_you_ever_utilized_an_of_the_online_tutorials_available_on_the_dhcd_website_to_assist_in_obtaining_your_permit_yes == "X" ~ "yes",
no_2 == "X" ~ "no"
)) %>%
select(-c(have_you_ever_utilized_an_of_the_online_tutorials_available_on_the_dhcd_website_to_assist_in_obtaining_your_permit_yes, no_2
)) %>%
unique() %>%
mutate(row_id = row_number()) %>%
relocate(row_id)
```
```{r}
#this version includes manual classification by the baltimore banner
survey <- read_csv("data/clean-survey.csv")
```
# FACTCHECK
## "Not all reviews were negative, but nearly four out of every five respondents said the process was difficult."
```{r}
glimpse(survey)
t <- survey %>%
mutate(difficult = case_when(
str_detect(overall_experience_obtaining_a_permit, "difficult") ~ TRUE,
TRUE ~ FALSE
)) %>%
group_by(difficult) %>%
count()
t %>%
mutate(perc = n/sum(t$n))
```
## "More than one in three said it was very difficult."
```{r}
grouper(survey, "overall_experience_obtaining_a_permit")
```
## "More than a third of survey respondents said it took longer than 60 days to get their permit approved or denied."
```{r}
grouper(survey, "approximately_how_long_did_it_take_from_the_time_you_applied_for_your_permit_to_receiving_an_approval_or_denial")
```
## "Getting encroachment plan permits — which authorize work on city and state-owned land — take the longest."
```{r}
use_permit <- survey %>%
filter(use_permit == TRUE)
demo_permit <- survey %>%
filter(demo_permit == TRUE)
construction_permit_building_inspection <- survey %>%
filter(construction_permit_building_inspection == TRUE)
construction_permit_construction <- survey %>%
filter(construction_permit_construction == TRUE)
construction_permit_encroachment_plan_fire <- survey %>%
filter(construction_permit_encroachment_plan_fire == TRUE)
construction_permit_encroachment_plan_planning <- survey %>%
filter(construction_permit_encroachment_plan_planning == TRUE)
construction_permit_permit_extensions <- survey %>%
filter(construction_permit_permit_extensions == TRUE)
construction_permit_demolition <- survey %>%
filter(construction_permit_demolition == TRUE)
construction_permit_electrical <- survey %>%
filter(construction_permit_electrical == TRUE)
construction_permit_gas_hvac <- survey %>%
filter(construction_permit_gas_hvac == TRUE)
calc_and_pivot_df <- function(party, group_by_column){
input_df <- eval(parse(text = party))
temp_input_df <- input_df %>%
group_by(.data[[group_by_column]]) %>%
count() %>%
ungroup()
raw_input_df <- temp_input_df %>%
pivot_wider(values_from = n, names_from = .data[[group_by_column]]) %>%
mutate(party = party,
type = "raw") %>%
relocate(party, type)
perc_input_df <- temp_input_df %>%
mutate(percent = (n/sum(n))*100) %>%
select(-n) %>%
pivot_wider(values_from = percent, names_from = .data[[group_by_column]]) %>%
mutate(party = party,
type = "perc") %>%
relocate(party, type)
return(raw_input_df %>%
bind_rows(perc_input_df) %>%
clean_names())
}
analyze_column_by_permit <- function(group_by_column, digits=1) {
#group_by_column <- "approximately_how_long_did_it_take_from_the_time_you_applied_for_your_permit_to_receiving_an_approval_or_denial"
t1 <- calc_and_pivot_df("use_permit", group_by_column)
t2 <- calc_and_pivot_df("demo_permit", group_by_column)
t4 <- calc_and_pivot_df('construction_permit_building_inspection', group_by_column)
t5 <- calc_and_pivot_df('construction_permit_construction', group_by_column)
t6 <- calc_and_pivot_df('construction_permit_encroachment_plan_fire', group_by_column)
t7 <- calc_and_pivot_df('construction_permit_encroachment_plan_planning', group_by_column)
t8 <- calc_and_pivot_df('construction_permit_permit_extensions', group_by_column)
t9 <- calc_and_pivot_df('construction_permit_demolition', group_by_column)
t10 <- calc_and_pivot_df('construction_permit_electrical', group_by_column)
t11 <- calc_and_pivot_df('construction_permit_gas_hvac', group_by_column)
output <- t1 %>%
bind_rows(t2, t4, t5, t6, t7, t8, t9, t10, t11)
return(output %>%
round_df(digits))
}
analyze_column_by_permit("approximately_how_long_did_it_take_from_the_time_you_applied_for_your_permit_to_receiving_an_approval_or_denial") %>%
filter(type == "raw") %>%
arrange(desc(greater_than_60_days))
```
## "About one-third of respondents specifically cited poor communication and long response times as the biggest challenges to getting permits."
```{r}
grouper(survey, "challenge_poor_communication_response_time")
```
## "More than 50 survey respondents said they had encountered “rude” city employees or received conflicting information."
```{r}
survey %>%
filter(challenge_conflicting_info == TRUE) %>%
bind_rows(survey %>%
filter(challenge_rude_difficult_staff == TRUE)) %>%
unique()
```