For this project, I decided to analyze healthcare-associated infections reported by hospitals across the United States. I wanted to get a better understanding of how hospitals perform when it comes to infection prevention and how their results compare to national benchmarks. I also wanted to look at whether there were noticeable differences between infection types and the number of hospital records reported across different states.
To conduct my analysis, I used R to examine the dataset, calculate descriptive statistics, and create five different visualizations. These include a bar chart, histogram, stacked bar chart, trellis chart, and heatmap. Each visualization focuses on a different part of the dataset to help identify patterns and better understand what the results show about hospital infection reporting and performance.
For this project, I used a dataset containing information about healthcare-associated infections in hospitals across the United States. Some of the information provided includes hospital names, locations, infection types, numerical scores, and how hospitals compare to national benchmarks.
library(data.table)
library(dplyr)
library(ggplot2)
library(scales)
filename <- "Healthcare_Associated_Infections_-_Hospital.csv"
df <- fread(filename, na.strings = c("NA", "", "Not Available"))
dim(df)
## [1] 222864 16
colnames(df)
## [1] "Provider ID" "Hospital Name" "Address"
## [4] "City" "State" "ZIP Code"
## [7] "County Name" "Phone Number" "Measure Name"
## [10] "Measure ID" "Compared to National" "Score"
## [13] "Footnote" "Measure Start Date" "Measure End Date"
## [16] "Location"
The data set contains 222,864 records and 16 different variables. For this part of my analysis, I decided to focus on central line-associated bloodstream infections (CLABSI), which are identified as HAI_1_SIR in the data set. I filtered out records that did not have a numerical score so I could get a better understanding of how hospitals performed compared to the national benchmark.
sir <- df[!is.na(df$Score) & df$"Measure ID" == "HAI_1_SIR", ]
nrow(sir)
## [1] 2048
summary(sir$Score)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.0000 0.1460 0.4565 0.5385 0.7602 5.4350
table(sir$"Compared to National")
##
## Better than the National Benchmark No Different than National Benchmark
## 508 1511
## Worse than the National Benchmark
## 29
After filtering out the data, I had 2,048 CLABSI records to analyze. The average standardized infection ratio was approximately 0.54, while the median was about 0.46. I also looked at how hospitals were classified compared to the national benchmark. Out of the 2,048 records, 1,511 were classified as no different from the national benchmark, 508 were classified as better, and only 29 were classified as worse. This shows that most of the reporting records were not significantly different from the national benchmark, while a smaller portion performed better or worse.
sir$Benchmark <- sir$"Compared to National"
benchmarkCount <- data.frame(count(sir, Benchmark))
benchmarkCount <- benchmarkCount[order(benchmarkCount$n, decreasing = TRUE), ]
ggplot(benchmarkCount, aes(x = reorder(Benchmark, -n), y=n)) +
geom_bar(colour="black", fill="gray76", stat="identity") +
labs(title = "CLABSI National Benchmark Comparison",
x = "National Benchmark",
y = "Number of Hospital Records") +
theme(plot.title = element_text(hjust = 0.5))
For this bar chart, I compared CLABSI records to the national benchmark. Out of the 2,048 records, 1,511 were classified as no different from the national benchmark, 508 were better, and only 29 were worse. The biggest thing I noticed was that most records fell into the no-difference category. This tells me that most of the reporting hospitals were not performing significantly better or worse than the national benchmark for this measure.
p2 <- ggplot(sir, aes(x=Score)) +
geom_histogram(bins=20, color="darkblue", fill="lightblue") +
labs(title="Distribution of CLABSI Infection Ratios",
x="CLABSI Standardized Infection Ratio",
y="Number of Hospital Records")
print(p2)
For this histogram, I looked at how the CLABSI infection ratios were distributed. Most of the scores were toward the lower end, with only a few records having much higher scores. The mean was around 0.54, while the median was 0.46. Since the mean was higher than the median, along with the shape of the graph, it shows that the data was skewed to the right. This means that while most scores were relatively low, there were still some much higher scores in the dataset.
sir_ids <- c("HAI_1_SIR", "HAI_2_SIR", "HAI_3_SIR",
"HAI_4_SIR", "HAI_5_SIR", "HAI_6_SIR")
new_df <- df %>%
filter(`Measure ID` %in% sir_ids,
!is.na(Score),
!is.na(`Compared to National`)) %>%
select(`Measure ID`, `Compared to National`) %>%
group_by(`Measure ID`, `Compared to National`) %>%
summarise(n = length(`Measure ID`), .groups = 'keep') %>%
data.frame()
new_df$Compared.to.National <- as.factor(new_df$Compared.to.National)
ggplot(new_df, aes(x = reorder(Measure.ID, n, sum),
y = n, fill = Compared.to.National)) +
geom_bar(stat="identity", position=position_stack(reverse = TRUE)) +
coord_flip() +
labs(title = "National Benchmark Comparison by Infection Type",
x = "",
y = "Number of Hospital Records",
fill = "National Benchmark") +
theme_light() +
theme(plot.title = element_text(hjust = 0.5))
This stacked bar chart compares six different types of hospital infections based on their national benchmark classifications. Similar to the first graph, most of the records were classified as no different from the national benchmark. However, the total number of records was different for each infection type. I found this graph useful because I could compare multiple infections in one place instead of looking at each one separately.
library(plotly)
plot_ly(textposition="inside",
labels=~Compared.to.National,
values=~n) %>%
add_pie(data=new_df[new_df$Measure.ID == "HAI_1_SIR", ],
name="CLABSI", title="CLABSI",
domain=list(row=0, column=0)) %>%
add_pie(data=new_df[new_df$Measure.ID == "HAI_2_SIR", ],
name="CAUTI", title="CAUTI",
domain=list(row=0, column=1)) %>%
add_pie(data=new_df[new_df$Measure.ID == "HAI_3_SIR", ],
name="SSI Colon", title="SSI Colon",
domain=list(row=1, column=0)) %>%
add_pie(data=new_df[new_df$Measure.ID == "HAI_6_SIR", ],
name="C. difficile", title="C. difficile",
domain=list(row=1, column=1)) %>%
layout(title="Trellis Chart: Hospital Infection Benchmark Comparisons",
showlegend=TRUE,
grid=list(rows=2, columns=2))
For this chart, I compared four different infection types using pie charts. I wanted to see how the percentages of better, worse, and no different compared between the infections. One thing I noticed was that C. difficile had the highest percentage of records classified as worse than the national benchmark at 9.95%, followed by SSI Colon at 7.51%. Even though most records were still classified as no different, the percentages showed that there were some noticeable differences depending on the infection type.
sir_df <- df %>%
filter(`Measure ID` %in% sir_ids,
!is.na(Score),
!is.na(State))
stateCount <- data.frame(count(sir_df, State))
stateCount <- stateCount[order(stateCount$n, decreasing=TRUE), ]
top_states <- stateCount$State[1:10]
heat_df <- sir_df %>%
filter(State %in% top_states) %>%
select(State, `Measure ID`) %>%
group_by(State, `Measure ID`) %>%
summarise(n = length(State), .groups = 'keep') %>%
data.frame()
g <- ggplot(heat_df, aes(x = Measure.ID, y = State, fill = n)) +
geom_tile(color="black") +
geom_text(aes(label=comma(n))) +
coord_equal(ratio=1) +
labs(title="Heatmap: Hospital Reporting Records by State and Infection Type",
x="Infection Measure ID",
y="State",
fill="Record Count") +
theme_minimal() +
theme(plot.title = element_text(hjust=0.5)) +
scale_fill_continuous(low="white", high="red")
print(g)
For my last graph, I created a heatmap to compare hospital reporting records across ten states and six infection measures. California had some of the highest record counts, followed by states such as Texas. The darker red sections helped me identify which states and infection types had more records. Something important to consider is that having more records does not mean that a state has more infections or worse hospital performance. It just means that more records were included for those measures in the dataset.
To conclude, this project helped me get a better understanding of healthcare-associated infections and how hospitals compare to national benchmarks. Throughout my analysis, I noticed that most of the hospital records were classified as no different from the national benchmark. ALthough there were still some differences depending on the infection type, especially when looking at the percentage of records classified as worse than the benchmark.
One of the biggest things I took away from this project was how using different visualizations can help explain the same data set in different ways. Each graph helped me identify patterns that I might not have noticed just by looking at the numbers.