To conduct the Diebold-Mariano test in R, you'll need to follow these steps:
47 chars3 lines
Prepare your forecasts and actual values vectors. Let's assume you have two vectors: forecast1
and forecast2
, containing the forecasted values for two different models, and a vector actual
containing the actual values.
Calculate the forecast errors:
58 chars3 lines
dm.test()
to perform the test:51 chars2 lines
By default, dm.test()
assumes that the differences of errors are normally distributed, and it performs a two-sided test. The alternative can also be set to "less" or "greater" if you have a specific hypothesis about which model is better.
Remember that the Diebold-Mariano test assumes that the errors are uncorrelated and have constant variance, so it should be used with caution and in combination with other evaluation metrics.
Please note that you will need to adjust the steps according to your specific data and models.
gistlibby LogSnag