开发者

Seasonal Adjustment in R or Python

D开发者_JS百科oes 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:

Seasonal Adjustment in R or Python

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.


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"))

Seasonal Adjustment in R or Python


http://mail.scipy.org/pipermail/scipy-user/2010-January/023847.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