Search code examples
rforecasting

n step ahead simulation of SARIMA process using R forecast package


I want to simulate an SARIMA process nsteps ahead, with nsim paths. I've already fitted the model, and the 'forecast' package has a 'simulate' function. However as far as I can see whilst it includes an nsim argument it only simulates 1 step ahead? Is this possible with the 'forecast' package?

https://robjhyndman.com/hyndsight/simulating-from-a-specified-seasonal-arima-model/

What I'm trying to achieve is work out the standard error of the sum of auto-correlated residuals (where the SARIMA model is fitted to the residuals of a model which exhibits auto-correlated residuals). So I want to perform monte-carlo simulation nsteps ahead, sum the values per simulation then work out the standard deviation of the sums.


Solution

  • nsim is the number of observations to simulate ahead. Set it to whatever you like. Here is an example.

    library(forecast)
    library(ggplot2)
    fit <- auto.arima(USAccDeaths)
    autoplot(USAccDeaths, series="Data") +
      autolayer(simulate(fit, nsim=36), series="Simulated")
    

    Created on 2019-07-30 by the reprex package (v0.3.0)