https://github.com/mattheaphy/actxps
Create actuarial experience studies
https://github.com/mattheaphy/actxps
Last synced: 3 months ago
JSON representation
Create actuarial experience studies
- Host: GitHub
- URL: https://github.com/mattheaphy/actxps
- Owner: mattheaphy
- License: other
- Created: 2022-06-12T21:42:20.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-06-25T12:15:04.000Z (8 months ago)
- Last Synced: 2024-10-30T00:11:04.621Z (4 months ago)
- Language: R
- Homepage: https://mattheaphy.github.io/actxps/
- Size: 18.8 MB
- Stars: 13
- Watchers: 3
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE
Awesome Lists containing this project
- jimsghstars - mattheaphy/actxps - Create actuarial experience studies (R)
README
---
output: github_document
editor_options:
chunk_output_type: inline
---```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)actxps:::set_actxps_plot_theme()
```
[](https://github.com/mattheaphy/actxps/actions/workflows/R-CMD-check.yaml)
The actxps package provides a set of tools to assist with the creation of
actuarial experience studies. Experience studies are used by actuaries to
explore historical experience across blocks of business and to inform assumption
setting for projection models.- The `expose()` family of functions convert census-level records into policy
or calendar year exposure records.
- The `exp_stats()` function creates experience summary data frames containing
observed termination rates and claims. Optionally, expected termination rates,
actual-to-expected ratios, and limited fluctuation credibility estimates can
also be returned.
- The `add_transactions()` function attaches summarized transactions to a
data frame with exposure-level records.
- The `trx_stats()` function creates transaction summary data frames containing
transaction counts, amounts, frequencies, and utilization. Optionally,
transaction amounts can be expressed as a percentage of one or more variables to
calculate rates or actual-to-expected ratios.
- The `autoplot()` and `autotable()` functions creates plots and tables for
reporting.
- The `exp_shiny()` function launches a Shiny app that allows for interactive
exploration of experience drivers.## Installation
The actxps package can be installed from CRAN with:
``` r
install.packages("actxps")
```To install the development version from [GitHub](https://github.com/) use:
``` r
devtools::install_github("mattheaphy/actxps")
```## Basic usage
An expanded version of this demo is available in `vignette("actxps")`.
The actxps package includes simulated census data for a theoretical
deferred annuity product with an optional guaranteed income rider.
The grain of this data is one row *per policy*.```{r packages, message=FALSE}
library(actxps)
library(dplyr)census_dat
```Convert census records to exposure records with one row *per policy per year*.
```{r example}
exposed_data <- expose(census_dat, end_date = "2019-12-31",
target_status = "Surrender")exposed_data
```Create a summary grouped by policy year and the presence of a guaranteed
income rider.```{r stats-grouped}
exp_res <- exposed_data |>
group_by(pol_yr, inc_guar) |>
exp_stats()exp_res
```Calculate actual-to-expected ratios.
First, attach one or more columns of expected termination rates to the exposure
data. Then, pass these column names to the `expected` argument of `exp_stats()`.```{r stats-ae}
expected_table <- c(seq(0.005, 0.03, length.out = 10), 0.2, 0.15, rep(0.05, 3))# using 2 different expected termination rates
exposed_data <- exposed_data |>
mutate(expected_1 = expected_table[pol_yr],
expected_2 = ifelse(exposed_data$inc_guar, 0.015, 0.03))exp_res <- exposed_data |>
group_by(pol_yr, inc_guar) |>
exp_stats(expected = c("expected_1", "expected_2"))exp_res
```
Create visualizations using the `autoplot()` and `autotable()` functions.
```{r plots, warning=FALSE, message=FALSE, dpi = 300}
autoplot(exp_res)
``````{r table1, eval = FALSE}
# first 10 rows showed for brevity
exp_res |> head(10) |> autotable()
``````{r table2, echo = FALSE}
exp_res |> head(10) |> autotable() |> gt::gtsave("man/figures/exp_gt.png")
```
Launch a Shiny app to interactively explore experience data.
```{r shiny, eval = FALSE}
exp_shiny(exposed_data)
```
**Logo**Image by macrovector on Freepik