2
$\begingroup$

I'm using statsmodels.tsa.seasonal.seasonal_decompose to remove seasonality from a time series. I can remove a seasonal component in this way:

import pandas as pd
from statsmodels.tsa.seasonal import seasonal_decompose

df = pd.read_csv('data.csv') 
# giving me a dataframe of columns ds and y, ds being a timestamp and y the signal

signal = df.y - seasonal_decompose(df.y, freq=7).seasonal

That makes signal the raw data with weekly seasonality removed.

What I want to do is remove all 4 seasonal components (weekly, monthly, quarterly, yearly) in this way, but I'm not sure whether to do it in the order of largest period to smallest or vice versa. For example I might do:

w = seasonal_decompose(df.y, freq=7)
r = df.y - w.seasonal
m = seasonal_decompose(r, freq=30)
r = r - m.seasonal
q = seasonal_decompose(r, freq=91)
r = r - q.seasonal
y = seasonal_decompose(r, freq=365)
r = r - y.seasonal

or, the reverse:

y = seasonal_decompose(df.y, freq=365)
r = df.y - w.seasonal
q = seasonal_decompose(r, freq=91)
r = r - m.seasonal
m = seasonal_decompose(r, freq=30)
r = r - q.seasonal
w = seasonal_decompose(r, freq=7)
r = r - y.seasonal

Which is preferable, and ideally why?

$\endgroup$
2
$\begingroup$

do it simulataneously with a SARMAX model https://autobox.com/pdfs/SARMAX.pdf where you disallow identification of the pulses, level shifts, local time trends and ARIMA structure

Daily data is often sufficiently handled with day-of-the-week and monthly indicators. If the data is based upon human habits then we often get day-of-the-month , lead and lag effects around holidays , day-of-the-month wt al.

Annual effects if the exist can be usually handled with level shifts or deterministic time trends .Seldom do we see quarterly effects being needed if monthly effects are in place.

| cite | improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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