Search code examples
rtime-seriesforecastingets

strange result when using r ets() function for analyzing CPI data


everyone. I just started to learn time series.

I have the following monthly CPI data (2010.01 - 2015.12) from China.

I would like to do some forecast with this data using ets() function from R.

vector1 <- c(100.6, 101.2, 99.3, 100.2, 99.9, 99.4, 100.4, 100.6, 100.6, 100.7, 101.1, 100.5, 101.0, 101.2, 99.8, 100.1, 100.1, 100.3, 100.5, 100.3, 100.5, 100.1, 99.8, 100.3, 101.5, 99.9, 100.2, 99.9, 99.7, 99.4, 100.1, 100.6, 100.3, 99.9, 100.1, 100.8, 101.0, 101.1, 99.1, 100.2, 99.4, 100.0, 100.1, 100.5, 100.8, 100.1, 99.9, 100.3, 101.0, 100.5, 99.5, 99.7, 100.1, 99.9, 100.1, 100.2, 100.5, 100.0, 99.8, 100.3, 100.3, 101.2, 99.5, 99.8, 99.8, 100.0, 100.3, 100.5, 100.1, 99.7, 100.0, 100.5)

I tried to follow the procedure from the following link: https://stats.stackexchange.com/questions/146098/ets-function-how-to-avoid-forecast-not-in-line-with-historical-data

The code is as follows:

train_ts<- ts(vector1, frequency=12)
fit2<-ets(train_ts, model="ZZZ", damped=TRUE, alpha=NULL, beta=NULL, gamma=NULL, 
        phi=NULL, additive.only=FALSE, lambda=TRUE, 
        lower=c(0.000,0.000,0.000,0.8),upper=c(0.9999,0.9999,0.9999,0.98), 
        opt.crit=c("lik","amse","mse","sigma","mae"), nmse=3, 
        bounds=c("both","usual","admissible"), ic=c("aicc","aic","bic"),
        restrict=TRUE)  
ets <- forecast(fit2,h=5,method ='ets') 

plot(forecast(fit2))
lines(fit2$states[,1],col='red')

However, I got the following graph which looks weird. And I get alpha =0, beta =0 and gamma = 0... which seems to mean I have no trend and no seasonality?

enter image description here

Sorry that I have many questions..

  1. Does the forecast look right? I think something is wrong here, but I could not figure out what is the problem.

  2. what does "fit2$states[,1]" stand for? what does the red line stand for?

Thanks a lot for all your kind helps..

I then tried to use part of the data vector[1:43]. what I got is ... enter image description here


Solution

  • First, smoothing parameters close to zero do not mean that you have no level, trend, or seasonality. They mean that the level, trend or seasonality do not change over time. See https://www.otexts.org/fpp/7.

    Second, you do not specify the version of the forecast package that you are using, or even that you are using the forecast package. So let's try your code using the current version of the package:

    library(forecast)
    vector1 <- c(100.6, 101.2, 99.3, 100.2, 99.9, 99.4, 100.4, 100.6,
      100.6, 100.7, 101.1, 100.5, 101.0, 101.2, 99.8, 100.1, 100.1, 100.3,
      100.5, 100.3, 100.5, 100.1, 99.8, 100.3, 101.5, 99.9, 100.2, 99.9,
      99.7, 99.4, 100.1, 100.6, 100.3, 99.9, 100.1, 100.8, 101.0, 101.1,
      99.1, 100.2, 99.4, 100.0, 100.1, 100.5, 100.8, 100.1, 99.9, 100.3,
      101.0, 100.5, 99.5, 99.7, 100.1, 99.9, 100.1, 100.2, 100.5, 100.0,
      99.8, 100.3, 100.3, 101.2, 99.5, 99.8, 99.8, 100.0, 100.3, 100.5,
      100.1, 99.7, 100.0, 100.5)
    train_ts <- ts(vector1, frequency=12)
    fit2 <- ets(train_ts, damped=TRUE)  
    ets <- forecast(fit2, h=5) 
    plot(forecast(fit2))
    lines(fit2$states[,1],col='red')
    

    enter image description here

    That looks ok to me, and not the same as what you posted.

    The first column of the states matrix contains the level of the series. In this case, the level goes through the middle of the data as you would expect.