How to loop Arima

574 views Asked by At

I have a question on using R studio to take Arima test on more than one time series. For example, I have three clients with three time series in 4 periods.

Client 1 client 2 client 3

1 3 7

2 5 3

4 3 1

5 8 9

Now I want to predict the next period after 5/8/9. I know how to use Arima to predict time series one by one, but in practice I have lots of clients and it will take too much time. Could u plz teach me how to do a loop or use lapply or so on to make things easier?

Also, when picking the order of Arima, I only know to use Ident to generate figures of ACF and PACF to tell the orders of MA and AR, which will not work on a large amount of time series - I feel unwise to draw hundreds of figures. Do you have any good advice to tell the order of Arima? Thank you!

1

There are 1 answers

1
Ujjwal Kumar On

apply would help you apply the same function to every column (if you have each column as one time-series). Please learn how to use it, there are a lot of examples on internet.

If you have a lot of time-series, and you want to avoid manual work, auto.arima should come in handy. In case you're not satisfied with its results:

  1. Try finding general rules first. That is, if you know that each of the time-series would be seasonal(with same season-length), you know that you need seasonal-differencing for all. Same thing can be said about long-term trend. These inferences could also be made algorithmically.

  2. Irrespective of whether 1 is applicable or not, in order to decide best value for parameters, you have to code up the logic which you use to decide AR and MA parameters manually. The simpler your manual logic, the easier its to code. One simple rule of thumb is to keep AR + MA = 1, chose AR if ACF falls gradually, MA if it falls rapidly. What is rapid and what is gradual would have to be decided by your code only.