MAPAx example for R

I have been asked a few time to provide an example how to use MAPAx, from the MAPA package for R, so I prepared this blog post. I admit the documentation could be better, so I put together this example from a retailing case – the original setting MAPAx was developed for (see paper here). This provides a step by step use of MAPAx.

As you can see, MAPA provides a flat forecast. This is “correct” in the sense that apart from promotions this time series contains like information that could be captured by exponential smoothing. On the other hand, MAPAx is provided with the promotional information and makes use of it.

10 thoughts on “MAPAx example for R”

Really appreciate the how-to, but can you fix the formatting? Also, I think you may have forgot the library(MAPA) line (should be obvious, but you never know if a new R user is trying the code). Thanks again for the example!

I have this issue when I select “MAPA” package. i know this is due to “smooth” package but raised it because I use only MAPA and smooth is required for “MAPA”. I have raised it as an issue in github for forecast package. I have cross posted it below. Appreciate all your help to the forecasting community.

I get following error when I use forecast function. The problem arises due to conflict with “smooth” package. I need to select smooth package because “MAPA” package requires it.

Error in UseMethod(“forecast”) :
no applicable method for ‘forecast’ applied to an object of class “c(‘ARIMA’, ‘Arima’)”

Not sure. The easiest way to get the xreg part working is to imput the complete matrix in both the estimation and forecast functions. It should be able to find what sample to use on its own from the target variable. It does not use dates to do that, but it counts observations, so the X’s do not have to be time series.

MAPAx sounds like an interesting alternative that would be worth trying out.

My experience with using ARIMAX and ETS so far in predicting 7-day forecasts for SKUs is that both models are very sensitive to trends just before the forecasting horizon: e.g. if the last 1-2 days see an increase in sales, both models assume an increase in every single day of the horizon leading to bad forecasting accuracy especially in the latest 3-7 days of the horizon where they extrapolate that initial trend too much .

If you have such experience yourself, do you know how MAPAx deals with ‘last-minute’ trends that do not last?

By construction MAPA and MAPAx would be resistant to such changes, as short term movements would be filtered out in the temporally aggregate views of the time series. Therefore, even if on the original sampling frequency the ETS model might have poor performance, at an aggregate level it would be more robust and eventually the final MAPA forecast that would combine information from both would be resistant to these effects.