generated from opensafely/research-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_review_files.R
52 lines (33 loc) · 1.58 KB
/
make_review_files.R
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
# Make master file -------------------------------------------------------------
print('Make master file')
df <- readr::read_csv("output/model_output_rounded.csv",
show_col_types = FALSE)
df$source <- "R"
tmp <- readr::read_csv("output/stata_model_output_rounded.csv",
show_col_types = FALSE)
tmp$source <- "Stata"
df <- df[!(df$name %in% tmp$name),]
df <- rbind(df, tmp)
# Save failures ----------------------------------------------------------------
print('Save failures')
tmp1 <- df[!is.na(df$error),
c("name","error","source")]
readr::write_csv(tmp1, "output/review-failures.csv")
df <- df[is.na(df$error),]
# Save counts at name level ----------------------------------------------------
print('Save counts at name level')
tmp2 <- unique(df[!is.na(df$N_total),
c("name","N_total","N_exposed")])
readr::write_csv(tmp2, "output/review-counts_name_rounded.csv")
# Save counts at term level ----------------------------------------------------
print('Save counts at term level')
tmp3 <- unique(df[!is.na(df$N_events),
c("name",
"term","N_events","person_time_total","outcome_time_median")])
readr::write_csv(tmp3, "output/review-counts_term_rounded.csv")
# Save model output ------------------------------------------------------------
print('Save model output')
tmp4 <- unique(df[df$term!="days_pre",
c("name","model","term",
"hr","conf_low","conf_high","surv_formula")])
readr::write_csv(tmp4, "output/review-model_output_rounded.csv")