import actxps as xp
import polars as pl
import numpy as np
= xp.load_census_dat()
census_dat = xp.load_withdrawals()
withdrawals = xp.load_account_vals()
account_vals
= xp.ExposedDF(census_dat, "2019-12-31",
expo ="Surrender")
target_status= np.concatenate((np.linspace(0.005, 0.03, 10),
expected_table .2, .15], np.repeat(0.05, 3)))
[= expo.data.with_columns(
expo.data =expected_table[expo.data['pol_yr'] - 1],
expected_1=pl.when(pl.col('inc_guar')).then(0.015).otherwise(0.03)
expected_2
)
expo.add_transactions(withdrawals)= expo.data.join(account_vals, how='left',
expo.data =["pol_num", "pol_date_yr"])
on
= expo.exp_shiny(expected=['expected_1', 'expected_2']) app
exp_shiny
exp_shiny.exp_shiny(self, predictors=None, expected=None, distinct_max=25, title=None, credibility=True, conf_level=0.95, cred_r=0.05, bootswatch_theme=None, col_exposure='exposure')
Interactively explore experience data
Launch a Shiny application to interactively explore drivers of experience.
Parameters
Name | Type | Description | Default |
---|---|---|---|
predictors |
str | list | numpy.numpy.ndarray | A character vector of independent variables in the data property to include in the shiny app. |
None |
expected |
str | list | numpy.numpy.ndarray | A character vector of expected values in the data property to include in the shiny app. |
None |
distinct_max |
int | Maximum number of distinct values allowed for predictors to be included as “Color” and “Facets” grouping variables. This input prevents the drawing of overly complex plots. Default value = 25. |
25 |
title |
str | Title of the Shiny app. If no title is provided, a descriptive title will be generated based on attributes of the ExposedDF object. |
None |
credibility |
bool | If True , future calls to summary() will include partial credibility weights and credibility-weighted termination rates. |
False |
conf_level |
float | Confidence level used for the Limited Fluctuation credibility method and confidence intervals. | 0.95 |
cred_r |
float | Error tolerance under the Limited Fluctuation credibility method. | 0.05 |
bootswatch_theme |
str | The name of a preset bootswatch theme passed to shinyswatch.get_theme. | None |
col_exposure |
str | Name of the column in the data property containing exposures. This input is only used to clarify the exposure basis when the ExposedDF is also a SplitExposedDF object. For more information on split exposures, see ExposedDF.expose_split(). |
'exposure' |
Notes
If transactions have been attached to the ExposedDF
object, the app will contain features for both termination and transaction studies. Otherwise, the app will only support termination studies.
If nothing is passed to predictors
, all columns names in dat
will be used (excluding the policy number, status, termination date, exposure, transaction counts, and transaction amounts columns).
The expected
argument is optional. As a default, any column names containing the word “expected” are used.
Layout
Filters
The sidebar contains filtering widgets organized by data type for all variables passed to the predictors
argument.
At the top of the sidebar, information is shown on the percentage of records remaining after applying filters. A description of all active filters is also provided.
The top of the sidebar also includes a “play / pause” switch that can pause reactivity of the application. Pausing is a good option when multiple changes are made in quick succession, especially when the underlying data set is large.
Grouping variables
This box includes widgets to select grouping variables for summarizing experience. The “x” widget is also used as the x variable in the plot output. Similarly, the “Color” and “Facets” widgets are used for color and facets. Multiple faceting variables are allowed. For the table output, “x”, “Color”, and “Facets” have no particular meaning beyond the order in which of grouping variables are displayed.
Study type
This box includes a toggle to switch between termination studies and transaction studies (if available). Different options are available for each study type.
Termination studies
The expected values checkboxes are used to activate and deactivate expected values passed to the expected
argument. This impacts the table output directly and the available “y” variables for the plot. If there are no expected values available, this widget will not appear. The “Weight by” widget is used to specify which column, if any, contains weights for summarizing experience.
Transaction studies
The transaction types checkboxes are used to activate and deactivate transaction types that appear in the plot and table outputs. The available transaction types are taken from the trx_types
property of the ExposedDF
object. In the plot output, transaction type will always appear as a faceting variable. The “Transactions as % of” selector will expand the list of available “y” variables for the plot and impact the table output directly. Lastly, a checkbox exists that allows for all transaction types to be aggregated into a single group.
Output
Plot
This tab includes a plot and various options for customization:
- y: y variable
- Geometry: plotting geometry
- Add Smoothing: activate to plot loess curves
- Confidence intervals: If available, add error bars for confidence intervals around the selected y variable
- Free y Scales: activate to enable separate y scales in each plot
- Log y-axis: activate to plot all y-axes on a log-10 scale
The gear icon above the plot contains a pop-up menu that can be used to change the size of the plot for exporting.
Table
The gear icon above the table contains a pop-up menu that can be used to change the appearance of the table:
- The “Confidence intervals” and “Credibility-weighted termination rates” switches add these outputs to the table. These values are hidden as a default to prevent over-crowding.
- The “Include color scales” switch disables or re-enables conditional color formatting.
- The “Decimals” slider controls the number of decimals displayed for percentage fields.
- The “Font size multiple” slider impacts the table’s font size
Export
This pop-up menu contains options for saving summarized experience data or the plot. Data is saved as a CSV file. The plot is saved as a png file.