R code developed by Insight Team