0
$\begingroup$

Please, put in R the following structure:

infl <- structure(list(infl = c(91.37, 91.8, 92.14, 92.65, 93.08, 93.17, 
93.08, 93.08, 93.34, 93.25, 93.17, 93.25, 93.59, 93.76, 94.27, 
94.7, 94.87, 94.79, 94.62, 94.7, 95.04, 95.21, 95.13, 95.3, 95.13, 
95.55, 95.98, 96.15, 96.07, 96.15, 95.98, 96.15, 96.49, 96.58, 
96.58, 96.92, 96.58, 96.83, 97.35, 97.86, 98.11, 98.2, 97.94, 
98.2, 98.28, 98.71, 98.63, 98.88, 98.2, 98.54, 99.31, 99.73, 
99.99, 100.08, 99.99, 100.25, 100.67, 100.93, 100.67, 101.1, 
100.62, 100.91, 101.47, 102.16, 102.44, 102.51, 102.36, 102.46, 
102.48, 102.51, 102.55, 102.96, 102.38, 102.7, 103.39, 104.05, 
104.31, 104.41, 104.14, 104.19, 104.59, 105.12, 105.69, 106.12, 
105.67, 106.04, 107.11, 107.46, 108.14, 108.54, 108.38, 108.22, 
108.42, 108.45, 107.9, 107.75, 106.82, 107.26, 107.66, 108.04, 
108.1, 108.27, 107.51, 107.89, 107.91, 108.17, 108.28, 108.61, 
107.75, 108.02, 109.09, 109.58, 109.71, 109.7, 109.32, 109.54, 
109.77, 110.15, 110.27, 110.93, 110.11, 110.57, 112.11, 112.75, 
112.74, 112.75, 112.03, 112.23, 113.08, 113.44, 113.54, 113.91, 
112.96, 113.53, 115.03, 115.56, 115.38, 115.29, 114.65, 115.1, 
115.97)), .Names = "infl", row.names = c("2001-01-31 00:00:00", 
"2001-02-28 00:00:00", "2001-03-31 01:00:00", "2001-04-30 01:00:00", 
"2001-05-31 01:00:00", "2001-06-30 01:00:00", "2001-07-31 01:00:00", 
"2001-08-31 01:00:00", "2001-09-30 01:00:00", "2001-10-31 00:00:00", 
"2001-11-30 00:00:00", "2001-12-31 00:00:00", "2002-01-31 00:00:00", 
"2002-02-28 00:00:00", "2002-03-31 00:00:00", "2002-04-30 01:00:00", 
"2002-05-31 01:00:00", "2002-06-30 01:00:00", "2002-07-31 01:00:00", 
"2002-08-31 01:00:00", "2002-09-30 01:00:00", "2002-10-31 00:00:00", 
"2002-11-30 00:00:00", "2002-12-31 00:00:00", "2003-01-31 00:00:00", 
"2003-02-28 00:00:00", "2003-03-31 01:00:00", "2003-04-30 01:00:00", 
"2003-05-31 01:00:00", "2003-06-30 01:00:00", "2003-07-31 01:00:00", 
"2003-08-31 01:00:00", "2003-09-30 01:00:00", "2003-10-31 00:00:00", 
"2003-11-30 00:00:00", "2003-12-31 00:00:00", "2004-01-31 00:00:00", 
"2004-02-29 00:00:00", "2004-03-31 01:00:00", "2004-04-30 01:00:00", 
"2004-05-31 01:00:00", "2004-06-30 01:00:00", "2004-07-31 01:00:00", 
"2004-08-31 01:00:00", "2004-09-30 01:00:00", "2004-10-31 01:00:00", 
"2004-11-30 00:00:00", "2004-12-31 00:00:00", "2005-01-31 00:00:00", 
"2005-02-28 00:00:00", "2005-03-31 01:00:00", "2005-04-30 01:00:00", 
"2005-05-31 01:00:00", "2005-06-30 01:00:00", "2005-07-31 01:00:00", 
"2005-08-31 01:00:00", "2005-09-30 01:00:00", "2005-10-31 00:00:00", 
"2005-11-30 00:00:00", "2005-12-31 00:00:00", "2006-01-31 00:00:00", 
"2006-02-28 00:00:00", "2006-03-31 01:00:00", "2006-04-30 01:00:00", 
"2006-05-31 01:00:00", "2006-06-30 01:00:00", "2006-07-31 01:00:00", 
"2006-08-31 01:00:00", "2006-09-30 01:00:00", "2006-10-31 00:00:00", 
"2006-11-30 00:00:00", "2006-12-31 00:00:00", "2007-01-31 00:00:00", 
"2007-02-28 00:00:00", "2007-03-31 01:00:00", "2007-04-30 01:00:00", 
"2007-05-31 01:00:00", "2007-06-30 01:00:00", "2007-07-31 01:00:00", 
"2007-08-31 01:00:00", "2007-09-30 01:00:00", "2007-10-31 00:00:00", 
"2007-11-30 00:00:00", "2007-12-31 00:00:00", "2008-01-31 00:00:00", 
"2008-02-29 00:00:00", "2008-03-31 01:00:00", "2008-04-30 01:00:00", 
"2008-05-31 01:00:00", "2008-06-30 01:00:00", "2008-07-31 01:00:00", 
"2008-08-31 01:00:00", "2008-09-30 01:00:00", "2008-10-31 00:00:00", 
"2008-11-30 00:00:00", "2008-12-31 00:00:00", "2009-01-31 00:00:00", 
"2009-02-28 00:00:00", "2009-03-31 01:00:00", "2009-04-30 01:00:00", 
"2009-05-31 01:00:00", "2009-06-30 01:00:00", "2009-07-31 01:00:00", 
"2009-08-31 01:00:00", "2009-09-30 01:00:00", "2009-10-31 00:00:00", 
"2009-11-30 00:00:00", "2009-12-31 00:00:00", "2010-01-31 00:00:00", 
"2010-02-28 00:00:00", "2010-03-31 01:00:00", "2010-04-30 01:00:00", 
"2010-05-31 01:00:00", "2010-06-30 01:00:00", "2010-07-31 01:00:00", 
"2010-08-31 01:00:00", "2010-09-30 01:00:00", "2010-10-31 01:00:00", 
"2010-11-30 00:00:00", "2010-12-31 00:00:00", "2011-01-31 00:00:00", 
"2011-02-28 00:00:00", "2011-03-31 01:00:00", "2011-04-30 01:00:00", 
"2011-05-31 01:00:00", "2011-06-30 01:00:00", "2011-07-31 01:00:00", 
"2011-08-31 01:00:00", "2011-09-30 01:00:00", "2011-10-31 00:00:00", 
"2011-11-30 00:00:00", "2011-12-31 00:00:00", "2012-01-31 00:00:00", 
"2012-02-29 00:00:00", "2012-03-31 01:00:00", "2012-04-30 01:00:00", 
"2012-05-31 01:00:00", "2012-06-30 01:00:00", "2012-07-31 01:00:00", 
"2012-08-31 01:00:00", "2012-09-30 01:00:00"), class = "data.frame")

