generated from jhudsl/OTTR_Template_Website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PersonaStats.Rmd
327 lines (278 loc) · 9.07 KB
/
PersonaStats.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
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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
---
title: "Personas"
author: "Kate Isaac"
date: "`r Sys.Date()`"
output: html_document
---
```{r}
library(dplyr)
library(magrittr)
```
```{r}
source(knitr::purl("TidyData.Rmd", quiet=TRUE)) # Intended for interactive analysis
```
```{r}
kindOfWorkDF <-
resultsTidy %>%
select(Timestamp, KindOfWork) %>%
separate_longer_delim(KindOfWork, delim = ", ") %>%
mutate(
KindOfWork = recode(KindOfWork, "Program administration," = "Program administration", "computational education" = "Computational education"),
value = TRUE
) %>%
pivot_wider(names_from = KindOfWork, values_from = value, values_fill = FALSE)
```
## Number of reported kinds of work description for each response
add a column with the count of number of descriptions for each respondent and then use the table function to see how many responses gave 1, 2, 3, ... descriptions for their kind of work
```{r}
numSelected <- kindOfWorkDF %>%
select(!Timestamp) %>%
rowSums()
numSelectedDF <- tibble("X" = numSelected) %>%
count(X) %>%
mutate(percentage_responses = round(n / nrow(resultsTidy) * 100, 0))
numSelectedDF
```
## What were the most common single responses
```{r}
singleResponseRows <- which(rowSums(kindOfWorkDF[2:ncol(kindOfWorkDF)]) == 1) # these rows are responses where they only provided one description
tibble("description" = unlist(lapply(1:length(singleResponseRows), function(x) colnames(kindOfWorkDF)[which(kindOfWorkDF[singleResponseRows[x], ] == TRUE)]))) %>% # for those rows, find the corresponding columns that are true and add the column names to a vector
count(description) %>% # count the number of times each of those descriptions is there
arrange(-n) # arrange in descending order
```
## What were the most common pairs of responses (no matter how many kinds of work descriptions were provided)
Look at [this solution from stackoverflow to find pairs](https://stackoverflow.com/a/62374554), but it only works to find pairs that are right next to each other, ugh. So just wrote my own function.
note that the first column of `kindOfWorkDF` is a timestamp and we don't want that one for this
note also `combn` will also fail if there aren't enough non-NA values, so we want to only select rows with more than one description
Given those two notes, pass this function the following input data frame
`kindOfWorkDF[which(rowSums(kindOfWorkDF[,2:ncol(kindOfWorkDF)]) > 1),-c(1)]`
```{r}
find_pairs <- function(inputDF, rowOI) {
pairs <- c()
notNA_cols_combos <- t(combn(which(inputDF[rowOI, ] == TRUE), 2)) # rows will be indices for each pair
for (rowIndex in 1:nrow(notNA_cols_combos)) {
pairs <- c(pairs, paste0(unlist(colnames(inputDF)[notNA_cols_combos[rowIndex, ]]), collapse = "-"))
}
return(pairs)
}
```
```{r}
numSelectedDF %<>%
mutate(X = as.integer(X))
kindOfWorkDF_subset <- kindOfWorkDF[which(rowSums(kindOfWorkDF[, 2:ncol(kindOfWorkDF)]) > 1), -c(1)]
pairs_all <- unlist(lapply(
1:nrow(kindOfWorkDF_subset),
function(x) find_pairs(kindOfWorkDF_subset, x)
)) %>%
as.data.frame() %>%
`colnames<-`(c("pairs")) %>%
group_by(pairs) %>%
mutate(count = n()) %>%
ungroup() %>%
distinct() %>%
arrange(-count) %>%
mutate(
percentage_notSingleDescription_responses =
round(count / sum(numSelectedDF[which(numSelectedDF$X > 1), "n"]) * 100, 0)
)
print(pairs_all, n = nrow(pairs_all))
```
This percentage sums to greater than 100, but I think because the pairs are made whether there a respondent provided 2, 3, or 5 descriptions so there will be more pairs than responses that had pairs possible, so not sure if the percentage is helpful or not.
## How many times was each description selected/reported
```{r}
numResponsesPerDescription <- data.frame("n" = colSums(kindOfWorkDF[, 2:ncol(kindOfWorkDF)])) %>%
arrange(-n)
numResponsesPerDescription
```
## Flag personas given all this info
```{r}
resultsTidy %<>%
mutate(
clinical_flag = str_detect(KindOfWork, "Clinical"), # any clinical
compOnly_flag = (tolower(KindOfWork) == "computational work"), # only computational
education_flag = str_detect(KindOfWork, "education") # any education
)
resultsTidy$decision_flag <- unlist(lapply(1:nrow(resultsTidy), function(x) {
(all(
str_detect(
tolower(resultsTidy$KindOfWork[x]),
c(
"(project leadership|project management|program administration)",
"computational work"
)
)
))
})) # function of projects + making decisions
resultsTidy$admin_flag <- unlist(lapply(1:nrow(resultsTidy), function(x) {
!any(str_detect(
tolower(resultsTidy$KindOfWork[x]), tolower(tolower(setdiff(
colnames(kindOfWorkDF)[2:(ncol(kindOfWorkDF) - 2)],
c(
"Project leadership",
"Project management",
"Program administration"
)
)))
))
})) # project steering or admin only (the project or program descriptions only)
```
### Which ones don't have an assigned persona?
```{r}
resultsTidy$KindOfWork[which(rowSums(resultsTidy[, c(
"clinical_flag",
"compOnly_flag",
"education_flag",
"decision_flag",
"admin_flag"
)]) == 0)]
```
### Which ones have more than one assigned persona and how do we pick one?
```{r}
resultsTidy$KindOfWork[which(rowSums(resultsTidy[, c(
"clinical_flag",
"compOnly_flag",
"education_flag",
"decision_flag",
"admin_flag"
)]) == 2)]
```
First appears to be education while the second appears to be decision (because of the leadership and management being present or having education + more than 2 other descriptions)
```{r}
which_rows <- which(rowSums(resultsTidy[, c(
"clinical_flag",
"compOnly_flag",
"education_flag",
"decision_flag",
"admin_flag"
)]) == 2)
updates <- data.frame(
Timestamp =
c(resultsTidy$Timestamp[which_rows[1]], resultsTidy$Timestamp[which_rows[2]]),
education_flag =
c(TRUE, FALSE),
decision_flag =
c(FALSE, TRUE)
)
resultsTidy %<>% dplyr::rows_update(updates, by = "Timestamp")
```
## Assign persona categories and save data (contact willingness, timestamp, UserType etc) for each persona
```{r}
# CLINICIANS
clinician_persona <- resultsTidy %>%
filter(clinical_flag == TRUE) %>%
group_by(UserType, ContactWillingness) %>%
mutate(
count = n(),
persona = "Clinician"
) %>%
select(UserType, persona, ContactWillingness, count, Email, Timestamp) %>%
arrange(-count) %>%
distinct()
```
```{r}
# ANALYSTS
analyst_persona <- resultsTidy %>%
filter(compOnly_flag == TRUE) %>%
group_by(UserType, ContactWillingness) %>%
mutate(
count = n(),
persona = "Analyst"
) %>%
select(UserType, persona, ContactWillingness, count, Email, Timestamp) %>%
arrange(-count) %>%
distinct()
```
```{r}
# EDUCATORS
educator_persona <- resultsTidy %>%
filter(education_flag == TRUE) %>%
group_by(UserType, ContactWillingness) %>%
mutate(
count = n(),
persona = "Educator"
) %>%
select(UserType, persona, ContactWillingness, count, Email, Timestamp) %>%
arrange(-count) %>%
distinct()
```
```{r}
# DECISION MAKERS/PIs?
pi_persona <- resultsTidy %>%
filter(decision_flag == TRUE) %>%
group_by(UserType, ContactWillingness) %>%
mutate(
count = n(),
persona = "PI"
) %>%
select(UserType, persona, ContactWillingness, count, Email, Timestamp) %>%
arrange(-count) %>%
distinct()
```
```{r}
# ADMIN
admin_persona <- resultsTidy %>%
filter(admin_flag == TRUE) %>%
group_by(UserType, ContactWillingness) %>%
mutate(
count = n(),
persona = "Admin"
) %>%
select(UserType, persona, ContactWillingness, count, Email, Timestamp) %>%
arrange(-count) %>%
distinct()
```
```{r}
no_persona <- resultsTidy %>%
filter(clinical_flag == FALSE & compOnly_flag == FALSE & education_flag == FALSE & decision_flag == FALSE & admin_flag == FALSE) %>%
group_by(UserType, ContactWillingness) %>%
mutate(
count = n(),
persona = "None Assigned"
) %>%
select(UserType, KindOfWork, persona, ContactWillingness, count, Email, Timestamp) %>%
arrange(-count) %>%
distinct()
```
```{r, eval=FALSE}
save(clinician_persona,
analyst_persona,
educator_persona,
pi_persona,
admin_persona,
no_persona,
file = here("data/persona_classifications.rdata")
)
```
```{r}
persona_df <- rbind(
clinician_persona,
analyst_persona,
educator_persona,
pi_persona,
admin_persona,
no_persona
) %>% select(-count)
```
```{r}
resultsTidy %<>%
mutate(
persona = case_when(
clinical_flag == TRUE ~ "Clinician",
compOnly_flag == TRUE ~ "Analyst",
education_flag == TRUE ~ "Educator",
decision_flag == TRUE ~ "PI",
admin_flag == TRUE ~ "Admin",
clinical_flag == FALSE & compOnly_flag == FALSE & education_flag == FALSE & decision_flag == FALSE & admin_flag == FALSE ~ "None assigned"
)
)
```
```{r, eval=FALSE}
ssPersonas <- gs4_create(name = "StateOfTheAnVIL_ResponsesPersonas", sheets = c("Personas", "AllResultsWithPersonas"))
```
```{r, eval=FALSE}
sheet_write(data = persona_df, ss = ssPersonas, sheet = "Personas")
```
```{r, eval=FALSE}
sheet_write(data = resultsTidy, ss = ssPersonas, sheet = "AllResultsWithPersonas")
```
Couldn't figure out how to move the file from my drive to a shared drive as every path I tried gave me errors, so I manually moved it on google drive.