-
Notifications
You must be signed in to change notification settings - Fork 3
/
README.Rmd
147 lines (106 loc) · 4.33 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
---
output: github_document
editor_options:
chunk_output_type: inline
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
actxps:::set_actxps_plot_theme()
```
# actxps <a href="https://mattheaphy.github.io/actxps/"><img src="man/figures/logo.png" align="right" height="138" /></a>
<!-- badges: start -->
[![R-CMD-check](https://github.com/mattheaphy/actxps/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/mattheaphy/actxps/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->
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")
```
<center><img src="man/figures/exp_gt.png" width="55%" height="55%" /></center>
Launch a Shiny app to interactively explore experience data.
```{r shiny, eval = FALSE}
exp_shiny(exposed_data)
```
<img src="man/figures/exp_shiny.png" width="100%" />
<br>
**Logo**
<a href="https://www.freepik.com/free-vector/shine-old-wooden-chest-realistic-composition-transparent-background-with-vintage-coffer-sparkling-particles_7497397.htm#query=treasure&position=7&from_view=search&track=sph">Image by macrovector</a> on Freepik