-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdescriptive_articles_stats.R
More file actions
161 lines (136 loc) · 8 KB
/
descriptive_articles_stats.R
File metadata and controls
161 lines (136 loc) · 8 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
150
151
152
153
154
155
156
157
158
159
160
library(dplyr)
library(gtsummary)
working_directory
my_gtsummary_theme
gtsummary_compact_theme
## Descriptive statistics - Articles
### Quality check
table_1 <- tbl_summary(df_meta %>%
dplyr::select(correctly_identified, reason),
type = list(
all_dichotomous() ~ "categorical")
, digits = list(all_categorical() ~ c(0, 1))
, missing = "ifany" #list missing data separately #ifany #no #always
,missing_text = "Missing"
) %>%
modify_header(label = "**Descriptives**") %>% # update the column header
bold_labels() %>%
italicize_levels()%>%
add_n( statistic = "{N_nonmiss}", col_label = "**n**", last = FALSE, footnote = FALSE)%>% # add column with total number of non-missing observations
modify_caption(caption = "Quality Check") %>%
as_flex_table() #covert gtsummary object to knitrkable object. also use as_flex_table() to maintain identation, footnotes, spanning headers
table_1
### Overall Descriptives
table_2 <- tbl_summary(df_quality %>%
dplyr::select(source_year_published, region, study_country, type_of_study, depression, anxiety, psychosis,
availability_of_data_article, how_to_access_the_data, status_email_request, data_received),
type = list(
all_dichotomous() ~ "categorical",
all_continuous() ~ "continuous2")
, statistic = list(
source_year_published ~ c(
"{min} - {max}" )
)
, digits = list(all_categorical() ~ c(0, 1),
all_continuous() ~ 0
)
, missing = "ifany" #list missing data separately #ifany #no #always
,missing_text = "Missing"
) %>%
modify_header(label = "**Descriptives**") %>% # update the column header
bold_labels() %>%
italicize_levels()%>%
add_n( statistic = "{N_nonmiss}", col_label = "**n**", last = FALSE, footnote = FALSE)%>% # add column with total number of non-missing observations
modify_caption(caption = "Correctly Identified Articles (N = {N})")
table_2
### By Descriptives
table_3 <- sapply(c("type_of_study", "depression", "anxiety", "psychosis",
"availability_of_data_article" ), function(x){
nn <- x
out <- if (nn == "type_of_study") {
tbl_summary(df_quality %>%
dplyr::select(source_year_published, region, study_country, type_of_study, depression, anxiety, psychosis,
availability_of_data_article, how_to_access_the_data, status_email_request, data_received),
by = any_of(nn),
type = list(
all_dichotomous() ~ "categorical",
all_continuous() ~ "continuous2")
, statistic = list(
source_year_published ~ c(
"{min} - {max}" )
)
, digits = list(all_categorical() ~ c(0, 1),
all_continuous() ~ 0
)
, missing = "ifany" #list missing data separately #ifany #no #always
,missing_text = "Missing"
) %>%
modify_header(label = "**Descriptives**") %>% # update the column header
bold_labels() %>%
italicize_levels()%>%
add_n( statistic = "{N_nonmiss}", col_label = "**n**", last = FALSE, footnote = FALSE)%>% # add column with total number of non-missing observations
modify_caption(caption = paste0("Correctly Identified Articles", " - ", nn, " (N = {N})")) %>%
modify_header(all_stat_cols() ~ paste0("**", "{level}**, n = {n} ({style_percent(p)}%)"))
} else {
tbl_summary(df_quality %>%
dplyr::select(source_year_published, region, study_country, type_of_study, depression, anxiety, psychosis,
availability_of_data_article, how_to_access_the_data, status_email_request, data_received),
by = any_of(nn),
type = list(
all_dichotomous() ~ "categorical",
all_continuous() ~ "continuous2")
, statistic = list(
source_year_published ~ c(
"{min} - {max}" )
)
, digits = list(all_categorical() ~ c(0, 1),
all_continuous() ~ 0
)
, missing = "ifany" #list missing data separately #ifany #no #always
,missing_text = "Missing"
) %>%
modify_header(label = "**Descriptives**") %>% # update the column header
bold_labels() %>%
italicize_levels()%>%
add_n( statistic = "{N_nonmiss}", col_label = "**n**", last = FALSE, footnote = FALSE)%>% # add column with total number of non-missing observations
modify_caption(caption = paste0("Correctly Identified Articles", " - ", nn, " (N = {N})")) %>%
modify_header(all_stat_cols() ~ paste0("**", nn , " - ", "{level}**, n = {n} ({style_percent(p)}%)"))
}
}, simplify = FALSE
)
table_4 <- sapply(c("status_email_request", "data_received"), function(x){
nn <- x
out <- tbl_summary(df_quality %>%
dplyr::select(source_year_published, region, study_country, type_of_study, depression, anxiety, psychosis,
availability_of_data_article, how_to_access_the_data, status_email_request, data_received),
by = any_of(nn),
type = list(
all_dichotomous() ~ "categorical",
all_continuous() ~ "continuous2")
, statistic = list(
source_year_published ~ c(
"{min} - {max}" )
)
, digits = list(all_categorical() ~ c(0, 1),
all_continuous() ~ 0
)
, missing = "ifany" #list missing data separately #ifany #no #always
,missing_text = "Missing"
) %>%
modify_header(label = "**Descriptives**") %>% # update the column header
bold_labels() %>%
italicize_levels()%>%
add_n( statistic = "{N_nonmiss}", col_label = "**n**", last = FALSE, footnote = FALSE)%>% # add column with total number of non-missing observations
modify_caption(caption = paste0("Data Request Articles", " - ", nn, " (N = {N})")) %>%
modify_header(all_stat_cols() ~ paste0("**", nn , " - ", "{level}**, n = {n} ({style_percent(p)}%)"))
}, simplify = FALSE
)
### Merge tables
table_merged1 <- tbl_merge(tbls= c(list(table_2),table_3),
tab_spanner = NULL) %>%
as_flex_table()
table_merged1
table_merged2 <- tbl_merge(tbls= c(list(table_2),table_4),
tab_spanner = NULL) %>%
as_flex_table()
table_merged2