generated from opensafely/research-template
/
starpu_ab_prescribing_os.R
99 lines (84 loc) · 3.69 KB
/
starpu_ab_prescribing_os.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# # # # # # # # # # # # # # # # # # # # #
# This script:
# Generate a plot to show overall antibiotics prescribing rate by month after star-pu adjustment
# By practice, by month, per 1000 patient
# # # # # # # # # # # # # # # # # # # # #
## Import libraries---
library('tidyverse')
library("ggplot2")
library('dplyr')
library('lubridate')
# impoprt data
df <- read_csv(
here::here("output", "measures", "measure_STARPU_antibiotics_os.csv"),
col_types = cols_only(
practice = col_double(),
sex = col_character(),
age_cat = col_character(),
antibacterial_brit = col_double(),
population = col_double(),
value = col_double(),
# Date
date = col_date(format="%Y-%m-%d")
),
na = character()
)
df$date <- as.Date(df$date)
df$cal_mon <- month(df$date)
df$cal_year <- year(df$date)
starpu <- df %>% filter(practice >0)
measurestar <- starpu%>%mutate(adjustedvalue= case_when(age_cat=="0-4" ~ value*0.8,
age_cat =="5-14"& sex=="M"~value*0.3,
age_cat =="5-14"& sex=="F"~value*0.4,
age_cat =="15-24"& sex=="M"~value*0.3,
age_cat =="15-24"& sex=="F"~value*0.6,
age_cat =="25-34"& sex=="M"~value*0.2,
age_cat =="25-34"& sex=="F"~value*0.6,
age_cat =="35-44"& sex=="M"~value*0.3,
age_cat =="35-44"& sex=="F"~value*0.6,
age_cat =="45-54"& sex=="M"~value*0.3,
age_cat =="45-54"& sex=="F"~value*0.6,
age_cat =="55-64"& sex=="M"~value*0.4,
age_cat =="55-64"& sex=="F"~value*0.7,
age_cat =="65-74"& sex=="M"~value*0.7,
age_cat =="65-74"& sex=="F"~value*1.0,
age_cat =="75+"& sex=="M"~value*1.0,
age_cat =="75+"& sex=="F"~value*1.3,
TRUE ~ 0))
measurstarpu=measurestar%>%
group_by(cal_mon,cal_year)%>%
mutate(mean_prescrib=mean(adjustedvalue*1000,na.rm = TRUE))
starpu_line_os <- ggplot(measurstarpu, aes(x=date))+
geom_line(aes(y=mean_prescrib),color="steelblue")+
geom_point(aes(y=mean_prescrib),color="steelblue")+
geom_vline(xintercept = as.numeric(as.Date("2019-12-31")))+
geom_vline(xintercept = as.numeric(as.Date("2020-12-31")))+
labs(
title = "Star-pu adjusted antibiotics prescribing rate by month - OS",
subtitle = "10/2020 - 10/2021",
caption = "TPP Practices",
x = "Time",
y = "star-pu adjusted prescribing rate"
)
starpu_line_os
ggsave(
plot= starpu_line_os,
filename="starpu_line_os.png", path=here::here("output"),
)
#star-pu boxplot
starpu_box_os <- ggplot(measurestar, aes(group=date,x=date,y=adjustedvalue*1000)) +
geom_boxplot()+
geom_vline(xintercept = as.numeric(as.Date("2019-12-31")))+
geom_vline(xintercept = as.numeric(as.Date("2020-12-31")))+
labs(
title = "Star-pu adjusted antibiotics prescribing rate by practice - OS",
subtitle = "10/2020 - 10/2021",
caption = "TPP Practices",
x = "Time",
y = "star-pu adjusted prescribing rate"
)
starpu_box_os
ggsave(
plot= starpu_box_os,
filename="starpu_box_os.png", path=here::here("output"),
)