Optimisation and regression analysis using R.