# Cigarette and life expectancy

[This article was first published on

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

**Freakonometrics » R-english**, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Yesterday evening, I uploaded a graph, with the labor productivity as a function of coffee consumption. Of course, it was for fun ! With this kind of regression, base on aggregated data, we can say almost anything, since most of them are correlated because of some (hidden) common factor, such as the wealth of the country. For instance, with a similar approach, we can see that there is an increasing relationship, when looking at life expectancy as a function of cigarette consumption,

> base=read.table( + "http://freakonometrics.free.fr/CigLE.csv", + header=TRUE,sep=",") > b=base[!is.na(base$CigCon),] > plot(b[,5],b[,4],xlab="Cigarette Consumption", + ylab="Life Expectancy (at birth)") > text(b[,5],b[,4]+1,b[,2],cex=.6) > library(splines) > X=b[,5] > Y=b[,4] > B=data.frame(X,Y) > reg=glm(Y~bs(X),data=B) > y=predict(reg,newdata=data.frame( + X=seq(0,4000,by=10))) > lines(seq(0,4000,by=10),y,col="red")

To

**leave a comment**for the author, please follow the link and comment on their blog:**Freakonometrics » R-english**.R-bloggers.com offers

**daily e-mail updates**about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.