tbl_mbte
with fitted signalsR/compute_metrics.R
mbte_compute_metrics.Rd
The presence of the `signal`- and `fits`-columns is required. An (error)- metric is computed based on the fitted signal-values and the original signal- values. This gets done in order to allow a comparison of different fitting-methods or to detect trends (e.g. an error metric gets used. A low error indicates, that the a model has been able to generalize the underlying trend).
mbte_compute_metrics(x, ...)
x | A |
---|---|
... | The ellipsis must only contain named elements. The elements are
used as |
A tibble with the following columns:
In this case, `desc` is a placeholder for all the columns
in x
, which are not columns for `signal` or `fits` (can be seen as
descriptive columns).
A character column with the name of the fits. Its elements will
be the names of the fitting quosures used (in most cases the names of
the fitting quosures in the call to mbte_fit
).
The name of the metric-quosure, which computed the result.
The actual result from the metric-computation (numeric or integer, depending on what type the metric quosures returned).
The metric quosures can use the following masked objects (see examples):
The predicted signal-values
The observed/measured (original) signal-values
Both masked objects (.pred
and .obs
) are numeric vectors.
A metric quosure must evalutate to a scalar numeric (double or integer-vector
of length 1). Otherwise or if an error is encountered, NA_real_
will
be the result of the metric computation.
A tibble containing event-information with the following columns:
The error, which occurred during processing. Errors occurring during the evaluation of a metric-quosure are wrapped.
The row-number of the original table (x
), at which the
error occurred.
The name of the fit.
The name of the current metric (a name in ...
).
NOTE: "current" referes to the moment the error/event occurred).
The current metric-quosure (element of ...
).
The current predicted signal-values (expected to be be numeric).
The observed signal-values (of the original signal).
NOTE: currently only errors are logged.
This function logs unusual events. A warning gets raised at the end of an
execution, if events have been logged. The event-log can be retrieved
by passing the returned object to mbte_event_log
. In this
case, a tibble containing the logged events will be returned to the user.
filtered_signals
(dataset used in examples)
#> # A tibble: 37 x 3 #> mv signal_nr signal #> <chr> <int> <list> #> 1 mv1 1 <tibble [22 × 2]> #> 2 mv3 2 <tibble [22 × 2]> #> 3 mv5 1 <tibble [30 × 2]> #> 4 mv6 1 <tibble [21 × 2]> #> 5 mv6 3 <tibble [30 × 2]> #> 6 mv7 1 <tibble [56 × 2]> #> 7 mv8 1 <tibble [29 × 2]> #> 8 mv8 2 <tibble [26 × 2]> #> 9 mv9 1 <tibble [63 × 2]> #> 10 mv10 1 <tibble [25 × 2]> #> # … with 27 more rows# fit linear model to each signal (`t` denotes the time column) fits <- mbte_fit(filtered_signals, lm = lm(value ~ t, .signal)) # define error metric (in this case normalized root mean squared error) nrmse <- function(pred, obs) { sqrt(mean((pred - obs)^2)) / (max(obs) - min(obs)) } # compute metrics # NOTE: `.pred` and `.obs` not present in scope, but provided via masking metrics <- mbte_compute_metrics(fits, nrmse = nrmse(.pred, .obs)) metrics#> # A tibble: 37 x 5 #> mv signal_nr fit metric result #> <chr> <int> <chr> <chr> <dbl> #> 1 mv1 1 lm nrmse 0.166 #> 2 mv3 2 lm nrmse 0.146 #> 3 mv5 1 lm nrmse 0.237 #> 4 mv6 1 lm nrmse 0.246 #> 5 mv6 3 lm nrmse 0.0979 #> 6 mv7 1 lm nrmse 0.254 #> 7 mv8 1 lm nrmse 0.222 #> 8 mv8 2 lm nrmse 0.221 #> 9 mv9 1 lm nrmse 0.243 #> 10 mv10 1 lm nrmse 0.156 #> # … with 27 more rows