Does anybody know of a routine to do seasonal adjustment in Python or even better, in R? Here is an example data-set (South African CPI), which tends to have spikes in the first few months of the year:
I would like to find the underlying pressures stripping out the seasonal factors, but I'd ideally like to use something fairly straightforward, built into either language, rather than interfacing or using outright an external package such as Demetra.
Seasonality testseasonal_decompose() tests whether a time series has a seasonality or not by removing the trend and identify the seasonality by calculating the autocorrelation(acf). The output includes the number of period, type of model(additive/multiplicative) and acf of the period.
For analyzing short-term price trends in the economy, seasonally adjusted changes are usually preferred since they eliminate the effect of changes that normally occur at the same time and in about the same magnitude every year—such as price movements resulting from changing climatic conditions, production cycles, model ...
Calculating a Seasonally Adjusted Annual Rate (SAAR) To calculate SAAR, take the un-adjusted monthly estimate, divide by its seasonality factor, and multiply by 12. Analysts start with a full year of data, and then they find the average number for each month or quarter.
Step 1. Define the data.
(Obtained from http://www.statssa.gov.za/publications/P0141/P0141February2011.pdf)
CPI <- c(102.3, 103.1, 104.3, 105.7, 106.2, 106.6, 107, 108.2, 108.5, 108.9,
108.9, 108.9, 109.2, 109.5, 110.2, 111.1, 111.3, 111.5, 111.5,
112.2, 112.3, 112.4, 112.6, 112.8, 113, 113.5, 114.3)
Step 2. Calculate monthly change in index, and convert to time series object.
dCPI <- ts(CPI[-1] - CPI[-length(CPI)], start=2008, frequency=12)
Step 3. Use the function stl()
to calculate seasonal, trend and residuals:
plot(stl(dCPI, "periodic"))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With