| Title: | Size-Power Tradeoff Visualization for Equal Predictive Ability of Two Forecasts |
|---|---|
| Description: | Offers tools for visualizing and analyzing size and power properties of tests for equal predictive accuracy, including Diebold-Mariano and related procedures. Provides multiple Diebold-Mariano test implementations based on fixed-smoothing approaches, including fixed-b methods such as Kiefer and Vogelsang (2005) <doi:10.1017/S0266466605050565>, and applications to tests for equal predictive accuracy as in Coroneo and Iacone (2020) <doi:10.1002/jae.2756>, alongside conventional large-sample approximations. HAR inference involves nonparametric estimation of the long-run variance, and a key tuning parameter (the truncation parameter) trades off size and power. Lazarus, Lewis, and Stock (2021) <doi:10.3982/ECTA15404> theoretically characterize the size-power frontier for the Gaussian multivariate location model. 'ForeComp' computes and visualizes the finite-sample size-power frontier of the Diebold-Mariano test based on fixed-b asymptotics together with the Bartlett kernel. To compute finite-sample size and power, it fits a best approximating ARMA process to the input data and reports how the truncation parameter performs and how robust testing outcomes are to its choice. |
| Authors: | Nathan Schor [aut], Minchul Shin [aut, cre, cph] |
| Maintainer: | Minchul Shin <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 1.0.0 |
| Built: | 2026-05-22 05:59:02 UTC |
| Source: | https://github.com/mcmcs/forecomp |
Diebold-Mariano Test (Bartlett kernel, normal approximation). This is a two-sided test.
dm.test.bt(d, M = NA, Mopt = NA, cl = 0.05)dm.test.bt(d, M = NA, Mopt = NA, cl = 0.05)
d |
loss differential |
M |
truncation parameter for the Bartlett kernel (if |
Mopt |
option for automatic bandwidth, 1 if Lazarus et al. (2018), 2 if Newey and West (1994, default), 3 if Andrews textbook NW ( |
cl |
confidence level (default = 0.05, i.e., 5%) |
This function returns a class with the following elements
rej is a T/F value. TRUE (reject), FALSE (accept)
stat is a test statistic
pval is an associated p-value
Minchul Shin
Diebold-Mariano Test (Bartlett kernel, fixed-b approximation). This is a two-sided test.
dm.test.bt.fb(d, M = NA, Mopt = NA, cl = 0.05)dm.test.bt.fb(d, M = NA, Mopt = NA, cl = 0.05)
d |
loss differential |
M |
truncation parameter for the Bartlett kernel (if |
Mopt |
option for automatic bandwidth, 1 if Lazarus et al. (2018, default), 2 if Newey and West (1994), 3 if Andrews textbook NW ( |
cl |
confidence level (default = 0.05, i.e., 5%), Only 0.05 (5%) or 0.10 (10%) are allowed. |
This function returns a class with the following elements
rej is a T/F value. TRUE (reject), FALSE (accept)
stat is a test statistic
Minchul Shin
Randomization test based on asymptotic symmetry, |t|-test statistic
dm.test.cnr.t(d, q = 2, cl = 0.05)dm.test.cnr.t(d, q = 2, cl = 0.05)
d |
loss differential |
q |
number of blocks |
cl |
confidence level (default = 0.05, i.e., 5%) |
This function returns a class with the following elements
rej is a T/F value. TRUE (reject), FALSE (accept)
stat is a test statistic
pval is an associated p-value
Minchul Shin
Randomization test based on asymptotic symmetry, Wald-statistic
dm.test.cnr.w(d, q = 2, cl = 0.05)dm.test.cnr.w(d, q = 2, cl = 0.05)
d |
loss differential |
q |
number of blocks |
cl |
confidence level (default = 0.05, i.e., 5%) |
This function returns a class with the following elements
rej is a T/F value. TRUE (reject), FALSE (accept)
stat is a test statistic
pval is an associated p-value
Minchul Shin
Diebold-Mariano Test (EWC, fixed-b approximation). This is a two-sided test.
dm.test.ewc.fb(d, B = NA, Bopt = NA, cl = 0.05)dm.test.ewc.fb(d, B = NA, Bopt = NA, cl = 0.05)
d |
loss differential |
B |
truncation parameter for the EWC long-run variance estimator (if |
Bopt |
option for automatic bandwidth, 1 if Lazarus et al. (2018, default, |
cl |
confidence level (default = 0.05, i.e., 5%) |
This function returns a class with the following elements
rej is a T/F value. TRUE (reject), FALSE (accept)
stat is a test statistic
pval is an associated p-value
Minchul Shin
t-Statistic based HAR-inference by Ibragimov and Muller (2010).
dm.test.im(d, q = 2, cl = 0.05)dm.test.im(d, q = 2, cl = 0.05)
d |
loss differential |
q |
number of blocks. When |
cl |
confidence level (default = 0.05, i.e., 5%) |
This function returns a class with the following elements
rej is a T/F value. TRUE (reject), FALSE (accept)
stat is a test statistic
pval is an associated p-value
Minchul Shin
This function performs the Diebold-Mariano test with their original recommendation.
Let be a sequence of loss differential, .
Then, the function performs a statistical test for the following null hypothesis:
This function follows the original recommendation by Diebold and Mariano (1995),
where the long-run variance is estimated using the rectangular kernel truncated at
. This function performs a two-sided test. Normal approximation is used to calculate critical values.
dm.test.r(d, h = 1, cl = 0.05)dm.test.r(d, h = 1, cl = 0.05)
d |
loss differential |
h |
h-step-ahead forecast (default = 1, i.e., comparing one-step-ahead forecasts) |
cl |
confidence level (default = 0.05, i.e., 5%) |
This function returns a class with the following elements
rej is a T/F value. TRUE (reject), FALSE (accept)
stat is a test statistic
pval is an associated p-value
Minchul Shin
Diebold-Mariano Test (Modified-DM). Finite-sample modification to the original DM's test. This is a two-sided test.
dm.test.r.m(d, h = 1, cl = 0.05)dm.test.r.m(d, h = 1, cl = 0.05)
d |
loss differential |
h |
h-step-ahead forecast (default = 1, i.e., one-step-ahead forecasts) |
cl |
confidence level (default = 0.05, i.e., 5%) |
This function is based on dm.test in the "forecast" package on CRAN.
This function returns a class with the following elements
rej is a T/F value. TRUE (reject), FALSE (accept)
stat is a test statistic
pval is an associated p-value
Minchul Shin
Diebold-Mariano Test (WPE, fixed-m approximation). This is a two-sided test. See Coroneo and Iacone (2020)
dm.test.wpe.fb(d, M = NA, Mopt = NA, cl = 0.05)dm.test.wpe.fb(d, M = NA, Mopt = NA, cl = 0.05)
d |
loss differential |
M |
truncation parameter for the WPE long-run variance estimator (if |
Mopt |
option for automatic bandwidth, 1 if Coroneo and Iacone's default value (M = floor(T^(1/3))) |
cl |
confidence level (default = 0.05, i.e., 5%) |
This function returns a class with the following elements
rej is a T/F value. TRUE (reject), FALSE (accept)
stat is a test statistic
pval is an associated p-value
Minchul Shin
This function computes the loss differential from two point forecasts. Let and
be point forecasts generated by the forecaster 1 (e.g., forecasting model 1) and the forecaster 2 (e.g., forecasting model 2), respectively.
is a forecasting target that both and try to forecast.
For a given loss function the loss differential is defined and computed as
for .
loss.diff.p(y, f1, f2, type = "quad", ...)loss.diff.p(y, f1, f2, type = "quad", ...)
y |
actual value, |
f1 |
point forecast 1, |
f2 |
point forecast 2, |
type |
Type of loss functions to compare.
|
... |
Extra parameters to compute loss function.
|
Type of loss functions. Define .
Quadratic loss function is defined as
Absolute loss function is defined as
Check loss function is defined as
Linex loss function is defined as
If c is positive (negative) real number, then the linex function is exponential (linear) for e>0 and linear (exponential) for e<0.
A sample average of the returned sequence, , is the difference in average loss from forecaster 1 and forecaster 2.
Positive means that the forecaster 2 incurs lower expected loss compared to the forecaster 1.
Negative means that the forecaster 1 incurs lower expected loss compared to the forecaster 2.
Statistical testing to test whether the loss differential is zero in expectation is possible. See, for example, dm.test.r.
This function returns a sequence of the loss differential, .
Minchul Shin
A dataset containing y, f1, f2 based on one of McCracken (2019)'s data generating processes. The name of the specification is "Unconditional-Rolling". R = 175, Rbar = 175, h = 12, P = 75; Note that the DGP is constructed in a way that there is no difference between f1 and f2 in terms of expected quadratic loss.
mikedatamikedata
A data frame with 75 rows and 3 variables:
Forecast target
Point forecast based on forecasting model 1
Point forecast based on forecasting model 2
Simulated data.
Error Statistics for the Survey of Professional Forecasters for GNP/GDP Price Index
PGDPPGDP
'PGDP' A data frame with 219 rows and 31 columns
<https://www.philadelphiafed.org/-/media/frbp/assets/surveys-and-data/survey-of-professional-forecasters/data-files/pgdp/data_spf_error_statistics_pgdp_3_aic.xls?la=en&hash=148987D03D54DA5391A44F28CBC12729>
'Plot_Tradeoff' creates a plot to show sensitivity of statistical significance to the choice of bandwidth and how size distortion and maximum power loss vary. It is designed for the Diebold-Mariano test for equal predictive accuracy (Diebold and Mariano, 1995). For a size-power tradeoff plot, see Lazarus, Lewis, Stock, and Watson (2018) and Lazarus, Lewis, and Stock (2021).
Plot_Tradeoff( data, f1 = NULL, f2 = NULL, y = NULL, loss_function = NULL, n_sim = 1000, m_set = NULL, cl = 0.05, verbose = TRUE, no_m_label = FALSE, na_handling = c("zero", "drop", "error") )Plot_Tradeoff( data, f1 = NULL, f2 = NULL, y = NULL, loss_function = NULL, n_sim = 1000, m_set = NULL, cl = 0.05, verbose = TRUE, no_m_label = FALSE, na_handling = c("zero", "drop", "error") )
data |
A data frame. |
f1 |
Column containing forecaster 1's predictions. Should be a string. |
f2 |
Column containing forecaster 2's predictions. Should be a string. |
y |
Column containing the realized value for the outcome variable. Should be a string. |
loss_function |
The transformation applied to the forecast error. Defaults to squared error loss. The user supplied function should take two inputs and a scalar output, loss = loss_function(f, y). For example, quadratic loss function would be defined as |
n_sim |
The number of simulations used to generate the ARIMA model. Defaults to 1,000. |
m_set |
The truncation parameter. If |
cl |
Significance level used in the hypothesis test. Defaults to 0.05. Only 0.05 and 0.10 are currently supported because the fixed-b approximation is implemented for these levels. |
verbose |
TRUE to print out the progress to the console. Defaults to TRUE. |
no_m_label |
TRUE to plot without m labels. Defaults to FALSE. |
na_handling |
How to handle missing/non-finite loss differentials. |
A list of length 2. The first element is a ggplot2 object of the size-power tradeoff. The second element is the underlying data used to construct the plot in element 1.
Nathan Schor and Minchul Shin
Diebold, F. X. & Mariano, R. S. (1995), Comparing Predictive Accuracy, Journal of Business & Economic Statistics, 13(3), 253-263.
Lazarus, E., Lewis, D. J., Stock, J. H. & Watson, M. W. (2018), HAR Inference: Recommendations for Practice, Journal of Business & Economic Statistics, 36(4), 541-559.
Lazarus, E., Lewis, D. J. & Stock, J. H. (2021), The Size-Power Tradeoff in HAR Inference, Econometrica, 89(5), 2497-2516.
# A typical example set.seed(1234) output = Plot_Tradeoff( data = TBILL, f1 = "SPFfor_Step1", f2 = "NCfor_Step1", y = "Realiz1", m_set = seq(from = 1, to = 70, by = 10) ) output[[1]] # The first element is a ggplot2 object of the size-power tradeoff. output[[2]] # The second element is the underlying data used to construct the plot in element 1. # An example with a user supplied loss function # To use the mean absolute error as a loss function rather than a quadratic loss function set.seed(1234) output = Plot_Tradeoff( data = TBILL, f1 = "SPFfor_Step1", f2 = "NCfor_Step1", y = "Realiz1", loss_function = function(f,y){ abs(f-y) }, m_set = seq(from = 1, to = 50, by = 10) ) # An example without (f1, f2, y). The function will take the first three columns and use them set.seed(1234) tmpdata = TBILL[, c("SPFfor_Step1", "NCfor_Step1", "Realiz1")] # data with [f1, f2, y] Plot_Tradeoff( data = tmpdata, m_set = seq(from = 1, to = 50, by = 10) )# A typical example set.seed(1234) output = Plot_Tradeoff( data = TBILL, f1 = "SPFfor_Step1", f2 = "NCfor_Step1", y = "Realiz1", m_set = seq(from = 1, to = 70, by = 10) ) output[[1]] # The first element is a ggplot2 object of the size-power tradeoff. output[[2]] # The second element is the underlying data used to construct the plot in element 1. # An example with a user supplied loss function # To use the mean absolute error as a loss function rather than a quadratic loss function set.seed(1234) output = Plot_Tradeoff( data = TBILL, f1 = "SPFfor_Step1", f2 = "NCfor_Step1", y = "Realiz1", loss_function = function(f,y){ abs(f-y) }, m_set = seq(from = 1, to = 50, by = 10) ) # An example without (f1, f2, y). The function will take the first three columns and use them set.seed(1234) tmpdata = TBILL[, c("SPFfor_Step1", "NCfor_Step1", "Realiz1")] # data with [f1, f2, y] Plot_Tradeoff( data = tmpdata, m_set = seq(from = 1, to = 50, by = 10) )
Error Statistics for the Survey of Professional Forecasters for Real GNP/GDP
RGDPRGDP
'RDGP' A data frame with 219 rows and 31 columns
<https://www.philadelphiafed.org/-/media/frbp/assets/surveys-and-data/survey-of-professional-forecasters/data-files/rgdp/data_spf_error_statistics_rgdp_3_aic.xls?la=en&hash=3AC9E2D8A5299F93CA7E16CFAA974C22>
Error Statistics for the Survey of Professional Forecasters for Treasury Bill Rate (Three Month)
TBILLTBILL
'TBILL' A data frame with 219 rows and 31 columns
<https://www.philadelphiafed.org/-/media/frbp/assets/surveys-and-data/survey-of-professional-forecasters/data-files/tbill/data_spf_error_statistics_tbill_1_aic.xls?la=en&hash=F432350F84B0E4CCE9A1E9D399447CA9>
Error Statistics for the Survey of Professional Forecasters for Unemployment Rate
UNEMPUNEMP
'UNEMP' A data frame with 219 rows and 31 columns
<https://www.philadelphiafed.org/-/media/frbp/assets/surveys-and-data/survey-of-professional-forecasters/data-files/unemp/data_spf_error_statistics_unemp_1_aic.xls?la=en&hash=4CAD0B11FEAB6C4D0F30C38965FE3354>