[R] Having problem with forecast.Arima() function
Berend Hasselman
bhh at xs4all.nl
Mon Aug 5 09:03:42 CEST 2013
On 05-08-2013, at 07:47, Salaam Batur <swordlight20 at gmail.com> wrote:
> Dear R users,
>
> I am having a problem using forecast.Arima fuction. Here is the whole code:
>
> d=scan("D:/Data.txt")
> d
> D=ts(data=d, start=1981,end=2012, frequency=1)
> D
> Time Series:
> Start = 1981
> End = 2012
> Frequency = 1
> [1] 384 403 427 450 499 550 575 615 640 680 702 730 760 790
> [15] 790 830 870 871 906 920 968 1010 1060 1111 1165 1191 1217 1221
> [29] 1089 1089 1090 1103
>
Please use dput to show objects.
> lnD=log(D)
> lnD3=diff(lnD, differences=3)
> adf.test(lnD3)
> Augmented Dickey-Fuller Test
>
> data: lnD3
> Dickey-Fuller = -3.5315, Lag order = 3, p-value = 0.05795
> alternative hypothesis: stationary
>
> #########d parameter is determined by ADF test, which is 3#############
>
> Now choosing p and q parameters
>
> par(mfrow=c(2,1))
> acf(lnD3, lag.max=20)
> pacf(lnD3, lag.max=20)
>
> ######### from acf and pacf, p=2, q=1##############
>
> Now fitting Arima
>
> arima1=arima(lnD3, order=c(2,0,1))
> arima1
> Series: x
> ARIMA(2,0,1) with non-zero mean
>
> Coefficients:
> ar1 ar2 ma1 intercept
> -0.5189 -0.2033 -1.0000 -1e-04
> s.e. 0.1806 0.1770 0.0993 5e-04
>
> sigma^2 estimated as 0.00118: log likelihood=54.24
> AIC=-100.48 AICc=-97.87 BIC=-93.64
>
> ####### Which looks good#########
>
> Using auto.arima() to see what R have in mind
>
> autoarima=auto.arima(lnD, d=3)
> autoarima
> Series: lnD
> ARIMA(2,3,0)
>
> Coefficients:
> ar1 ar2
> -1.0282 -0.5851
> s.e. 0.1524 0.1560
>
> sigma^2 estimated as 0.001731: log likelihood=50.37
> AIC=-94.73 AICc=-93.77 BIC=-90.63
>
> ###### From AIC and BIC, I prefer arima1 instead of autoarima######
> Now using forecast.Arima
>
> forecastArima1=foreca.Arima(arima1, h=5)
> *Warining message
> Error in ts(x) : 'ts' object must have one or more observations*
>
I assume that this should be forecast.Arima
> But forecasting autoarima is no problem
> forecastAutoArima=forecast.Arima(autoarima, h=5, c=(0.95))
> forecastAutoArima
>
> Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
> 2013 7.084688 7.031373 7.138004 7.003150 7.166227
> 2014 7.167079 7.049206 7.284951 6.986808 7.347349
> 2015 7.285478 7.069813 7.501142 6.955648 7.615308
> 2016 7.443636 7.085484 7.801789 6.895890 7.991383
> 2017 7.618670 7.081729 8.155612 6.797489 8.439852
>
> Why???? Is there a bug probelm with arima() function itself???
>
This not reproducible code.
Which packages have you loaded?
adf.test, auto.arima and forecast.Arima are not standard.
So using package sos told me that I needed package tseries and forecast.
Using your data and your code gave me this for the code starting at auto.arima:
autoarima=auto.arima(lnD, d=3)
> autoarima
Series: lnD
ARIMA(2,3,0)
Coefficients:
ar1 ar2
-1.0282 -0.5851
s.e. 0.1524 0.1560
sigma^2 estimated as 0.001731: log likelihood=50.37
AIC=-94.73 AICc=-93.77 BIC=-90.63
>
> forecastArima1=forecast.Arima(arima1, h=5)
> forecastArima1
Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
2013 -0.0212777938 -0.06606177 0.02350618 -0.08976898 0.04721339
2014 0.0088824273 -0.07130043 0.08906529 -0.11374668 0.13151153
2015 -0.0004052589 -0.08451693 0.08370641 -0.12904295 0.12823243
2016 -0.0017177972 -0.08583008 0.08239448 -0.13035643 0.12692083
2017 0.0008517381 -0.08342997 0.08513345 -0.12804602 0.12974949
>
> forecastAutoArima=forecast.Arima(autoarima, h=5, c=(0.95))
> forecastAutoArima
Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
2013 7.084688 7.031373 7.138004 7.003150 7.166227
2014 7.167079 7.049206 7.284951 6.986808 7.347349
2015 7.285478 7.069813 7.501142 6.955648 7.615308
2016 7.443636 7.085484 7.801789 6.895890 7.991383
2017 7.618670 7.081729 8.155612 6.797489 8.439852
So you must be doing something other than what you have shown.
Berend
> If anyone knows the problem, or shows me a right direction, I would really
> appreciate it!!!
> Many many thanks!!!
>
> Chintemur Batur
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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.
More information about the R-help
mailing list