Healthcare Expenditure As A Percentage Of GDP

By Steve Dunn

This project was completed as part of CUNY IS608's curriculum. To see other projects, please click here for the homepage.

My final project is on healthcare expenditure as a percentage of GDP in countries around the world. I chose this topic because it is currently a part of public discourse and hope to find if expenditure on health care is a real indicator of life expectancy. The data source is from the World Bank http://data.worldbank.org/indicator/SH.XPD.PCAP/countries.

Loading Libraries:

suppressPackageStartupMessages(library("maps"))
suppressPackageStartupMessages(library("mapproj"))
suppressPackageStartupMessages(library("rgeos"))
suppressPackageStartupMessages(library("maptools"))
suppressPackageStartupMessages(library("rworldmap"))
suppressPackageStartupMessages(library("RColorBrewer"))
suppressPackageStartupMessages(library("mapdata"))
suppressPackageStartupMessages(library("ggplot2"))
suppressPackageStartupMessages(library("reshape2"))
suppressPackageStartupMessages(library("sqldf"))

Loading Cleaned Data

# Loading Data and setting working Directory
setwd("C:\\Users\\dundeva\\Desktop\\SPS\\IS608\\CUNY_IS608-master\\FinalProject")

# loading Health Care expenditure data
hcare <- read.csv("../FinalProject/HealthcareExpenditurecleaned.csv", header = TRUE, 
    sep = ",", check.names = FALSE)
summary(hcare)

# loading life expectancy data
lifexpct1 <- read.csv("../FinalProject/LifeExpectancycleaned.csv", header = TRUE, 
    sep = ",", check.names = FALSE)
summary(lifexpct1)

# loading Regions
cregion <- read.csv("../FinalProject/Region.csv", header = TRUE, sep = ",", 
    check.names = FALSE)
summary(cregion)

# loading Shape File
np_dist2 <- readShapeSpatial("../FinalProject/ne_110m_admin_0_countries.shp")

Transforming the Data set from a wide to long format so that there is a column for all the Years(1995-2012) and then merge the Cost , Age and Region data set

hc <- reshape(hcare, varying = c("1995", "1996", "1997", "1998", "1999", "2000", 
    "2001", "2002", "2003", "2004", "2005", "2006", "2007", "2008", "2009", 
    "2010", "2011", "2012"), v.names = "cost", timevar = "Year", times = c("1995", 
    "1996", "1997", "1998", "1999", "2000", "2001", "2002", "2003", "2004", 
    "2005", "2006", "2007", "2008", "2009", "2010", "2011", "2012"), direction = "long")

life <- reshape(lifexpct1, varying = c("1995", "1996", "1997", "1998", "1999", 
    "2000", "2001", "2002", "2003", "2004", "2005", "2006", "2007", "2008", 
    "2009", "2010", "2011", "2012"), v.names = "Age", timevar = "Year", times = c("1995", 
    "1996", "1997", "1998", "1999", "2000", "2001", "2002", "2003", "2004", 
    "2005", "2006", "2007", "2008", "2009", "2010", "2011", "2012"), direction = "long")

# merging life expectancy and Expenditure data sets

hl <- sqldf("SELECT hc.Countryname,hc.CountryCode, hc.Year , hc.cost, life.Age \n       FROM hc LEFT JOIN life where hc.CountryName= life.CountryName \n             and hc.CountryCode=life.countryCode \n             and hc.Year=life.Year ")

# Adding Regions merged data set
hl2 <- sqldf("Select hl.Countryname,hl.CountryCode, hl.Year , hl.cost, hl.Age,cregion.Region\n           from hl left join cregion where hl.CountryCode=cregion.CountryCode\n           and hl.Countryname=cregion.CountryName\n           and cregion.Region !=''")

# Plot Heat Map For World Health Expenditure
sPDF <- joinCountryData2Map(hl2, joinCode = "NAME", nameJoinColumn = "CountryName")
par(mai = c(0, 0, 0.2, 0), xaxs = "i", yaxs = "i")
mapCountryData(sPDF, mapTitle = "World Health Expenditure", nameColumnToPlot = "cost")

# Plot Heat Map For World Life Expectancy
sPDF <- joinCountryData2Map(hl2, joinCode = "NAME", nameJoinColumn = "CountryName")
par(mai = c(0, 0, 0.2, 0), xaxs = "i", yaxs = "i")
mapCountryData(sPDF, mapTitle = "World Life Expectancy ", nameColumnToPlot = "Age")

Life Expectancy vs Percentage GDP on Healthcare

suppressPackageStartupMessages(library("googleVis"))
# Creating Geo Charts with googlevis package

GeoChart <- gvisGeoChart(hl2, "CountryName", "cost", "Age", options = list(width = 610, 
    height = 400, colorAxis = "{colors:['#99FF66','#2EB82E','#006600']}", backgroundColor = "#F0F0F0"))
# Display chart
print(GeoChart, "chart")

Plotting a subset of the data to compare spending against Age for the BRIC countries along with Canada,Great Britain and Australia

# Setting year as numeric instead of char
D <- transform(hl2, Year = as.numeric(Year))

# plotting a subset of the data to compare spending against Age
(hsb7 <- D[D$CountryCode %in% c("BRA", "CHN", "IND", "RUS", "USA", "GBR", "CAN", 
    "AUS"), ])
G <- gvisGeoChart(hsb7, "CountryName", "cost", "Age", options = list(width = 610, 
    height = 400, colorAxis = "{colors:['#99FF66','#2EB82E','#006600']}", backgroundColor = "#F0F0F0"))
T <- gvisTable(hsb7, options = list(width = 610, height = 270))
GT <- gvisMerge(G, T, horizontal = FALSE, chartid = "gt")
M <- gvisMotionChart(hsb7, "CountryCode", "Year", options = list(width = 610, 
    height = 670))

GTM <- gvisMerge(GT, M, horizontal = TRUE, tableOptions = "bgcolor=\"#CCCCCC\" cellspacing=10")

# Display chart
print(GTM, "chart")