plot_cumulative_loss: Plot Cumulative Loss Differences

View source: R/plots.R

plot_cumulative_lossR Documentation

Plot Cumulative Loss Differences

Description

Generates a time-series plot of cumulative squared error (MSE) loss differences between each competing forecast and the benchmark. A positive value at time t means the competing forecast has accumulated lower squared errors than the benchmark up to that point (i.e., the forecast is outperforming the benchmark cumulatively).

Usage

plot_cumulative_loss(data_matrix, benchmark_col = ncol(data_matrix))

Arguments

data_matrix

Matrix or data frame of dimension P x K_total, where rows are time periods and columns are pre-computed forecast errors (y_t - \hat{y}_{k,t}) for each forecast including the benchmark. Do not pass raw forecasts: the function squares column values directly, so passing raw forecasts produces cumulative sums of squared forecast levels, not cumulative MSE differences.

benchmark_col

Index or name of the benchmark column. Defaults to the last column.

Details

The cumulative loss difference for forecast k at time t is:

\text{CLD}_{k,t} = \sum_{s=1}^{t} \left( e_{\text{bench},s}^2 - e_{k,s}^2 \right)

where e_{k,s} = y_s - \hat{y}_{k,s} is the forecast error of forecast k at period s. The function squares the values in data_matrix directly, so pre-computed forecast errors (not raw forecasts) must be passed for the result to represent cumulative MSE differences.

A positive \text{CLD}_{k,t} means forecast k has accumulated lower squared errors than the benchmark up to period t. A negative value means the benchmark has been more accurate up to that point.

Value

A ggplot object. The y-axis shows the cumulative MSE difference; forecasts above zero at the right edge have outperformed the benchmark over the full evaluation window. The top 2 and bottom 2 forecasts (by final cumulative loss difference) are labelled directly on the plot.

See Also

white_reality_check, plot_performance_metrics

Examples

data(metals)
P        <- nrow(metals)
K_total  <- ncol(metals)
realized <- c(metals[-1, K_total], metals[P, K_total])
errors   <- sweep(as.matrix(metals), 1, realized, "-")
p <- plot_cumulative_loss(errors, benchmark_col = K_total)
print(p)

RCtest documentation built on June 2, 2026, 9:07 a.m.