mutate_metrics {expstudy} | R Documentation |
Add common metrics to an experience study
Description
mutate_metrics()
calculates metrics for an experience study using common
measures associated with the data. These measures are identified via the
measure_sets
argument which can be provided directly or be guessed using
regular expressions (regexs
). See guess_measure_sets()
for additional
detail on how this guessing is implemented.
Usage
mutate_metrics(
.data,
measure_sets = guess_measure_sets(.data),
metrics = list(AVG_OBSRV = avg_observed, AVG_EXPEC = avg_expected, CI_FCTR = ci_fctr,
AE_RATIO = ae_ratio, CREDIBILITY = credibility),
...,
.by = NULL,
.keep = c("all", "used", "unused", "none"),
.before = NULL,
.after = NULL
)
Arguments
.data |
A |
measure_sets |
A (potentially named) list of measure sets. Only need to specify once if
chaining multiple |
metrics |
A named list of functions to calculate metrics. Each function will be
applied to each set identified in |
... |
Additional (optional) arguments passed along to each (metric function)metrics. |
.by |
< |
.keep |
Control which columns from
|
.before , .after |
< |
Details
This function is structured in a way that uses sets of measures within the
study as the first function argument of each metric function. The default
argument uses a set of metric functions, provided by expstudy
, which are
commonly requested metrics used in actuarial analyses. For convenience,
a vectorized version of these default metric functions have also been
provided; see metrics for more information.
Value
An object of the same type as .data
. The output has the following
properties:
Columns from
.data
will be preserved according to the.keep
argument.Existing columns that are modified by
...
will always be returned in their original location.New columns created through
...
will be placed according to the.before
and.after
arguments.The number of rows is not affected.
Columns given the value
NULL
will be removed.Groups will be recomputed if a grouping variable is mutated.
Data frame attributes are preserved.
Naming convention
expstudy
uses a naming convention where some functions are prefixed by the
underling dplyr
verb. The purpose of this is to associate the resulting
structure of the expstudy
function with a very similar output as what the
dplyr
function would produce. Note that the intention here is not replace
all dplyr
use cases but instead add specific functionality to streamline
routine experience study analyses.
Examples
# Metrics can be added at a seriatim level, but often are
# calculated after some aggregation is applied to a cohort:
mortexp |>
dplyr::group_by(
GENDER
) |>
summarise_measures() |>
mutate_metrics()