# R Toolkit

## Summary of topic

R is a free statistical software package. It may be of use to actuaries as it provides free cutting-edge statistical tools for data analysis and visualisation. This page discusses R and provides some educational resources.

## Those working on the topic

Nigel De Silva - nigel.desilva at thomasmiller dot com

Trevor Maynard - trevor.maynard at lloyds dot com

Markus Gesmann - Markus.Gesmann at lloyds dot com

## Getting started

R is a free, integrated suite of software facilities for data manipulation, calculation and graphical display. Most people simply use it as a statistics package.

R is available from the R Project website.

We created a little video, showing how to install R and all the tools required to build your own package, see here.

## Education

There are many good introductory texts and tutorials for R. Some of these are available through the R Project website, others may be found via Google or Del.icio.us

We presented a Poster at GIRO 2006 in Vienna to give a brief overview on R in isurance and reserving.

Here is a series of R examples for actuaries. The aim is to introduce actuaries to R’s capabilities and to provide simple examples of various techniques which might prove useful in actuarial work. The series starts with a very brief introduction to R. I would welcome comments, reviews, corrections, etc. for this series. In particular, I would be interested in suggestions for new examples.

## Data Visualisation

This wiki contains a separate page on this topic

## Packages

To get the most out of R you are likely to want to install some of the many packages that are available. You are also likely to want to install the following excel addin.

You might have problems getting past your proxy, if you do we suggest that you set up a batch file ("R.bat", say) using a text editor. The file should contain the following text:

REM Set the PATH to the folder were you installed R

PATH=C:\Program Files\R\R-2.8.0\bin

REM Now start R with the windows START command

START Rgui --internet2

Run this batch file to start R and hopefully you will be able to install packages directly through the R menu.

Some useful packages include:

**MASS** from Venables and Ripley’s excellent book – this contains a variety of useful functions and comes as standard in the latest version of R.**evd/evir/extRemes** – these contain functions for extreme value analysis.**car** – by John Fox’s book, which also contains a variety of general functions. **copula** – obvious really! A bit more here.**reserving** - by Markus Gesmann. He started developing some of the standard reserving tools (Mack-Chain-Ladder, Munich-Chain-Ladder, Bootstrap) in late 2003, early 2004, hopefully we can build on this. See documentation, examples, and the reserving_0.1-4.zip package for R-2.2.0 and higher for MS Windows Reserving suggests the following packages: boot, Hmisc, lattice, MASS, and grid. MG had some new ideas to use the inbuild modeling functionalty of R, which are presented here. The development of this package has stopped, see the new ChainLadder package**ChainLadder** - by Markus Gesmann. Starting reserving in R from scratch again, using linear regression as a starting point has helped tremendously to simplify the code. Mack- and Munich-Chain-Ladder procedures are already available. More information here: ChainLadder on Google Code**actuar** - package by Vincent Goulet and Sébastien Auclair (Canada) - Collection of functions related to actuarial science applications, namely credibility theory and risk theory.**maps**, just put "require(maps)" into your code. Useful for plotting geospatial data. For example this simple whereInTheWorld function.

## R Souls

R Souls is an R user group, based at Lloyds. This page contains details of the group's discussions

## Tips

## Comments

**If you would like to comment please update this wiki page in the comments section; if appropriate these will be merged in with the main text in due course. Alternatively you can discuss this page via the "Discuss" tab at the top**

**Add your comments here:**

- We might want to adopt an R coding standard, this article gives some draft thoughts.

- R can be incredibly useful for monte carlo simulations (usually much faster than Excel/VBA). However try not to use loops as they can be very inefficient. R offers subscripting/vectorisation which is a very powerful alternative. More examples on this might be useful.

- Perhaps we should consider the discussion boards on the Institute of Actuaries website to start a discussion group for new R users?

## Comments (1)

## Anonymous said

at 5:22 pm on Nov 15, 2006

regarding the proxy tip, I found RGUI.exe --internet2 works, the .exe seems to matter in some cases?

You don't have permission to comment on this page.