R code to support various analyses