Shiny mortality tracker

The R programming language has steadily increased in importance for actuaries.  A marker for this importance is that knowledge of R is required for passing UK actuarial exams.  R has many benefits, but one thing that native R lacked was an easy user interface for creating apps for others to use.  Fortunately, this has changed with the release of libraries like Shiny, which we will demonstrate here in the context of an interactive mortality tracker.

In Richards (2022) I proposed a semi-parametric approach to the mortality hazard for annuity portfolios and pension schemes.  This approach can be used for exploring mortality patterns in time, including covid-19 shocks and detecting data-quality issues.  In Appendix C there was R code for calculating the semi-parametric estimate of a daily mortality tracker.  With Shiny this can be turned into an interactive exploratory tool.  To demonstrate, perform the follow steps:

  1. Download and install R.  After selecting your "mirror", there is a choice of macOS, Windows or Linux binaries.
  2. Open an R console on your computer.
  3. Install the Shiny library with \({\tt install.packages("shiny")}\).
  4. Paste the accompanying R script to this blog into the R console.

You should get something like the screenshot shown in Figure 1.

Figure 1. Shiny mortality tracker.

Screenshot of Shiny-based mortality tracker using R

The input file used by this R script is the same format generated by the data-audit feature in Longevitas.  The example input file attached to this blog is from a medium-sized pension scheme in the UK.  To use a file for a different portfolio, just edit the \({\tt read.csv()}\) call in the R script.


Richards, S. J. (2022) Real-time measurement of portfolio mortality levels in the presence of shocks and reporting delays, Annals of Actuarial Science, 16(3), pages 1–23, doi:10.1017/S1748499522000021

Written by: Stephen Richards
Publication Date:
Last Updated:

The link below is for the R script for presenting a Shiny app for the mortality tracker of Richards (2022):


The script above is pre-programmed to reference the sample input file attached to this web page:


To reference a different or local input file, just change the \({\tt read.csv()}\) call in the R script.

Previous posts

Robust mortality forecasting for 2D age-period models

The covid-19 pandemic caused mortality shocks in many countries, and these shocks severely impact the standard forecasting models used by actuaries.  I previously showed how to robustify time-series models with a univariate index (Lee-Carter, APC) and those with a multivariate index (Cairns-Blake-Dowd, Tang-Li

Tags: Filter information matrix by tag: outliers, Filter information matrix by tag: coronavirus, Filter information matrix by tag: forecasting, Filter information matrix by tag: mortality projections

Unpoking the bear

The human immune system is a powerful defender, using its arsenal of antibodies to identify and attack foreign pathogens. But such antibodies have a potential dark side: autoantibodies that begin to attack, not invading microbes, but healthy tissues.
Tags: Filter information matrix by tag: immunotherapy

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.