#Download all 3 datasets
medicaid_final <- read_csv("medicaid_final.csv") %>%
mutate(state=str_to_title(state))
mortality_final <- read_csv("mortality_final.csv") %>%
mutate(state=str_to_title(state))
population_final <- read_csv("population_final.csv") %>%
mutate(state=str_to_title(state))
# join data set
medicaid_mortality <- full_join(
x = medicaid_final, y = mortality_final, by = "state")
medicaid_mortality_population <- full_join(x=medicaid_mortality,
y=population_final, by = "state") %>%
mutate(across(starts_with("spending_per_enrol"),
~round(., 0)))Milestone 4
Joining dataset
Creating new variables
Spending per capita (i.e, spending per enrolee) was created as part of #medicaid_final in milestone 3.
Mortality/capita was calculated per 10,000 people
medicaid_mortality_population <- medicaid_mortality_population %>%
mutate(cancer_mort_rate =
cancer_death/population_per_state * 10000) %>%
mutate(ihd_mort_rate = ihd_death/population_per_state * 10000)%>%
mutate(across(starts_with("cancer_mort_rate"), ~round(., 2)))%>%
mutate(across(starts_with("ihd_mort_rate"), ~round(., 2)))Visualizations
Visual 1: Medicaid Spending by State
Interactive graph of Medicaid spending by state by a bar graph, and hovering over bar would show state name and spending per enrollee.
plot_ly(
medicaid_mortality_population,
x= ~state,
y= ~spending_per_enrol,
mode="bar")%>%
layout(
title="Medicaid Spending by State",
yaxis=list(title="Average Spending per EnroLlee", ascending=T),
xaxis=list(title="State", tickangle= -45,
categoryorder="total descending"),
paper_bgcolor="azure",
plot_bgcolor="white"
)Kansas, Oregon, Indiana, Alaska and Maryland have the highest average Medicaid spending per enrolee. Alabama, Virginia, North Dakota, Arkansas, and North Carolina have the lowest average Medicaid spending per enrollee.
Visual 2: Intaractive Graph of Cancer and Ischemic Heart Disease (IHD) Mortality by State
Mortality rate is calculated per 10,000 people. Hovering over each colored bar will show state, cancer and IHD mortality rate per 10,000 people, and the perspective state’s Medicaid spending per enrolee. Hovering over each bar will display mortality rate (cancer or IHD) and the perspective state’s spending.
plot_ly(medicaid_mortality_population,
x=~state,
y= ~ihd_mort_rate,
name='IHD Mortality Rate',
type='bar',
text= ~paste('spending:', spending_per_enrol)
) %>% add_trace(
y=~cancer_mort_rate,
name='Cancer Mortality Rate') %>%
layout(
title="Cancer and IHD Mortality Rate by States",
yaxis=list(title="Mortality Rate per 10,000 adults",
ascending=T),
xaxis=list(title="State",
tickangle= -45, categoryorder="total descending"),
barmode='stack',
annotations=list(x = 1.3,
y =-0.1,
text='Note:<br>IHD =<br>Ischemic Heart Disease
<br>2. Mortality rate <br> is calculated <br> per 10,000 people',
showarrow=F,
xref='paper',
yref='paper',
align="left")
)Top 5 states with cancer mortality are: West Virginia, Mississippi, Kentucky, Maine and Arkansas; and bottom 5 states are: California, Alaska, District of Columbia, Colorado and Utah. Top 5 states with ischemic heart disease mortality are: Mississippi, Arkansas, West Virginia, Tennessee and Kentucky; and bottom 5 states are: Massachusetts, Oregon, Minnesota, Colorado and Utah. The highest cancer mortality rate is 11.94- compared and lowest 4.17- per-10,000-people. The highest IHD mortality rate is 7.12- and lowest 1.72-per -10,000 -people.
Visual 3: Correlation Between Cancer Mortality Rate and Healthcare Expenditure
#Code used to generate visual, inclduing legend
graph1 <- ggplot(medicaid_mortality_population,
aes(x=spending_per_enrol, y=cancer_mort_rate)) +
geom_point(color = "#FC4E07", size = 3, shape = 23)+
geom_smooth(method = lm, se = FALSE) +
theme(legend.position="none") +
labs(x="Average Spending per Adult",
y="Mortality rate per 10,000 Adults",
title="Correlation Between Medicaid Spending by State\nand Cancer Mortality rate",
caption="Note: IHD:Ischemic Heart Disease;
Cancer mortality is calculated per 10,000 adults") +
theme_bw()
graph1There seems to be a slight negative correlation between state medicaid spending per adult enrollee and cancer related death per 10,000 adults. As average state medicaid spending per adult increased, cancer related deaths per 10,000 adults increased.
Visual 4: Correlation Between Ischemic Heart Disease (IHD) Mortality Rate and Healthcare Expenditure
#Code used to generate visual, inclduing legend
graph2 <- ggplot(medicaid_mortality_population,
aes(x=spending_per_enrol, y=ihd_mort_rate)) +
geom_point(color = "darkblue", size = 3, shape = 4)+
geom_smooth(method = lm, se = FALSE) +
#geom_text(aes(label=state),
# size=2,
# nudge_x = 0.45,
# nudge_y=0.25,
# check_overlap=T) +
theme(legend.position="none") +
labs(x="Average spending per adult",
y="Deaths per 10,000 adults",
title="Correlation Between Medicaid spending per
Adult by State \n and IHD Mortality State",
caption="IHD:Ischemic Heart Disease;
IHD mortality is calculated per 10,000 adults") +
theme_bw()
graph2There seems to be a slight negative correlation between state medicaid spending per adult enrolee and Ischemic Health Disease (IHD) related death per 10,000 adults. As average state medicaid spending per adult increased, IHD related deaths per 10,000 adults increased.
Visual 5: Interactive Table of 5 States with Lowest Medicare Spending, and Top 5 States of Cancer and Ischemic Heart Disease (IHD) Mortality Rate
An interactive table is constructed of 51 states with Medicare spending per enrollee, and their associated cancer and IHD mortality rates. The Medicare spending column is highlighted with 5 states of lowest spending. The top 5 cancers and IHD mortality rates were highlighted.
table <- medicaid_mortality_population %>%
select(state,spending_per_enrol,
cancer_mort_rate, ihd_mort_rate)%>%
rename("State"=state, "Spending Per Enrollee"=spending_per_enrol,
"Cancer Mortality Rate"=cancer_mort_rate,
"IHD Mortality Rate"=ihd_mort_rate)
datatable(table,
caption=htmltools::tags$caption(
style='caption-side:top; text-align: center;
color:black; font-size:150%;',
'Table1: Five States with Lowest Medicare Spending
and Top 5 States of Cancer and IHD Mortality Rates'),
options=list(pageLength=15,
order=list(1,'asc'),
columnDefs=list(
list(className='dt-center', targets=1:3)),
dom= 'ltip'),
rownames = F,
filter="top"
) %>%
formatStyle(
'Spending Per Enrollee',
backgroundColor=styleInterval(2239, c('yellow','white'))
)%>%
formatStyle(
'Cancer Mortality Rate',
backgroundColor = styleInterval(9.40,c('white', 'yellow'))
)%>%
formatStyle(
'IHD Mortality Rate',
backgroundColor = styleInterval(6.0,c('white', 'yellow'))
)When Medicaid spending is sorted in ascending order and 15 states shown per page, only 1 state, Arkansas, is also identified to be within top 5 of highest cancer and IHD mortality rate. Mississippi and Maine are within the 15 states that have lowest Medicaid spending per enrollee, but have high IHD and cancer realted morality, and cancer related mortality, respectively.
Visual 6: Interactive Visualization of Medicare Spending Among States with Top and Bottom Five Mortality Rates of Cancer and Ischemic Heart Disease (IHD)
States of top and bottom 5 cancer and IHD mortality rates and their associated Medicaid spending per enrollee are selected, resulting in 14 unique states. Scatter plots of IHD and cancer mortality rates were plotted. Size of circles signifies amount of spending of each state. Hovering over each circle will display respective state and spending per enrollee.
cancer_top5<-medicaid_mortality_population %>%
arrange(desc(cancer_mort_rate))%>%
select("state", "spending_per_enrol",
"cancer_mort_rate","ihd_mort_rate" ) %>% head(5)
ihd_top5<-medicaid_mortality_population %>%
arrange(desc(ihd_mort_rate))%>%
select("state", "spending_per_enrol",
"cancer_mort_rate","ihd_mort_rate") %>% head(5)
cancer_bot5<-medicaid_mortality_population %>%
arrange(cancer_mort_rate)%>%
select("state", "spending_per_enrol",
"cancer_mort_rate","ihd_mort_rate") %>% head(5)
ihd_bot5<-medicaid_mortality_population %>%
arrange(ihd_mort_rate)%>%
select("state", "spending_per_enrol",
"cancer_mort_rate","ihd_mort_rate") %>% head(5)
mort_5 <-rbind(cancer_top5,cancer_bot5,ihd_top5,ihd_bot5)%>%
distinct(state, .keep_all = TRUE)
plot_ly(mort_5, x = ~cancer_mort_rate, y = ~ihd_mort_rate,
text= ~paste('State:', state,
'<br>Spending ($):', spending_per_enrol),
type = 'scatter',
mode = 'markers', size = ~spending_per_enrol,
sizes = c(10, 50),
marker = list(opacity = 0.5,
sizemode = 'diameter'),
name='Size =<br>Medicare Spending <br>per Enrollee'
)%>%
layout(title = 'IHD vs Cancer Mortality by Medicaid Spending per Enrollee',
xaxis = list(title= 'Cancer Mortality per 10,000 People',
showgrid = FALSE,
range=c(0,13)),
yaxis = list(title = 'IHD Mortality per 10,000 People',
showgrid = FALSE,
range=c(0,13)),
showlegend=TRUE,
annotations=list(x = 1.3,
y =-0.1,
text='Note:<br>1. IHD =<br>Ischemic Heart Disease
<br>2. Mortality rate <br> is calculated <br> per 10,000 people',
showarrow=F,
xref='paper',
yref='paper',
align="left")
)The right side cluster consists of 5 states with highest cancer and IHD mortality, left side clusters consists of 8 states with lowest cancer and IHD moralities, and one state, Maine, exhibits high cancer mortality rate and low IHD mortality rate. Although lowest medicare spending state, Arkansas (smallest circle of the whole plot), locates within the high mortality cluster, there is also a wide range of spending amount within the cluster; and same observation is also seen within the low mortality cluster.