Closed tyumru closed 6 years ago
nnetar uses recursive forecasting. So just grab the second forecast produced. If you want to use a direct multi-step forecasting strategy, you will need to write your own code.
I assume you're fitting something along the lines of nnetar(y[1:(T-1)], ...)
and thus forecast.nnetar
starts the prediction at T
?
@robjhyndman is this behavior different from the other forecast.xxx
methods? (EDIT: nevermind, just saw your reply above as I was writing this comment)
With the current implementation, following the example in the documentation, you could do:
## Fit model to first 100 years of lynx data
fit <- nnetar(window(lynx,end=1920), decay=0.5, maxit=150)
## Apply fitted model to later data, including all optional arguments
fit2 <- nnetar(window(lynx,start=1921), model=fit)
forecast(fit2)
then forecast(fit2)
will start after the end of the time series (year 1935 in the lynx example data).
Alternatively, the following code with produce the same effect:
## Fit model to first 100 years of lynx data
fit3 <- nnetar(lynx, decay=0.5, maxit=150, subset=1:100)
forecast(fit3)
@gabrielcaceres thank you for your answer, I was not aware of this functionality. @robjhyndman thank you for this great package.
Hey there,
In the below line of function
fcast <- ts(fcast, start = tspx[2] + 1 / tspx[3], frequency = tspx[3])
Here, the start time of the fcast is assumed to be in the next period, however it might not be the case.
For instance, let's say we fit the model using the data until T-1 and we would like to predict T+1 (i.e. we provide an xreg with Start=T+1). In this case forecast.nnetar returns a fcast$mean with Start = T, instead of T+1.