knitr::opts_chunk$set(results = 'hide', warning=FALSE)

Create Graph Function

library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.0 --
## v ggplot2 3.3.3     v purrr   0.3.4
## v tibble  3.0.6     v dplyr   1.0.4
## v tidyr   1.1.2     v stringr 1.4.0
## v readr   1.4.0     v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
state.graphs <- function(ur_state){
ggplot(data = subset(ICU_all_combine_1, state %in% c(ur_state)),
       aes(x=month.year.date,
           y=Subgroup.discharges))+
  geom_line()+
  theme_bw()+
  labs(title = ur_state,
       x= "Month and Year",
       y= "Number of Discharges with ICU Care")+
  theme(axis.title = element_text(size = 14),
        axis.text.x = element_text(angle = 60, hjust = 1, size =12),
        axis.text.y = element_text(size = 12))
}

Prepare Data for all US

Original data has numbers of discharges with different types of subspecialty care, such cardiac ICU…. Here we only look at the number of discharges receiving any type of ICU.

load("C:/Users/jkempke/OneDrive - Emory University/Side Projects/HCUP ICU Time Series/Data/raw_data/ICU_all_combine.RData")

ICU_all_combine_1 <- ICU_all_combine %>%
  mutate(Subgroup.discharges = as.numeric(Subgroup.discharges),
         year.string = sapply(strsplit(ICU_all_combine$month, split = "-"), getElement,1),
         month.string = sapply(strsplit(ICU_all_combine$month, split = "-"), getElement,2),
         month.string = ifelse(nchar(month.string) == 1, str_pad(month.string, 2, pad = "0"), 
                               month.string), 
         month.year = paste("01",month.string, year.string, sep = "/" ),
         month.year.date = as.Date(month.year, format = "%d/%m/%y"))

ICU_any_US <- ICU_all_combine_1 %>% 
  filter(icu.type=="intensive care")%>%
  group_by(month.year.date)%>%
  summarise(US.discharges = sum(Subgroup.discharges, na.rm = T))

First Look

Looks like data inclusion falls off in 2019.

ggplot(data = ICU_any_US,
       aes(x=month.year.date,
           y=US.discharges))+
  geom_line()+
  theme_bw()+
  labs(title = "All available states",
       x= "Month and Year",
       y= "Number of Discharges with ICU Care")+
  theme(axis.title = element_text(size = 14),
        axis.text.x = element_text(angle = 60, hjust = 1, size =12),
        axis.text.y = element_text(size = 12))

Prepare Data by each state

Exclude data after December 2018 given above result

ICU_all_combine_1 <- ICU_all_combine_1 %>%
  filter(year.string<19 & icu.type=="intensive care")%>%
  select(-month, -month.year, -icu.type, -mech.vent)

Visualize Time Series by State

Several states without data. Many other states seem quite variable.

lapply(unique(ICU_all_combine_1$state), state.graphs)