R code for analysis of first MS chapter