I have started learning time series forecasting and struggling a bit with the concept of differencing, particularly for (S)ARIMA(X) model, which is often recommended model to start with.

I am trying to predict website visitors using media/marketing spend as exogenous variable, which has quite good positive correlation 0.7 with the website traffic.

My timeseries looks like this: Visitors

As we can see the data contains strong annual seasonality. In order to make the data stationary, I've defined for each day a comparable day from the last year (usually same week and weekday, but sometimes can be same week promotion starting day Mon vs Wed).

After applying the differencing my timeseries looks like below: enter image description here

So still the data is not stationary, and would require to remove the trend component as well by subtracting the previous day. (Adfuller test p value 0.4)

Now, subtracting previous observations to remove the trend: enter image description here

Now the data doesn't look predictable to me, but rather noise. Anyhow, when I use the exogenous variable marketing spend with ARIMA model, I get the results that looks like this for 21 days period (I tried applying the same differencing also for media spend but the ARIMA ended up doing a flat forecast then as well):

enter image description here

As you can see the ARIMA model prediction is flat throughout the 21 days forecast horizon. Clearly I am not doing it right, and would appreciate any tips or suggestions for further reading/learning. Also, would be interesting to hear from the experts what kind of models you would be applying for such timeseries?


1 Answer 1


I am assuming, in your last plot y is the explanatory variable (marketing spend), and AutoARIMA is the the forecast of the target variable (website visitors). For me this forecast makes sense. Just a flat line, because April is an "average month" (meaning: no special events, like Christmas, that would influence website visits). I can also see the influence of marketing on this plot: when it goes up, visits also go up.

I think you did a good job with the seasonal differencing, and then the normal differencing. At this point I would try a simple ARIMA model (no explanatory variable) just to have a baseline. But now you could make a step back: plot your target and explanatory variable on the same plot. Maybe the seasonality pattern is due to the marketing spends applied seasonally.

Also use your "business knowledge": Do you think marketing spend effects the visits or the trend of the visits? In the first case difference visits and marketing or none of them. In the second case difference just the visits, but not the marketing. In lot of cases a marketing spend on day_1 will effect visits on day_1 and day_2 and day_3, etc. In this case you might try to use a transfer function instead of just one coefficient to model this dependency (transfer functions are part of the ARIMAX methodology).

Calculate and plot forecast intervals! This will give you more insight into the fitted model, and also tells you, if the forecast is useful. When your model contains differencing, the forecast intervals may increase very quickly over time (because forecast errors are accumulated over time) - this makes the forecast less useful. What does you "business sense" tell you? Precision of forecast should be as good 5 days ahead and 21 days ahead? In that case try to avoid the "trend removing differencing".

Consider using a logarithmic transformation on visits. But only if you think this is what captures the "true underlying data generation mechanism". When business people talk, do they say "we had a 1000 visit growth"(perhaps no transform needed), or "we had a 1% growth"(I would use the log transform here)?

Use a holdout sample to validate your model!

Your second plot looks like the trend in this time series is very special: slow increase, fast increase, than decrease. State space models are able to capture such "local trends".

  • 1
    $\begingroup$ Thank you so much for the great answer, very insightful for me, and got plenty of new ideas to look into. Just to add for the last plot where is AutoARIMA and y, this is actually the test set, so comparing the arima model (predictions) against the actuals, and seeing if it captures the underlying trend. $\endgroup$
    – miroslaavi
    Commented May 6 at 19:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.