-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmh_tools_data.R
More file actions
150 lines (110 loc) · 3.82 KB
/
mh_tools_data.R
File metadata and controls
150 lines (110 loc) · 3.82 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
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
library(dplyr)
library(tidyr)
library(gtsummary)
working_directory
my_gtsummary_theme
gtsummary_compact_theme
## Data - Tools
tools <- sapply(c("depression", "anxiety", "psychosis"), function(x){
nn <- x
df <- df_quality %>%
tidyr::drop_na(other_tools_used) %>%
dplyr::filter(.data[[nn]] == "Yes") %>%
dplyr::select(other_tools_used) %>%
mutate(split = str_split(other_tools_used, ";", simplify = FALSE))
out <- tibble::tibble(tools = unlist(df$split)) %>%
group_by(tools) %>%
count() %>%
ungroup() %>%
dplyr::arrange(-n) %>%
dplyr::mutate(topic = nn)
return(out)
}, simplify = FALSE
)
df_tools_unique <- do.call("rbind", tools) %>%
dplyr::select(tools) %>%
dplyr::distinct(tools)
df_tools_all <- do.call("rbind", tools) %>%
dplyr::left_join(df_mh_tools %>%
dplyr::filter(tools != "other") %>%
dplyr::mutate(correct = "yes"),
by = c("tools", "topic")
) %>%
tidyr::drop_na(correct) %>%
dplyr::select(-correct)
## Data - Top n Tools
tools_top_n <- sapply(unique(df_tools_all$topic), function(x){
nn <- x
top_n_tools <- df_top_n %>%
dplyr::pull(n)
top <- df_tools_all %>%
dplyr::filter(topic == nn) %>%
dplyr::slice_max(n, n=top_n_tools, with_ties = FALSE) %>%
dplyr::pull(tools)
df_top <- df_tools_all %>%
dplyr::filter(topic == nn) %>%
dplyr::mutate(tools_new = if_else(tools %in% top, tools, "others")) %>%
dplyr::group_by(tools_new, topic) %>%
dplyr::summarise(n = sum(n), .groups = "drop")
return(df_top)
}, simplify = FALSE
)
df_tools_top_n_all <- do.call("rbind", tools_top_n)
## Data- Tools by Country
tools_country <- sapply(c("depression", "anxiety", "psychosis"), function(x){
nn <- x
df <- df_quality %>%
tidyr::drop_na(other_tools_used) %>%
dplyr::filter(.data[[nn]] == "Yes")
country <- sapply(unique(df$study_country), function(y){
df_new <- df %>%
dplyr::filter(study_country == y) %>%
dplyr::select(other_tools_used) %>%
mutate(split = str_split(other_tools_used, ";", simplify = FALSE))
out <- tibble::tibble(tools = unlist(df_new$split)) %>%
group_by(tools) %>%
count() %>%
ungroup() %>%
dplyr::arrange(-n) %>%
dplyr::mutate(topic = nn,
study_country = y)
return(out)
}, simplify = FALSE
)
out_ <- do.call("rbind", country)
}, simplify = FALSE
)
df_tools_country_unique <- do.call("rbind", tools_country) %>%
dplyr::select(tools, study_country) %>%
dplyr::distinct(tools, study_country)
df_tools_country_all <- do.call("rbind", tools_country) %>%
dplyr::left_join(df_mh_tools %>%
dplyr::filter(tools != "other") %>%
dplyr::mutate(correct = "yes"),
by = c("tools", "topic")
) %>%
tidyr::drop_na(correct) %>%
dplyr::select(-correct)
## Data - Top n Tools by country
tools_country_top_n <- sapply(unique(df_tools_country_all$topic), function(x){
nn <- x
top_n_tools <- df_top_n %>%
dplyr::pull(n)
top <- df_tools_all %>%
dplyr::filter(topic == nn) %>%
dplyr::slice_max(n, n=top_n_tools, with_ties = FALSE) %>%
dplyr::pull(tools)
df_top <- df_tools_all %>%
dplyr::filter(topic == nn) %>%
dplyr::mutate(tools_new = if_else(tools %in% top, tools, "others"))
df_top_country <- df_tools_country_all %>%
dplyr::filter(topic == nn) %>%
dplyr::left_join(df_top %>%
dplyr::select(tools, topic, tools_new),
by = c("tools", "topic")) %>%
dplyr::group_by(study_country, tools_new, topic) %>%
dplyr::summarise(n = sum(n), .groups = "drop")
return(df_top_country)
}, simplify = FALSE
)
df_tools_country_top_n_all <- do.call("rbind", tools_country_top_n)