R code used for my PhD research