The data within the dataset was originally sourced from Medicare, a federal health insurance program. It includes information regarding the performance data of hospitals across the country. The dataset holds 24 variables (19 categorical and 5 quantitative):
Facility.Name : the name of the hospital
Facility.City : city in which the hospital is located in
Facility.State : the state in which the hospital is based in
Facility.Type: the kind of organization operating the hospital (government, private, church, proprietary)
Rating.Overall: the overall rating of the hospital
Rating.Mortality : above, same, below, or unknown in comparison to the national hospital mortality rating
Rating.Safety : above, same, below, or unknown in comparison to the national hospital safety rating
Rating.Readmission : above, same, below, or unknown in comparison to national hospital readmission rating
Rating.Experience : above, same, below, or unknown in comparison to the national hospital patience experience rating
Rating.Effectiveness : above, same, below, or unknown in comparison to national hospital effectiveness of care
Rating.Timeliness : above, same, below, or unknown in comparison to national hospital timeliness of care
Rating.Imaging : above, same, below or unknown in comparison to national hospital effective use of imaging
Procedure.Heart Attack.Cost: the cost of care for heart attacks
Procedure.Heart Failure.Cost: the cost of care for heart failure
Procedure.Pneumonia.Cost: the cost of care for pneumonia
Procedure.Hip Knee.Cost: the cost of care for hip or knee issues
Procedure.Heart Attack.Quality: whether lower, average, worse in comparison to national quality rating
Procedure.Heart Failure.Quality: whether lower, average, worse in comparison to national quality rating
Procedure.Pneumonia.Quality: whether lower, average, worse in comparison to national quality rating
Procedure.Hip Knee Quality: whether lower, average, worse in comparison to national quality rating
Procedure.Heart Attack.Value : lower, average, worse, or unknown in comparison to national cost of care for heart failures
Procedure.Heart Failure.Value : lower, average, worse, or unknown in comparison to national cost of care for heart failures
Procedure.Pneumonia.Value : lower, average, worse, or unknown in comparison to the national cost of care for pneumonia
Procedure. Hip Knee.Value : lower, average, worse, or unknown in comparison to the national cost of care for hip or knee conditions
I chose to analyze hospital type, quality, and cost as healthcare continues to become increasingly expensive in the US. Majority are aware of how much medical treatment can cost, and how it places a heavy burden to many individuals who require medical care but cannot afford the heightened costs. I believe that healthcare should be available to all individuals regardless of financial status. By evaluating hospital types, quality, and costs, I aim to identify affordable options for individuals running on strained budgets, and to see if higher costs guarantee improved quality treatment (i.e. if there is a correlation).
As previously stated, the dataset holds 24 variables total. However, I only need 7 of those variables, so I will begin by cleaning the data using the select() and rename() functions to make the data easier to work with. In addition, the mutate() function will allow for the creation of a new variable to represent the overall average pricing behaviors of each hospital.
Before beginning the research, it is important to note a key limitation of this dataset. While the dataset provided the quantitative Rating.Overall variable, it did not provide a general categorical quality rating, which was necessary for the visualizations. To address this issue, I utilized the Rating.Effectiveness variable as an overall quality rating (seen in the boxplot visualization). This is a limitation attached to the dataset shaping the different visualizations presented through this analysis.
Load Libraries
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.2.1 ✔ readr 2.2.0
✔ forcats 1.0.1 ✔ stringr 1.6.0
✔ ggplot2 4.0.3 ✔ tibble 3.3.1
✔ lubridate 1.9.5 ✔ tidyr 1.3.2
✔ purrr 1.2.2
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(dplyr)library(ggplot2)library(plotly)
Attaching package: 'plotly'
The following object is masked from 'package:ggplot2':
last_plot
The following object is masked from 'package:stats':
filter
The following object is masked from 'package:graphics':
layout
Load the Dataset
hospitals =read_csv("~/Downloads/hospitals.csv")
Rows: 4772 Columns: 24
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (19): Facility.Name, Facility.City, Facility.State, Facility.Type, Ratin...
dbl (5): Rating.Overall, Procedure.Heart Attack.Cost, Procedure.Heart Failu...
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
#clean the data by using select, and rename functions clean_hos = hospitals |>#keeping the variables that I needselect(Facility.Type, Rating.Overall, Rating.Effectiveness, ends_with("Cost")) |>#renaming the variables so that they are easier to work withrename(heartattack_cost =`Procedure.Heart Attack.Cost`, heartfailure_cost =`Procedure.Heart Failure.Cost`, pneumonia_cost =`Procedure.Pneumonia.Cost`, hipknee_cost =`Procedure.Hip Knee.Cost` )head(clean_hos)
# A tibble: 6 × 7
Facility.Type Rating.Overall Rating.Effectiveness heartattack_cost
<chr> <dbl> <chr> <dbl>
1 Government 2 Same 23394
2 Government 1 Above 22579
3 Government 3 Same 24002
4 Private 1 Below 0
5 Proprietary 4 Same 0
6 Private 2 Below 23940
# ℹ 3 more variables: heartfailure_cost <dbl>, pneumonia_cost <dbl>,
# hipknee_cost <dbl>
Utilized the select() function to keep only the needed variables and rename() for simplicity.
clean_hos2 = clean_hos |>#create new column adding together treatment costs mutate(hospital_cost = (heartattack_cost + heartfailure_cost + hipknee_cost + pneumonia_cost) /4 ) |>filter(hospital_cost >0.00)#take out entries that resulted in 0, to only keep relevant entries
Mutate() allowed me to mutate a new column “hospital_cost” by adding together the costs of the separate treatments and dividing by 4. This allows us to look at each hospital’s average pricing behavior.
Analyzing Hospital Type and Cost
#remove "Unknown" type entries from the subset type_hospital = clean_hos2 |>filter(Facility.Type !="Unknown")
For the hospitals whose type wasn’t known, they were specified as “Unknown”. In order to ensure a clean and meaningful comparison across hospital types, they are being excluded.
ggplot(type_hospital, aes(x = Facility.Type, y = hospital_cost, fill = Facility.Type)) +geom_bar(stat ="identity") +theme_minimal(base_family ="serif") +labs(title ="Comparing Hospital Types and Pricing Behavior", #visualization titlesubtitle ="Types: Government, Private, Proprietary, Church ",x ="Hospital Type", ,y ="Average Treatment Costs",caption ="Source: CORGIS, gathered from Medicare", fill ="Hospital Type"#changing legend name ) +scale_fill_manual(values =c("dodgerblue1", "hotpink2", "darkseagreen", "orchid4")) #manually assigning colors
The visualization indicates that private hospitals exhibit significantly higher average treatment costs across hospital types. On the other hand, church-affiliated hospitals display the lowest average treatment costs, presenting an economical option for price-conscious patients.
Treatment Costs Across Quality Assessments
#remove "None" entries for the hospitals with no data quality1 = clean_hos2 |>filter(Rating.Effectiveness !="None")
Similar to how I removed the “Unknown” types for the prior visualization, I am removing the entries containing “None” for this boxplot. This allows us to only analyze relevant performance data.
#create a boxplot visualization displays the distribution of treatment costs by quality levelsp =ggplot(quality1, aes(x = Rating.Effectiveness, y = hospital_cost, fill = Rating.Effectiveness)) +geom_boxplot(alpha =0.8) +theme_minimal(base_family ="serif") +labs(title ="Distribution of Treatment Costs Across Quality Level", caption ="Source: CORGIS, gathered from Medicare", x ="Quality Rating in Comparison to National Rating",y ="Average Hospital Cost",fill ="Quality Level" ) +scale_fill_manual(values =c("darkslategray3", "darkorange1", "indianred3"))ggplotly(p) #make the boxplot visualization interactive
The boxplot reveals a paradoxical relationship between hospital costs and quality level. Hospitals providing “Above” average quality care had the highest median ($19K), however, the maximum cost distribution was actually lower than hospitals rated “Below” and “Same”. Both the “Below” and “Same” categories display wide spreads spanning from $2K - $26K in terms of average treatment costs. This signifies that hospitals can charge inflated prices, while continuing to offer sub-par quality care. Ultimately, higher costs do not guarantee enhanced quality care, and there are options for patients with strained budgets to receive high grade quality treatments.
Pricing Behavior Across Quality Ratings by Hospital Types
#filer out hospitals where rating was unknown quality2 = type_hospital |>filter(Rating.Overall >0)
The above code filters out any ratings below 1. The entries containing 0 did not mean the hospital rating was 0, but rather the rating was unknown.
p2 =ggplot(quality2, aes(x = hospital_cost, y = Rating.Overall ,color = Facility.Type)) +#adding small variation to the location of each data pointgeom_jitter(aes(text =paste0(#formatting the text what appears when hovering over each point"Hospital Type: ", Facility.Type, "<br>Avg Cost: $", hospital_cost, "<br>Quality Rating: ", Rating.Overall)), alpha =0.5, size =2, height = .2 ) +geom_smooth(method = lm, se =FALSE) +labs(title ="Average Treatment Cost vs Quality Rating by Hospital Type", caption ="Source: CORGIS, gathered by Medicare",x ="Average Treatment Cost", y ="Quality Rating", color ="Hospital Type"#edit legend title ) +theme_minimal(base_family ="serif")
Warning in geom_jitter(aes(text = paste0("Hospital Type: ", Facility.Type, :
Ignoring unknown aesthetics: text
ggplotly(p2, tooltip ="text") #to make the scatterplot interactive
`geom_smooth()` using formula = 'y ~ x'
By merging hospital ratings, type, and average treatment cost, the visualization further demonstrates how inflated costs do not guarantee improved quality care. Although private hospitals offer treatments at the highest average cost, their quality ratings are scattered across all tiers (much like every other hospital type).
An interesting observation is how congested the data is at the lowest rating and highest costs. If you look at the bottom right, there is a dense cluster of points, indicating that a notable number of hospitals (regardless of type) actually offer high costing treatments at low quality.
Furthermore, the regression lines are relatively flat; however proprietary hospitals display a steeper slope. Although the line is steeper, it actually demonstrates an inverse relationship between treatment cost and quality. As the cost increases, the quality rating goes down. This once again asserts that higher costs cannot ensure finer quality treatment.
Multiple Linear Regression
When selecting the variables for this multiple linear regression model, I weighed two choices:
1) Macro-scale Analysis: using hospital_cost and Rating.Overall to evaluate overall hospital pricing behavioral trends
2) Micro-scale Analysis: shifting focus and using the costs of each specific procedure (heart attack, heart failure, pneumonia, hip/knee)
I ultimately decided to continue the analysis on a macro-scale so that the linear regression would directly align with my previous research and visualizations. I also integrated Facility.Type as a categorical control variable to allow the model to evaluate the relationship between treatment costs and quality ratings while keeping hospital type constant. Utilizing Facility.Type also smoothly connects back to the first visualization within this analysis, taking into consideration the average cost differences across hospital types.
fit1 =lm(Rating.Overall ~ hospital_cost + Facility.Type, data = quality2)summary(fit1)
Call:
lm(formula = Rating.Overall ~ hospital_cost + Facility.Type,
data = quality2)
Residuals:
Min 1Q Median 3Q Max
-2.49723 -0.70254 -0.02874 0.83874 2.44836
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 3.894e+00 8.300e-02 46.911 < 2e-16 ***
hospital_cost -3.943e-05 3.332e-06 -11.832 < 2e-16 ***
Facility.TypeGovernment -4.249e-01 7.292e-02 -5.827 6.19e-09 ***
Facility.TypePrivate -8.806e-02 6.461e-02 -1.363 0.173
Facility.TypeProprietary -4.305e-01 7.241e-02 -5.946 3.04e-09 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 1.025 on 3272 degrees of freedom
Multiple R-squared: 0.05983, Adjusted R-squared: 0.05868
F-statistic: 52.06 on 4 and 3272 DF, p-value: < 2.2e-16
The multiple linear regression model displays a statistically significant relationship between hospital pricing behavior and quality care levels. The model assigned church-affiliated hospitals as the baseline (intercept = 3.894). Previously, an analysis revealed that church-affiliated hospitals offered the lowest average treatment expenditures across hospital types, turning them into a natural baseline for comparison.
A crucial observation involves private hospitals in particular. Private hospitals had a non-significant p-value of 0.173 relative to the baseline. Although private hospitals recorded the highest average treatment costs, this statistical insignificance indicates that the inflated prices of private hospital treatments do not guarantee superior quality care.
The resulting p-value of 2.2e-16 is statistically significant as it sits substantially below the threshold of 0.05. However, this only indicates that a relationship exists; it cannot measure real-world practical significance. To understand the real-world significance, we can utilize the adjusted r-squared of 0.05868. This value indicates that hospital costs and types only account for 6% of variance in quality ratings. Nearly 94% of the variation in quality remains unexplained, revealing that inflated costs alone cannot guarantee improved quality. Essentially, this low percentage reveals there is an extensive numbers of factors involved when determining the quality of care hospitals provide.
Conclusion
Ultimately, through this analysis we evaluated hospital costs across hospital types, examined distributions of costs across quality levels, compared average treatment expenditures across quality ratings by hospital types, and executed a multiple linear regression model to demonstrate these relationships through a statistical equation. The research and visualizations included within this analysis conclude that higher financial costs cannot guarantee improved quality care. These findings reinforce the belief that high quality care is able to be provided to all individuals without inflating costs and inflicting heavy financial burdens.
Technical Difficulties
The main technical challenge I faced was when turning the boxplot into an interactive visual. I was attempting to have the hospital name appear (in addition to the value) when you hover over the outliers. I tried incorporating text= into the aesthetics, however the names wouldn’t appear. I turned to boxplot guides and even GitHub forums of people who had similar issues but I unfortunately was not able to get the code to work.