statsmodels.tsa.seasonal.seasonal_decompose

statsmodels.tsa.seasonal.seasonal_decompose(x, model='additive', filt=None, freq=None, two_sided=True)[source]

Seasonal decomposition using moving averages

Parameters:

x : array-like

Time series

model : str {“additive”, “multiplicative”}

Type of seasonal component. Abbreviations are accepted.

filt : array-like

The filter coefficients for filtering out the seasonal component. The concrete moving average method used in filtering is determined by two_sided.

freq : int, optional

Frequency of the series. Must be used if x is not a pandas object. Overrides default periodicity of x if x is a pandas object with a timeseries index.

two_sided : bool

The moving average method used in filtering. If True (default), a centered moving average is computed using the filt. If False, the filter coefficients are for past values only.

Returns:

results : obj

A object with seasonal, trend, and resid attributes.

See also

statsmodels.tsa.filters.bk_filter.bkfilter, statsmodels.tsa.filters.cf_filter.xffilter, statsmodels.tsa.filters.hp_filter.hpfilter, statsmodels.tsa.filters.convolution_filter

Notes

This is a naive decomposition. More sophisticated methods should be preferred.

The additive model is Y[t] = T[t] + S[t] + e[t]

The multiplicative model is Y[t] = T[t] * S[t] * e[t]

The seasonal component is first removed by applying a convolution filter to the data. The average of this smoothed series for each period is the returned seasonal component.