generated from opensafely/sro-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
join_measures.R
83 lines (63 loc) · 3.22 KB
/
join_measures.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
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
# This scrip loads all measure files and
# (1) joins them together
# (2) rounds counts to the nearest 10
# Note that the ungrouped measure (population) and grouped measures
# differ in the number of their variables
# Load packages ----
library(magrittr)
source(here::here("lib", "funs.R"))
fs::dir_create(here::here("output", "joined", "measures"))
# Get file names and path ----
bp002_excl_breakdown_dr3_measures <- fs::dir_ls(
path = "output/joined",
glob = "*measure_bp002_excl_denominator_r3_*_breakdown_rate.csv$"
)
bp002_excl_population_dr3_measures <- fs::dir_ls(
path = "output/joined",
glob = "*measure_bp002_excl_denominator_r3_population_rate.csv$"
)
bp002_excl_breakdown_dr4_measures <- fs::dir_ls(
path = "output/joined",
glob = "*measure_bp002_excl_denominator_r4_*_breakdown_rate.csv$"
)
bp002_excl_population_dr4_measures <- fs::dir_ls(
path = "output/joined",
glob = "*measure_bp002_excl_denominator_r4_population_rate.csv$"
)
bp002_achievem_breakdown_measures <- fs::dir_ls(
path = "output/joined",
glob = "*measure_bp002_achievem_*_breakdown_rate.csv$"
)
# Remove practice level data from achievement measures
bp002_achievem_breakdown_measures <- bp002_achievem_breakdown_measures[!stringr::str_detect(bp002_achievem_breakdown_measures, "practice")]
bp002_achievem_population_measures <- fs::dir_ls(
path = "output/joined",
glob = "*measure_bp002_achievem_population_rate.csv$"
)
df_bp002_achievem_population <- read_population_measures(bp002_achievem_population_measures)
df_bp002_achievem_breakdown <- read_breakdown_measures(bp002_achievem_breakdown_measures)
df_bp002_achievem <- dplyr::bind_rows(df_bp002_achievem_population, df_bp002_achievem_breakdown)
df_bp002_achievem <- df_bp002_achievem %>%
round_variables(c("bp002_numerator", "bp002_denominator", "population"))
readr::write_csv(df_bp002_achievem,
here::here("output", "joined", "measures", "measures_bp002_achievem.csv"))
df_bp002_excl_dr3_population <- read_population_measures(bp002_excl_population_dr3_measures) %>%
dplyr::mutate(excl_rule = "bp002_denom_r3") %>%
dplyr::rename(excl_denominator = bp002_excl_denominator_r3)
df_bp002_excl_dr4_population <- read_population_measures(bp002_excl_population_dr4_measures) %>%
dplyr::mutate(excl_rule = "bp002_denom_r4") %>%
dplyr::rename(excl_denominator = bp002_excl_denominator_r4)
df_bp002_excl_dr3_breakdown <- read_breakdown_measures(bp002_excl_breakdown_dr3_measures) %>%
dplyr::mutate(excl_rule = "bp002_denom_r3") %>%
dplyr::rename(excl_denominator = bp002_excl_denominator_r3)
df_bp002_excl_dr4_breakdown <- read_breakdown_measures(bp002_excl_breakdown_dr4_measures) %>%
dplyr::mutate(excl_rule = "bp002_denom_r4") %>%
dplyr::rename(excl_denominator = bp002_excl_denominator_r4)
df_bp002_excl <- dplyr::bind_rows(df_bp002_excl_dr3_population,
df_bp002_excl_dr3_breakdown,
df_bp002_excl_dr4_population,
df_bp002_excl_dr4_breakdown)
df_bp002_excl <- df_bp002_excl %>%
round_variables(c("excl_denominator", "population"))
readr::write_csv(df_bp002_excl,
here::here("output", "joined", "measures", "measures_bp002_excl.csv"))