-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdescriptive_tools_stats.R
More file actions
104 lines (85 loc) · 3.23 KB
/
descriptive_tools_stats.R
File metadata and controls
104 lines (85 loc) · 3.23 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
library(dplyr)
library(gtsummary)
working_directory
my_gtsummary_theme
gtsummary_compact_theme
## Descriptive statistics - Tools articles numeric
table_5 <- sapply(unique(df_tools_country_all$topic), function(x){
nn <- x
df <- df_tools_country_all %>%
dplyr::mutate(study_country = as.factor(study_country)
) %>%
dplyr::filter(topic == nn) %>%
dplyr::mutate(tools = as.factor(tools)
)
out <- gtsummary::tbl_continuous(df
,variable = n
,include = tools
,by = study_country
,statistic = everything() ~ c("{sum}")
,digits = list(everything() ~ c(0)
)
) %>%
gtsummary::add_overall(col_label = paste0("**Overall**", " N = ", length(unique(df$tools)))) %>%
gtsummary::as_flex_table()
}, simplify = FALSE
)
table_5
## Descriptive statistics - Tools articles proportion
table_6 <- sapply(unique(df_tools_country_all$topic), function(x){
nn <- x
df <- df_tools_country_all %>%
dplyr::slice(rep(seq(n()), times = n)) %>%
dplyr::mutate(study_country = as.factor(study_country)
) %>%
dplyr::filter(topic == nn) %>%
dplyr::mutate(tools = as.factor(tools)
)
out <- tbl_summary(df,
include = tools,
by = study_country,
sort = all_categorical() ~ "frequency",
percent = "column",
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() %>%
gtsummary::add_overall() %>%
gtsummary::as_flex_table()
}, simplify = FALSE
)
table_6
## Descriptive statistics - Tools articles proportion top n
table_7 <- sapply(unique(df_tools_country_top_n_all$topic), function(x){
nn <- x
df <- df_tools_country_top_n_all %>%
dplyr::slice(rep(seq(n()), times = n)) %>%
dplyr::mutate(study_country = as.factor(study_country)
) %>%
dplyr::filter(topic == nn) %>%
dplyr::mutate(tools_new = as.factor(tools_new)
)
out <- tbl_summary(df,
include = tools_new,
by = study_country,
sort = all_categorical() ~ "frequency",
percent = "column",
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() %>%
gtsummary::add_overall() %>%
gtsummary::as_flex_table()
}, simplify = FALSE
)
table_7