# How to fit a stepwise regression with ARIMA errors using Arima function in R?

I am fitting a regression model with ARIMA errors in R using the Arima function from the forecast package. I assume that the function takes all predictors from a matrix that I assign to the xreg argument. Thus regression is fitted using all of them and the output is produced accordingly.

Now, I appreciate that coefficients with high p-values are likely to have no impact on the overall outcome, however I would like to understand how I could fit a stepwise regression using Arima function.

On a side note, how would I go about fitting a regularised regression (LASSO or ridge) with ARIMA errors -- either through Arima function, or other means?

• Stepwise is a terrible method of variable selection. This has been discussed here many times. – Peter Flom Jan 14 at 12:21
• @PeterFlom thank you for your comment -- I appreciate stepwise has some limitations, but my question is not about its advantages or disadvantages, it's about applying stepwise in Arima function. – Dmitry Ishutin Jan 14 at 13:35
• @PeterFlom: What method of variable selection would you recommend instead of the stepwise method? – Isabella Ghement Jan 14 at 15:34
• The best is substantive knowledge and a priori hypotheses. For automatic methods, I like LASSO. – Peter Flom Jan 14 at 21:00
• @IsabellaGhement, thank you for your inputs. I will try as you suggested to use glm(), but I have a highly seasonal data with multiple seasonal cycles, hence I know that residuals will always be seasonally correlated, therefore I am fitting SARIMA to tackle this. I am still looking forward to a tidy solution where both stepwise regression and ARIMA fitting could be done on the fly, like it's done in Arima function from the forecast package, which only fits a standard regression with all input variables. – Dmitry Ishutin Jan 16 at 10:53