Dear R users,
Please let me know how to plot the forecast in such a model:
First I do it simple with ARIMA model that works ok with the codes provided to 
me at the lecture:

arima<-arima(HCPIlong, order=c(1,1,0))

arima.predict<-predict(arima, n.ahead= 5 )

ts.plot(HCPIlong,arima.predict$pred,lty=1:2, main="Forecast of HCPI")


But I need to include the additional variable in my model to check if it helps 
to predict the outcome:
First I built the OLS model with the same lagged variable (HCPI, look the 
series below): 

ar<- lm(diff(HCPIlong)[2:16]~diff(HCPIlong)[1:15]-1)

ar.predict<-predict(ar, n.ahead=5)


and then the same + Wages:

ar1<-lm(diff(HCPIlong)[2:16]~diff(HCPIlong)[1:15]+diff(wageslong)[1:15]-1)


ar1.predict<-predict(ar1, n.ahead=5)

ts.plot(HCPIlong,ar1.predict$pred,lty=1:2)


(or: 
ar2<-lm(diff(HCPIlong)[2:16]~diff(wageslong)[1:15]-1)

ar2.predict<-predict(ar2, n.ahead=5))


but when I try to plot it with codes that were used in ARIMA the program 
reports the mistake:
'Error in ar1.predict$pred : $ operator is invalid for atomic vectors'

If I try to do it without $:
ts.plot(HCPIlong,ar1.predict)
Error in .cbind.ts(list(...), .makeNamesTs(...), dframe = dframe, union = TRUE) 
: 
  non-time series not of the correct length

Does it exists the code how to plot it together with historical data or how to 
include the additional variable in the first ARIMA model?

Thank you in advance,
Olga

Series:
Year HCPI
1993 4.8
1994 2.91
1995 2.75
1996 1.03
1997 1.81
1998 1.03
1999 0.55
2000 1.29
2001 2.67
2002 1.93
2003 2.34
2004 1.02
2005 0.82
2006 1.5
2007 1.68
2008 3.35

Year  Wage
1993  2.9
1994  2.4
1995  3.3
1996  6.0
1997  4.5
1998  3.7
1999  3.4
2000  3.7
2001  4.4
2002  4.1
2003  3.5
2004  3.3
2005  3.1
2006  3.1
2007  3.3
2008  4.3


        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to