| as_gt | R Documentation |
Generic presentation helper. Methods return a gt table for objects where a
formatted reporting table is more useful than another plot.
Create a formatted gt table from an object returned by
assess_excess_threshold(). The original object remains a regular
data.frame subclass; as_gt() is only used when a presentation table is
needed for a report, tariff note or pricing review.
Format the coefficient-level result from bootstrap_coefficients() as a
gt table. The table retains the requested link or exponentiated scale and
shows how many bootstrap estimates were available for each coefficient.
Create a formatted gt table from an object returned by rating_table().
Risk factors are presented as row groups, while fitted model effects are
shown as relativities or coefficients depending on the scale selected in
rating_table().
as_gt(x, ...)
## S3 method for class 'threshold_assessment'
as_gt(
x,
claims = TRUE,
loss = FALSE,
premium = TRUE,
locale = "nl-NL",
loss_decimals = 0,
premium_decimals = 0,
ratio_decimals = 1,
color_last_column = TRUE,
title = NULL,
subtitle = NULL,
...
)
## S3 method for class 'bootstrap_coefficients'
as_gt(
x,
scale = c("link", "exponentiated", "relativity"),
confidence = 0.95,
interval = c("percentile", "normal"),
locale = "nl-NL",
estimate_decimals = 3,
success_decimals = 1,
title = NULL,
subtitle = NULL,
...
)
## S3 method for class 'rating_table'
as_gt(
x,
significance = NULL,
show_effect_spanner = NULL,
model_labels = NULL,
locale = "nl-NL",
estimate_decimals = 3,
exposure_decimals = 0,
missing_text = "–",
title = NULL,
subtitle = NULL,
...
)
x |
A supported object to convert, such as a |
... |
Arguments passed to methods. |
claims |
Logical. If |
loss |
Logical. If |
premium |
Logical. If |
locale |
Character. Locale used to format model effects and exposure,
for example |
loss_decimals, premium_decimals, ratio_decimals |
Non-negative whole numbers controlling displayed decimals for loss amounts, premium amounts and percentage ratios. |
color_last_column |
Logical. If |
title |
Optional character. Table title. If |
subtitle |
Optional character. Table subtitle. If |
scale |
Character string. |
confidence |
Numeric scalar between 0 and 1 giving the confidence level. |
interval |
Character string. |
estimate_decimals |
Non-negative whole number. Number of decimals shown for fitted coefficients or relativities. |
success_decimals |
Non-negative whole number. Number of decimals for the success-rate percentage. |
significance |
Optional logical. If |
show_effect_spanner |
Optional logical. If |
model_labels |
Optional character vector with display labels for the
fitted models. By default, each model object name is used unchanged. An
unnamed vector is matched to the model columns in their existing order. A
named vector can map model object names to labels, for example
|
exposure_decimals |
Non-negative whole number. Number of decimals shown for the exposure column, when available. |
missing_text |
Single character string used to display missing values.
The default is an en dash ( |
The first column of a rating_table identifies the model risk factor.
as_gt() uses this column as groupname_col and sets
row_group_as_column = TRUE. Levels belonging to the same risk factor are
therefore kept together in a compact format suitable for a tariff note,
model review or technical appendix.
Risk-factor and level order are taken directly from rating_table(). Use
its risk_factor_order, level_order, numeric_level_order,
reference_first and order_model arguments to determine the order before
formatting the table.
With significance = TRUE, significance stars are appended to the fitted
effects and the significance levels are shown below the table. This requires
an object originally created with rating_table(significance = TRUE),
because p-value information is deliberately not retained when significance
is disabled during table construction. Significance stars are a statistical
diagnostic and should be interpreted together with exposure, effect size,
model stability and actuarial relevance.
In the underlying rating_table, estimates and significance indicators are
stored in separate est_* and signif_* columns. as_gt() merges each pair
only for display. The estimates therefore remain numeric in the source
object, including when several models are presented in one table.
A gt_tbl object for supported methods.
Martin Haringa
portfolio <- data.frame(
policy_id = 1:10,
sector = rep(c("Industry", "Retail"), each = 5),
claim_count = c(
0, 1, 1, 1, 1,
0, 1, 1, 1, 1
),
claim_amount = c(
0, 25000, 120000, 50000, 175000,
0, 40000, 90000, 150000, 300000
),
policy_years = rep(1, 10)
)
thresholds <- assess_excess_threshold(
data = portfolio,
claim_amount = "claim_amount",
thresholds = c(25000, 50000, 100000, 150000),
exposure = "policy_years",
group = "sector",
claim_count = "claim_count"
)
if (requireNamespace("gt", quietly = TRUE)) {
as_gt(thresholds)
}
portfolio <- MTPL
portfolio$zip <- as.factor(portfolio$zip)
frequency_model <- glm(
nclaims ~ bm + zip + offset(log(exposure)),
family = poisson(),
data = portfolio
)
fitted_tariff <- rating_table(
frequency_model,
model_data = portfolio,
exposure = "exposure",
significance = TRUE
)
if (requireNamespace("gt", quietly = TRUE)) {
as_gt(fitted_tariff)
as_gt(fitted_tariff, model_labels = "Frequency model")
as_gt(fitted_tariff, significance = FALSE, locale = "en-US")
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.