R functions used in analysis