I have a monthly inflation data. From 1999/01 to 2014/10.
I made an AR(1) model, with data from 1999/01 to 2007/12, which gaves me: Yt = 0.0057 + 0.6212Yt-1 ;
data<-read.table("C:/TimeSeries/Inflation/inflation.txt", header=T, dec=",")
data.ts <- ts(data, start=c(1999,01), freq=12)
time = window(data.ts, start=c(1999,01),end=c(2007,12))
inflarima<-Arima(time,order=c(1,0,0))
inflarima
As the theory says my first prediction should be: Et(Yt+1) = 0.0057 + 0.6212Yt ; The second: 0.0057 + 0.6212*0.0057 + (0.6212^2)*Yt and so on... Right ???
So, my first period prediction is january 2008, which gives a value of (0,0057 + 0,6212*Y2007,12 = (0,0057 + 0,6212*0.003790990 = 0,008054962988) 0,008054962988
stat=c(2008,01) #First Prediction will be january 2008
out_of_sample=window(data.ts,start=stat) #out of sample data
recurs.pred1=ts(0,start=stat,end=c(2014,7),frequency=12) #Matrix to put the predictions through RECURSIVE METHOD
for (t in 1:(length(dado_de_fora))) {
reg.recur1=Arima(window(time,end=c(2007,3+t)),c(1,0,0))
recurs.pred1[t]=predict(reg.recur1,n.ahead=1)$pred #y chapeu de 1T2008, modelo Arma(1,1)
}
The values of my pedictions:
recurs.pred1[]
Jan Feb Mar Apr May .......
2008 0.004556208 0.003796366 0.003965125 0.003948726 0.003681815 .......
Here starts the problem:
Jan
2008 0.004556208
HOW i got this value ???!! the right value supposed to be 0,008054962988 , am i Right?
These are the data: from: 1999/01 to 2014/07
You've committed several errors, both methodological and conceptual.
First error, I think, is from the lack of your understanding of AR(1): one step ahead forecast is not a+bY{t}
, it is rather a*(1-b)+b*Y{t}
. Your theory is wrong. Consult your textbook or documentation of the arima
to clinch the matter. Thus, your forecast of Jan 2008 must be
> 0.0057*(1-0.6212) + 0.6212*0.003790990
[1] 0.004514123
Secondly, you have monthly based monthly inflation rates, so the argument in reg.recur1=Arima(window(time,end=c(2007, 3+t)),c(1,0,0))
must be 11+t
. (What is Arima
?)
Finally, it is just plain wrong to fit inflation data in levels to AR(1). Oftentimes, it is suitable to fit the first difference of inflation, i.e. increase in inflation.
Following little example might help. I roughly followed your code.
library(forecast)
set.seed(20141221)
x <- arima.sim(n=108, list(ar=0.5))
data.ts <- ts(x, start=c(1999,01), freq=12)
time = window(data.ts, start=c(1999,01),end=c(2007,12))
inflarima <- arima(time, order = c(1, 0, 0)) #
inflarima$coef
# ar1 intercept
#0.4945659 0.2069526
#1-step ahead forecast
0.4945659*time[108] + 0.2069526*(1-0.4945659)
#[1] 0.1147776
forecast(inflarima, h=1) #use forecast rather than predict. returns the same.
# Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
#Jan 2008 0.1147776 -0.9938675 1.223423 -1.580749 1.810304