-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathREADME.Rmd
81 lines (61 loc) · 2.23 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
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# simulationmachine
<!-- badges: start -->
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)
[![Travis build status](https://travis-ci.org/kasaai/simulationmachine.svg?branch=master)](https://travis-ci.org/kasaai/simulationmachine)
<!-- badges: end -->
This package implements the claims history simulation algorithm detailed in [*An Individual Claims History Simulation Machine*](https://www.mdpi.com/2227-9091/6/2/29) by Andrea Gabrielli and Mario V. Wüthrich. The goal is to provide an easy-to-use interface for generating claims data that can be used for loss reserving research.
## Installation
You can install the development version from [GitHub](https://github.com/) with:
``` r
# install.packages("remotes")
remotes::install_github("kasaai/simulationmachine")
```
## Example
First, we can specify the parameters of a simulation using `simulation_machine()`:
```{r}
library(simulationmachine)
charm <- simulation_machine(
num_claims = 50000,
lob_distribution = c(0.25, 0.25, 0.30, 0.20),
inflation = c(0.01, 0.01, 0.01, 0.01),
sd_claim = 0.85,
sd_recovery = 0.85
)
charm
```
Once we have the charm object, we can use `conjure()` to perform the simulation.
```{r, message=FALSE}
library(dplyr)
records <- conjure(charm, seed = 100)
glimpse(records)
```
Let's see how many claims we drew:
```{r}
records %>%
distinct(claim_id) %>%
count()
```
If you prefer to have each row of the dataset to correspond to a claim, you can simply pivot the data with tidyr:
```{r}
records_wide <- records %>%
tidyr::pivot_wider(
names_from = development_year,
values_from = c(paid_loss, claim_status_open),
values_fill = list(paid_loss = 0)
)
glimpse(records_wide)
````
-----
Please note that this project is released with a [Contributor Code of Conduct](https://github.com/kasaai/community/blob/master/CODE_OF_CONDUCT.md). By participating in this project you agree to abide by its terms.