It is Eurozone's CPI monthly time series.

Then an inflation estimate is

dinfl <- diff(log(infl))

I would like to get dinfl seasonality with the greatest possible accuracy; it's a stationary time series.

What would your suggestment be (model + package + function)?

Is there any chance of structural break which may require some analysis before? I remember something about bfast() package which allowed for structural break searching, I don't know if it could be useful here.

Many thanks,

$\endgroup$
2
$\begingroup$

To be fair, there is never a best model; they're all just simplifications of reality. For seasonality decomposition, base R offers a couple powerful options: decompose() and stl(). Here is the basics of how to apply it to your data:

infl.ts <- ts(infl$infl,start=c(2001,1),frequency=12)
plot(infl.ts)
plot(decompose(infl.ts,type='multiplicative'))
plot(stl(infl.ts,s.window='periodic'))
plot(stl(infl.ts,s.window=5))

stl() in particular is a very powerful decomposition technique with many parameters you can tune. In the first call I used stationary seasonality (s.window='periodic'). In the second one I used smoothing changing seasonality (s.window=5). There are some details in the help documents (?stl) and the referenced scholarly articles have far more info.

$\endgroup$
7
  • $\begingroup$ I did just realize I forgot to diff(log()) your data first. Doing so does seem to improve the fit based on the 'remainder' panel of the stl() plot. (As it should.) $\endgroup$ – Shea Parkes Nov 6 '12 at 13:36
  • 1
    $\begingroup$ And I forgot to promote Rob Hyndman's excellent online resource: otexts.com/fpp/6 $\endgroup$ – Shea Parkes Nov 6 '12 at 13:42
  • $\begingroup$ Thank you for your answer, Shea Parkes. Then I invite you to try stl() on my sample but considering just the observations starting from January 2009 till today: you will see a seasonal component which is much different from the one obtained by using stl() on the whole sample. Then I guess there must be some issue, like a structural break somewhere. Is it correct? stl() "sees" trend in differenced CPI time series, which should no be theoretically correct... $\endgroup$ – Lisa Ann Nov 6 '12 at 14:10
  • $\begingroup$ This is true, it does look for trend even if you pass it a diff'd time series. If you wanted to use stl() it might make the most sense to just log() the series so it will look for multiplicative seasonality. You're also right that there appears to be a structural break ~Jan-2009. For my job, seeing is believing; I've never looked into formal structural break identifiers. $\endgroup$ – Shea Parkes Nov 6 '12 at 21:46
  • $\begingroup$ Yesterday I used bfast() package to search for structural breaks, and it found it about on 2008 ~ 2009; it is simple to use, it works like stl() but the output highlights structural breaks (it's slower, though). When I find a break in trend component I guess it would be better using stl() from that date on, also if the seasonal component does not show any break... correct? $\endgroup$ – Lisa Ann Nov 7 '12 at 8:18

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.