generated from opensafely/research-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #113 from opensafely/milanwiedemann/add-comparison…
…-figure Add manuscript figure comparing OpenSAFELY-TPP and NHS BSA data
- Loading branch information
Showing
6 changed files
with
250 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# Load NHS BSA validation data and summarise total count by: | ||
# 1. pf_consultation | ||
# 2. pf_medication | ||
df_bsa_validation_total <- df_bsa_validation |> | ||
group_by(date, data_desc, count_method) |> | ||
mutate(count_total = sum(count, na.rm = TRUE)) |> | ||
select(-count_group, -count) |> | ||
distinct() %>% | ||
ungroup() %>% | ||
filter(count_method == "count_40pct") | ||
|
||
# Transform OpenSAFLEY data into same format as NHS BSA validation data | ||
# 1. pf_consultation from: | ||
# 1.1. clinical condition (not every PF consult. has a linked clin. condition) | ||
df_os_consultation_from_condition_validation <- df_measures %>% | ||
filter(measure_desc == "clinical_condition") %>% | ||
filter(is.na(group_by)) %>% | ||
select( | ||
date = interval_start, | ||
count_group = measure, | ||
count = numerator | ||
) %>% | ||
mutate( | ||
data_source = "opensafely", | ||
data_desc = "pf_consultation", | ||
count_desc = "consultation_type", | ||
count_method = "opensafely_tpp", | ||
) |> | ||
filter(date >= "2024-02-01") %>% | ||
relocate( | ||
date, data_source, data_desc, | ||
count_desc, count_group, count_method, count | ||
) | ||
|
||
# 1.1. consultation id (better description of total PF consult. in OS) | ||
df_os_consultation_from_id_validation <- df_pf_consultations_total |> | ||
mutate( | ||
data_source = "opensafely", | ||
data_desc = "pf_consultation", | ||
count_desc = "consultation_id", | ||
count_group = "consultation_id", | ||
count_method = "opensafely_tpp" | ||
) |> | ||
select( | ||
date = interval_start, | ||
data_source, data_desc, count_desc, count_group, count_method, | ||
count = pf_consultation_total | ||
) | ||
|
||
# 2. pf_medication from linked medication | ||
df_os_medication_validation <- df_pfmed %>% | ||
rename(date = interval_start) %>% | ||
mutate( | ||
count = numerator, | ||
data_source = "opensafely", | ||
data_desc = "pf_medication", | ||
count_desc = "dmd_code", | ||
count_method = "opensafely_tpp", | ||
count_group = dmd_code, | ||
) |> | ||
filter(date >= "2024-02-01") %>% | ||
select( | ||
date, data_source, data_desc, | ||
count_desc, count_group, count_method, count | ||
) | ||
|
||
df_os_validation_total <- bind_rows( | ||
df_os_consultation_from_condition_validation, | ||
df_os_consultation_from_id_validation, | ||
df_os_medication_validation | ||
) %>% | ||
group_by(date, data_desc, count_desc, count_method) |> | ||
mutate(count_total = sum(count, na.rm = TRUE)) |> | ||
select(-count_group, -count) |> | ||
distinct() %>% | ||
ungroup() | ||
|
||
# Combine NHS BSA and OpenSAFELY data | ||
pf_validation <- bind_rows(df_bsa_validation_total, df_os_validation_total) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters