Set-up includes data.table, fpp3, and kableExtra packages
# Paths
projpath <- "C:/Users/dancu/Documents/Fall2022_ADEC743002"
rawdata <- file.path(projpath, "RawData")
output <- file.path(projpath, "Output")
# Out-of-pocket spending
pocketper<-read.csv(file.path(rawdata, "pocketper.csv"))
head(pocketper,3)
## Country.Name Country.Code
## 1 Austria AUT
## 2 Belgium BEL
## 3 Bulgaria BGR
## Series.Name Series.Code
## 1 Out-of-pocket expenditure (% of current health expenditure) SH.XPD.OOPC.CH.ZS
## 2 Out-of-pocket expenditure (% of current health expenditure) SH.XPD.OOPC.CH.ZS
## 3 Out-of-pocket expenditure (% of current health expenditure) SH.XPD.OOPC.CH.ZS
## X2015..YR2015. X2016..YR2016. X2017..YR2017. X2018..YR2018. X2019..YR2019.
## 1 19.09111 19.24335 20.63871 19.59343 19.07191
## 2 19.34007 18.00682 17.80459 18.23685 18.17289
## 3 42.50994 43.25471 43.36105 40.51738 38.97313
tail(pocketper) #shows empty rows
## Country.Name Country.Code
## 30 United Kingdom GBR
## 31
## 32
## 33
## 34 Data from database: World Development Indicators
## 35 Last Updated: 12/22/2022
## Series.Name
## 30 Out-of-pocket expenditure (% of current health expenditure)
## 31
## 32
## 33
## 34
## 35
## Series.Code X2015..YR2015. X2016..YR2016. X2017..YR2017.
## 30 SH.XPD.OOPC.CH.ZS 16.08236 16.28811 16.73583
## 31 NA NA NA
## 32 NA NA NA
## 33 NA NA NA
## 34 NA NA NA
## 35 NA NA NA
## X2018..YR2018. X2019..YR2019.
## 30 16.99979 17.07361
## 31 NA NA
## 32 NA NA
## 33 NA NA
## 34 NA NA
## 35 NA NA
pocketper<-data.table(pocketper)
pocketper<-pocketper[1:30] #remove empty rows at the bottom
# Melt year columns into rows
pocketper.m <- data.table::melt(data = pocketper,
id.vars = c("Country.Name","Series.Code"),
measure.vars = c("X2015..YR2015.", "X2016..YR2016.", "X2017..YR2017.", "X2018..YR2018.","X2019..YR2019."))
# Clean up table, rename column
pocketper.m2<-pocketper.m[,c(1,3,4)]
names(pocketper.m2)[names(pocketper.m2) == "value"] <- "OutPocketPct"
# Life Expectancy
le<-read.csv(file.path(rawdata, "le.csv"))
head(le,3)
## Country.Name Country.Code Series.Name
## 1 Austria AUT Life expectancy at birth, total (years)
## 2 Belgium BEL Life expectancy at birth, total (years)
## 3 Bulgaria BGR Life expectancy at birth, total (years)
## Series.Code X2015..YR2015. X2016..YR2016. X2017..YR2017. X2018..YR2018.
## 1 SP.DYN.LE00.IN 81.19024 81.64146 81.64390 81.69268
## 2 SP.DYN.LE00.IN 80.99268 81.43902 81.49268 81.59512
## 3 SP.DYN.LE00.IN 74.61463 74.81220 74.81463 74.96341
## X2019..YR2019.
## 1 81.89512
## 2 81.99512
## 3 75.11220
le<-data.table(le)
le<-le[1:30]
# Melt year columns into rows
le.m <- data.table::melt(data = le,
id.vars = c("Country.Name","Series.Code"),
measure.vars = c("X2015..YR2015.", "X2016..YR2016.", "X2017..YR2017.", "X2018..YR2018.","X2019..YR2019."))
le.m2<-le.m[,c(1,3,4)]
names(le.m2)[names(le.m2) == "value"] <- "LifeExp"
# Check missing values before merging
sapply(pocketper.m2, function(x) sum(is.na(x)))
## Country.Name variable OutPocketPct
## 0 0 0
sapply(le.m2, function(x) sum(is.na(x)))
## Country.Name variable LifeExp
## 0 0 0
health<-merge(pocketper.m2,le.m2)
# rename year values
health[variable == "X2015..YR2015."]$variable<-"2015"
health[variable == "X2016..YR2016."]$variable<-"2016"
health[variable == "X2017..YR2017."]$variable<-"2017"
health[variable == "X2018..YR2018."]$variable<-"2018"
health[variable == "X2019..YR2019."]$variable<-"2019"
names(health)[names(health) == "variable"] <- "Year"
# Glance at the new table
health[Country.Name=="Switzerland"]
## Country.Name Year OutPocketPct LifeExp
## 1: Switzerland 2015 25.85815 82.89756
## 2: Switzerland 2016 26.57211 83.60244
## 3: Switzerland 2017 26.40589 83.55122
## 4: Switzerland 2018 27.98195 83.75366
## 5: Switzerland 2019 25.29318 83.90488
# round decimals
health$LifeExp<-round(health$LifeExp,2)
health$OutPocketPct<-round(health$OutPocketPct,2)
as.array(round(summary(health$OutPocketPct),2)) %>% kbl(caption="Out of Pocket %", col.names = NULL) %>% kable_classic(full_width=F,html_font="Times New Roman")
| Min. | 9.26 |
| 1st Qu. | 13.01 |
| Median | 19.12 |
| Mean | 21.57 |
| 3rd Qu. | 27.64 |
| Max. | 44.43 |
as.array(round(summary(health$LifeExp),2)) %>% kbl(caption="Life Expectancy", col.names = NULL) %>% kable_classic(full_width=F,html_font="Times New Roman")
| Min. | 74.32 |
| 1st Qu. | 77.86 |
| Median | 81.19 |
| Mean | 80.05 |
| 3rd Qu. | 82.07 |
| Max. | 83.90 |
Switzerland and United States Summary Comparison
health[Country.Name=="Switzerland"] %>% kbl(caption="Switzerland Health Spending and LE") %>% kable_classic(full_width=F,html_font="Times New Roman")
| Country.Name | Year | OutPocketPct | LifeExp |
|---|---|---|---|
| Switzerland | 2015 | 25.86 | 82.90 |
| Switzerland | 2016 | 26.57 | 83.60 |
| Switzerland | 2017 | 26.41 | 83.55 |
| Switzerland | 2018 | 27.98 | 83.75 |
| Switzerland | 2019 | 25.29 | 83.90 |
health[Country.Name=="United States"] %>% kbl(caption="U.S. Health Spending and LE") %>% kable_classic(full_width=F,html_font="Times New Roman")
| Country.Name | Year | OutPocketPct | LifeExp |
|---|---|---|---|
| United States | 2015 | 11.74 | 78.69 |
| United States | 2016 | 11.63 | 78.54 |
| United States | 2017 | 11.40 | 78.54 |
| United States | 2018 | 11.30 | 78.64 |
| United States | 2019 | 11.31 | 78.79 |
I took an average of the 2015-2019 out-of-pocket and life expectancy values to plot them on a scatterplot.
meanout<-aggregate(health$OutPocketPct, by=list(health$Country.Name), FUN=mean)
names(meanout)[names(meanout) == "x"] <- "OutPocketPct"
meanlife<-aggregate(health$LifeExp, by=list(health$Country.Name), FUN=mean)
names(meanlife)[names(meanlife) == "x"] <- "LifeExp"
avgcountry<-merge(meanout,meanlife)
names(avgcountry)[names(avgcountry) == "Group.1"] <- "Country.Name"
ggplot(avgcountry, aes(x = OutPocketPct, y = LifeExp)) +
labs(title = "EU, Switzerland, UK, US", subtitle="2015-2019 averages",x="Out of Pocket Spending (% of health spending)", y="Life Expectancy (years)")+
geom_point(size=.75) +
geom_text(size=2, aes(label=Country.Name)) +
geom_smooth(method=lm,se=FALSE, fullrange=TRUE, lwd=.75)
## `geom_smooth()` using formula 'y ~ x'
The line of best fit reflects the slightly negative correlation between out-of-pocket spending and life expectancy. While not an outlier, Switzerland bucks this trend.
cor(health$OutPocketPct,health$LifeExp)
## [1] -0.3361479
This combination of high out-of-pocket spending and life expectancy provide a good starting point for more rigorous analysis. Burton-Jeangros, et. al. (2019) praise Switzerland’s consumer-driven and decentralized health marketplace. Perhaps their combination of government support, high volume spending, and market forces amount to an optimal mix for producing strong health outcomes.