## R for actuaries

*28 March 2018 | by Gemma Gregson*

**The use of R in insurance is not new, but a combination of technological advances and the current operating environment mean that demand for R is increasing. In this blog post, Mark Lee and Buu Truong discuss the use of R in actuarial processes.**

Like many actuaries in the insurance industry, Buu has grown up with Excel. While there are some actuaries who use R, it has yet to enter the mainstream. With 20 years’ experience in numerical computing Mark hopes that will change and so the Excel versus R debate is guaranteed to spark a lively discussion in the Insight office.

##### What is R?

**Mark Lee (ML):** R is an open source programming language and an environment for statistical computing and graphical data analysis. It’s what is known as an interpreted language meaning that you can type commands on-the-fly interactively rather than writing a full program like you have to with compiled languages such as C++.

**Buu Truong (BT):** As it’s open source, the code is freely available and can be inspected, modified and enhanced, rather like a cake recipe. This differs to proprietary software where often only the vendor can modify the software.

There are many applications and programs that use open source. Python is one such example and has similar uses to R. The Android operating system and the web browser, Mozilla Firefox, are also based on open source code.

##### Why is R of interest to actuaries?

**(BT)** R can be used for reserving, pricing and capital modelling. It is a good tool for actuaries because it is good at data analysis and visualisation.

**(ML)** R can effectively handle large arrays of data and we have helped personal lines clients develop pricing models using R. It is not just a way to implement new data science and machine learning techniques, R can be used for more traditional actuarial methods such as GLMs.

We are also seeing demand from the London Market as R can also be used on small data sets. For example, parameter error in the London Market can be quantified and understood by using statistical methods and R is a powerful tool for such analysis.

**(BT)** As we discussed in a previous blog, the ‘big three’ ie GDPR, IFRS17 and Brexit are causing companies to scrutinise their actuarial processes. Where changes are being made, R is being considered as a feasible alternative to Excel and proprietary software.

R is a good tool for actuaries because it is good at data analysis and visualisation

##### Is R better than Excel?

**(ML)** Yes! If you have a complicated process, then Excel is not the right tool. R can interface with commonly used tools and databases, automate reporting and free up time from processes so that you can focus on analysis.

My rule of thumb is if you use the INDIRECT function or nested/multiple lookups in Excel then it would almost certainly be simpler, more transparent and more maintainable in R. Similarly, if you have lots of rows in Excel, then a R-based model will be slimmer and faster.

In the London Market, pricing is often done using Excel, but R would be better for stochastic models or for deterministic models that have a lot of statistical analysis. There is also an appetite in pricing for applying machine learning techniques to large sets of data. R lends itself to that kind of work much better than Excel does.

Another example where we have used R is in the technical provisions process where you are manipulating an array of data. That can be done much more easily in R than with Excel.

**(BT)** But Excel is good because it allows people at different technical levels to read the sheets. There is an instant audit trail and you can see all the intermediate steps. Ironically, R is used less in capital modelling, yet the capital modelling process is closer to what R does well because it holds all the steps in its memory and you have to ask the machine to pull something specific out.

Overall, I would say the answer depends – R isn’t right for everything. You need to consider where R is best, where Excel is best and where proprietary tools are best. The answer will depend on what it is being used for and the skills and knowledge of the team.

##### Is R better than the proprietary software used for reserving, pricing and capital modelling?

**(BT)** I wouldn’t necessarily say it is better in all cases. Lots of insurance companies use proprietary software tools and it would not always be best to move away from those, but there are instances where companies should consider using R. One example of this is in capital modelling where Insight are building capital models in R for validating outputs from a proprietary software model.

Decision makers need to ask if R would be a good solution and the answer to that will depend on its use and will also vary from company to company.

**(ML)** R could be a good capital modelling option for smaller companies that are upgrading from Excel. It has the advantage of being free, unlike proprietary software which is licensed. Also, insurers may already have individuals with R skills and they can hire from other industries meaning a cheaper, more sustainable resource pool.

**(BT)** R is supported by a vibrant community. With proprietary software there is the risk that the vendor will decide not to support the software in the future. That reliance is removed if the model is based on R.

**(ML)** R is also relatively fast and has optimised packages to implement common statistical tasks. As with proprietary software, the run speed will depend on the complexity of the model, but R can give proprietary software tools a run for their money!

##### Is R the only alternative?

**(ML)** No, there are other open-source software tools such as Python, Julia and Stan. R is of particular interest because it is already part of the actuarial exam syllabuses in other countries and we understand that the Institute and Faculty of Actuaries is introducing computer-based assessments in R to the 2019 curriculum. We may start to see a new cohort of actuaries coming through who are as familiar with R as they are with Excel.

**(BT)** Even if you have already completed the exams, you should become familiar with what R is, how it can be used, and how it compares to other programming languages, so that you can make an informed choice as to the best tool for the job.

##### Do actuaries need to be able to code to use R?

**(BT)** If you can build a spreadsheet in Excel then there is no reason why you can’t learn to code in R. There are more than 10,000 packages that have been developed by the R community that are available to download so there is often no need to completely reinvent the wheel. It is a case of learning the syntax and having a programming mindset.

**(ML)** R is a variant of the language S, which was designed to be an interactive environment and one where the user didn’t think of themselves as programming. RStudio is an integrated development environment that is free to download and helps you interact with R. We have had actuaries on our data science courses who have never coded before and after just one day, they are able to import data, analyse it with the help of a graphics package, and then export the analysis to Word or pdf.

**(BT)** Knowledge of R should complement existing skills. People joke that actuaries might be replaced by computers one day and some may worry that the strengths of R will take us one step closer to that – but R is just another tool to help us with our analysis. It will never replace our business knowledge and ability to communicate technical concepts. Just like anything else, R has its pros and cons that need to be weighed up in the context of use.

Buu Truong is the managing director of Insight Risk Consulting and Mark Lee is a senior consultant at Insight Risk Consulting.

This blog is based on our experience of the UK general insurance market. It is intended for general interest purposes only.