MortData ‐ Custom data - hnlearndev/rslife GitHub Wiki
Custom mortality and morbidity data
Schema for custom data
If the custom mortality and morbidity data is used out of SOA XML and IFOA XLS format, the data schema must follow the below three options:
1. Ultimate Tables - age + qx
Single mortality rate per age - the most common format:
| age | qx |
|-----|---------|
| 25 | 0.00120 |
| 26 | 0.00135 |
| 27 | 0.00150 |
| ... | ... |
2. Ultimate Tables - age + lx
Survivor function format - same data expressed as remaining lives:
| age | lx |
|-----|----------|
| 25 | 100000.0 |
| 26 | 99880.0 |
| 27 | 99745.1 |
| ... | ... |
3. Select Tables - age + qx + duration
Mortality rate under selection effect (based on duration since issued)
| age | qx | duration |
|-----|---------|----------|
| 35 | 0.00080 | 1 |
| 35 | 0.00095 | 2 |
| 35 | 0.00110 | 3 |
| 36 | 0.00085 | 1 |
| 36 | 0.00102 | 2 |
| 36 | 0.00118 | 3 |
| ... | ... |... |
Method from_df
// DataFrames - qx
let df_qx = df! {
"age" => [25u32, 26, 27],
"qx" => [0.001f64, 0.0012, 0.0015],
}?;
// Custom data from dataframe
let data_from_df_with_qx = MortData::from_df(df_qx)?;
// DataFrames - lx
let df_lx = df! {
"age" => [25u32, 26.0, 27.0],
"lx" => [100000.0f64, 99900.0, 99780.0],
}?;
// Custom data from dataframe
let data_from_df_with_lx = MortData::from_df(df_lx)?;
- Backbone of cutom data import under struct MortData
- All others custom data import will use this method as medium.
- Underlied with rules and validation to support data integrity and related calculation.
- age data must be consecutive with no gap and u32 convertible
- qx and lx must be f64 convertible
- qx must be between 0 and 1.
Method from_xlsx
// Custom data from spreadsheet XLSX
let data_from_xlsx = MortData::from_ods("data/mortality.xlsx", "select")?;
- Sheet name is required.
- Header is at the first row (row A).
- Data starts from second row (row B).
Method from_ods
// Custom data from spreadsheet ODS
let data_from_ods = MortData::from_ods("data/mortality.ods", "select")?;
Similar to from_xlsx method but used for ods files.