robjhyndman / forecast

Forecasting Functions for Time Series and Linear Models
http://pkg.robjhyndman.com/forecast
1.1k stars 340 forks source link

dm.test function #939

Closed SantiagoD999 closed 10 months ago

SantiagoD999 commented 1 year ago

Good morning professor Hyndman,

Working with your excellent package forecast, I am using the dm.test function. I want to compare twenty 21 step-ahead forecasts, but I am not sure if the correct way of defining the dm.test function is dm.test(e1,e2),h=21, varestimator = "bartlett"), because I get this warning:

Warning message: In 2 (1 - b/(m + 1)) d.cov[-1] : longer object length is not a multiple of shorter object length

Here I send an small reproducible example supposing x and y are twenty 21-step ahead forecasts produced by some model.

set.seed(1) x<-ts(rnorm(20)) y<-ts(rnorm(20)) autoplot(x)+autolayer(y) dm.test(as.numeric(x),as.numeric(y),h=21,varestimator = "bartlett")

Thank you ver much.

robjhyndman commented 1 year ago

With only 20 observations, you can't have h=21. I've added a check to return a better error message when this occurs.

SantiagoD999 commented 1 year ago

Thank you, but that means that the definition of the function: dm.test(e1,e2),h=21, varestimator = "bartlett") for N 21-ahead forecasts (where N>h), is correct?

robjhyndman commented 1 year ago

Yes, I believe the function is correct.