1
$\begingroup$

My goal is to extract the seasonality of a product's grocery sales time series.

I know standard time series decomposition when a time series is expressed as $𝑦_𝑡=𝑇_𝑡+𝑆_𝑡+𝑅_𝑡$, the sum (for an additive model) of a trend component, a seasonal component and the remainder. Currently in Python, I use the seasonal_decompose function from the statsmodels library.

I know that wit a certain regularity, the seller gives a discount on the product in form of a promotion. Since I know the exact periods of the promotion, I would like to control for this information before decomposing the time series in order to make sure that the promotional effect is not falsely attributed to the seasonality. What methods/libraries could I use to control for this additional regressor?

$\endgroup$

1 Answer 1

1
$\begingroup$

A simple approach would be to first fit a regression of sales on explanatory variables capturing the promotion. This could be anything from a single Boolean dummy regressor to a larger model capturing price points, discount percentages, or any other attributes of the promotions. Promotions can get very complicated indeed. You can start with a simple model and analyze it for as long as your time box allows, just be sure not to overparameterize it too much.

Then take the residuals from that regression and decompose those, using STL or whatever other method you prefer, like Exponential Smoothing.

This approach is very similar to a "regression with ARIMA models", which is what ARIMA models typically fit in the presence of explanatory variables. Rob Hyndman's blog post on "The ARIMAX model muddle" gives a very nice overview about the differences between this and an ARIMAX model, much of which is applicable to your decomposition question.

$\endgroup$
5
  • $\begingroup$ Thank you very much for your reponse, suggestion and the link to the video :-) $\endgroup$ Commented Mar 3, 2023 at 13:46
  • $\begingroup$ Can I ask one more thing. Imagine I want to estimate the seasonality for the future. At first, I thought I just use the seasonality estimated on the historical data. However, events such as easter vary from year to year and cannot be found in past data. Do you have an idea of how to approach this? $\endgroup$ Commented Mar 9, 2023 at 16:18
  • $\begingroup$ As long as you know when events like these occur, you can feed them in as Boolean explanatory variables: a long sequence of zeros with a few ones at the time points when this event occurred. (Which can mean Easter Sunday itself, or the two weeks before, or the week after, depending on your data.) Then use an approach as above. $\endgroup$ Commented Mar 9, 2023 at 18:21
  • $\begingroup$ Thank you very much for your response. So you would add the binary "easter variable" to the regression (next to the promo variables)? In a next step, I would do the decomposition on the residual from the regression, which gives me the seasonality (for everything except easter). In a final step, I can add the coefficient from the regression to the seasonality (for easter). $\endgroup$ Commented Mar 9, 2023 at 20:40
  • 1
    $\begingroup$ Yes, pretty much. In the final step, you can calculate a fit or forecast including or excluding Easter, per your preference. $\endgroup$ Commented Mar 9, 2023 at 20:48

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.