
rm(list=ls())

library(quantreg)

###  WHO data


D = read.csv("WHO_Life_expectancy.csv",header=TRUE)
D = D[D$Year == 2000,]
D = D[,c(1,4,7,8,17,22)]
D = na.omit(D)

Country = D[,1]
D = D[,-1]
attach(D)
n = nrow(D)


## QUANTILE One regressor -- Log GDP

LogGDP = log(GDP)

pdf("WHO_Quantile.pdf")
plot(LogGDP,Life.expectancy, pch=21,cex=1.8, bg="lightpink",
           ylab="",xlab="",cex.axis=1.5)
title(ylab="Life Expectancy",line=2.3, cex.lab=1.7)
title(xlab="Log(GDP)",line=2.5, cex.lab=1.7)

out = rq(Life.expectancy ~ LogGDP,tau=c(.1,.5,.9))
summary(out,alpha=.05)
fit = out$fitted.values
lines(LogGDP,fit[,1],col="red",lwd=4)
lines(LogGDP,fit[,2],col="purple",lwd=4)
lines(LogGDP,fit[,3],col="red",lwd=4)
dev.off()

