Last active
July 26, 2018 14:18
-
-
Save gabrielburcea/eb3f98d756d72683b35f777ecc98613c to your computer and use it in GitHub Desktop.
Slide 14 - daily emergency access performance, Jan to July 2015
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
library(tidyverse) | |
library(lubridate) | |
data <- read.csv("df.csv", header = TRUE) | |
data$X <- NULL | |
####################################################### | |
# Code that converts all the columns names to lowercase | |
df_tolower <- function(x) { | |
colnames(x) <- tolower(colnames(x)) | |
x | |
} | |
##################################################### | |
df <- df_tolower(data ) | |
################################################################################################################ | |
# subseting data set ########################################################################################### | |
################################################################################################################ | |
dt_rmds<- df[c("pat_code","start_datetime", "end_datetime", "ward_code", "spell.number", "episode.order")] | |
colname_ct <- function(df, colname){ | |
df[,colname] = as.POSIXct(df[,colname]) | |
df | |
} | |
dt_rmds_ct <- dt_rmds %>% | |
colname_ct("start_datetime") %>% | |
colname_ct("end_datetime") | |
str(dt_rmds_ct) | |
############################# | |
# selecting the jan - july ## | |
############################# | |
dt_jan_jul <- subset(dt_rmds_ct, (start_datetime >= "2015-01-01 00:00:00" & start_datetime <= "2015-07-27 23:59:00") | | |
(end_datetime >= "2015-01-01 00:00:00" & end_datetime <= "2015-07-27 23:59:00")) | |
########################################################## | |
########################################################## | |
# calculating total time by using difftime ############ | |
# length of stay for the emergency department ############ | |
########################################################## | |
########################################################## | |
# creating a new variable - under 4 hrs and above 4 hrs ## | |
########################################################## | |
dt_los <- dt_jan_jul %>% | |
filter(ward_code == "A&E") %>% | |
mutate(Los = difftime(end_datetime, start_datetime, units = c("min"))) %>% | |
mutate(Time = as.Date(end_datetime)) %>% | |
mutate(One_week = lubridate::round_date(dt_jan_jul$Time, "7 days")) %>% | |
select(pat_code, Los, Time, One_Week) | |
dt_categ_4hr_perf <- dt_los %>% | |
mutate(hr_perf = case_when( | |
Los <= 240 ~ "under_4hrs", | |
Los >= 240 ~ "above_4hrs")) # https://dplyr.tidyverse.org/reference/case_when.html | |
# This function allows you to vectorise multiple if and else if statements. | |
# It is an R equivalent of the SQL CASE WHEN statement. | |
# 240 equivalent of 4 hrs -> creating a new variable with 4 hrs or above 4 performance | |
sum_4hrs_perf <- dt_categ_4hr_perf %>% | |
group_by(Time, hr_perf) %>% | |
dplyr::summarise(Count = n()) %>% | |
spread(hr_perf, Count) %>% | |
mutate(N = under_4hrs + above_4hrs) | |
######################### | |
# Applying the qicharts # | |
######################### | |
#Readm, | |
plot3 <- qicharts2::qic(Time, under_4hrs, | |
n = N, | |
data = tail(sum_4hrs_perf,100), | |
chart = 'p', | |
ylab = "percent", | |
show.grid = TRUE, | |
#freeze = 1, | |
#part = 11, | |
multiply= 100, | |
#x.format = "%d-%m-%Y", | |
x.angle = 45, | |
xlab = " Compliance with 4hr emergency care standard, %", | |
title = "daily 4 hr emergency access performance, January to July 2015") | |
plot3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment