R code for my Master Thesis