2
$\begingroup$

On the section "STL decomposition" in the 2nd edition of Forecasting: Principles and Practice, it says that the seasadj() function can be used to compute the seasonally adjusted series but it does not say how this seasonally adjusted series is computed. I'm wondering how to do this in python's statsmodel package as there is no such seasadj function.

If I have an STL decomposition like so: enter image description here

would the seasonally adjusted series be the trend + remainder? Just the trend?

In python:

from statsmodels.tsa.seasonal import STL

stl_decomp = STL(series, period=12, seasonal=7).fit()
stl_seas_adj = stl_decomp.trend + stl_decomp.resid

Is this the correct way to compute the seasonally adjusted data?

$\endgroup$

1 Answer 1

3
$\begingroup$

From the statsmodels docs, stl.fit() returns a DecomposeResult object. This has the estimated seasonal component of the time series decomposition. Subtracting this from the original time series should then provide you with a seasonally-adjusted time series.

$\endgroup$
3
  • $\begingroup$ which is effectively the same thing as stl_seas_adj = stl_decomp.trend + stl_decomp.resid then. $\endgroup$ Commented Sep 14, 2023 at 23:19
  • 1
    $\begingroup$ that is stl_decomp.trend + stl_decomp.resid = stl_decomp.observed - stl_decomp.seasonal $\endgroup$ Commented Sep 14, 2023 at 23:20
  • $\begingroup$ Correct. You can verify this in your code. Also, be aware of this method only working if it's additive. If the decomposition is multiplicative, neither way will work to get the seasonally adjusted data $\endgroup$ Commented Sep 14, 2023 at 23:39

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.