To perform the Diebold-Mariano test in R using two models, you will need to have the forecasted values from both models.
Here is an example of how to conduct the Diebold-Mariano test using the dm.test function from the forecast package:
309 chars10 lines
Make sure to replace the model1 and model2 vectors with your own forecasted values from the two models you want to compare.
The dm.test function computes the Diebold-Mariano test statistic and p-value, indicating whether there is a statistically significant difference in forecast accuracy between the two models. The null hypothesis is that the two models have the same forecast accuracy.
Make sure to install the forecast package if you haven't already done so by using the following command: install.packages("forecast").
gistlibby LogSnag