[This article was first published on 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,

+ "http://freakonometrics.free.fr/CigLE.csv",
> 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")