Professional Documents
Culture Documents
Expt. 12 Forecasting 214
Expt. 12 Forecasting 214
Expt. 12 Forecasting 214
______________________________________________________________________________
Q1. Aim: To check whether the forecast errors are normally distributed with mean zero and
constant variance. Also plot the ACF and PACF plot.
Code:
volcanodust=scan("http://robjhyndman.com/tsdldata/annual/dvi.dat",skip=1)
volcanodust
volcanoseries=ts(volcanodust,start=c(1500))
volcanoseries
plot.ts(volcanoseries)
acf(volcanoseries,lag.max = 20,plot=FALSE)
pacf(volcanoseries,lag.max=20,plot = FALSE)
library(forecast)
model=auto.arima(volcanoseries)
model
auto.arima(volcanoseries,ic="aic",trace = TRUE)
myfore=forecast::forecast(model,level=c(95),h=31)
myfore
plot(myfore)
plot.ts(myfore$residuals)
hist(myfore$residuals)
Output:
Autocorrelation of series
0 1 2 3 4 5 6 7 8 9 10
1 0.666 0.374 0.162 0.046 0.017 - 0.016 0.021 0.006 0.01
0.007
11 12 13 14 15 16 17 18 19 20
0.004 0.024 0.075 0.082 0.064 0.039 0.005 0.028 0.108 0.182
Partial autocorrelation of series
1 2 3 4 5 6 7 8 9 10
0.666 -0.126 -0.064 -0.005 0.04 -0.039 0.058 -0.016 -0.025 0.028
11 12 13 14 15 16 17 18 19 20
-0.008 0.036 0.082 -0.025 -0.014 0.008 -0.025 0.073 0.131 0.063
Series: volcanoseries
ARIMA(1,0,2) with non-zero mean
Coefficients:
ar1 ma1 ma2 mean
0.4723 0.2694 0.1279 57.5178
s.e. 0.0936 0.0969 0.0752 8.4883
sigma^2 = 4897: log likelihood = -2661.84
AIC=5333.68 AICc=5333.81 BIC=5354.45
Fitting models using approximations to speed things up...
ARIMA(2,0,2) with non-zero mean : 5334.08
ARIMA(0,0,0) with non-zero mean : 5614.16
ARIMA(1,0,0) with non-zero mean : 5336.8
ARIMA(0,0,1) with non-zero mean : 5404.21
ARIMA(0,0,0) with zero mean : 5758.893
ARIMA(1,0,2) with non-zero mean : 5331.912
ARIMA(0,0,2) with non-zero mean : 5350.019
ARIMA(1,0,1) with non-zero mean : 5332.533
ARIMA(1,0,3) with non-zero mean : 5333.205
ARIMA(0,0,3) with non-zero mean : 5334.578
ARIMA(2,0,1) with non-zero mean : 5332.595
ARIMA(2,0,3) with non-zero mean : 5334.89
ARIMA(1,0,2) with zero mean : 5360.125
Now re-fitting the best model(s) without approximations...
ARIMA(1,0,2) with non-zero mean : 5333.682
Best model: ARIMA(1,0,2) with non-zero mean
Series: volcanoseries
ARIMA(1,0,2) with non-zero mean
Coefficients:
ar1 ma1 ma2 mean
0.4723 0.2694 0.1279 57.5178
s.e. 0.0936 0.0969 0.0752 8.4883
sigma^2 = 4897: log likelihood = -2661.84
AIC=5333.68 AICc=5333.81 BIC=5354.45
Point Forecast Lo 95 Hi 95
1970 22.67720 -114.4732 159.8276
1971 38.42748 -132.3340 209.1890
1972 48.50091 -134.4268 231.4286
1973 53.25886 -132.2742 238.7920
1974 55.50617 -130.6032 241.6155
1975 56.56763 -129.6701 242.8053
1976 57.06898 -129.1973 243.3353
1977 57.30579 -128.9669 243.5785
1978 57.41764 -128.8565 243.6917
1979 57.47046 -128.8040 243.7449
1980 57.49542 -128.7791 243.7699
1981 57.50720 -128.7673 243.7817
1982 57.51277 -128.7617 243.7873
1983 57.51540 -128.7591 243.7899
1984 57.51664 -128.7579 243.7912
1985 57.51723 -128.7573 243.7917
1986 57.51750 -128.7570 243.7920
1987 57.51764 -128.7569 243.7921
1988 57.51770 -128.7568 243.7922
1989 57.51773 -128.7568 243.7922
1990 57.51774 -128.7568 243.7923
1991 57.51775 -128.7568 243.7923
1992 57.51775 -128.7568 243.7923
1993 57.51775 -128.7568 243.7923
1994 57.51775 -128.7568 243.7923
1995 57.51775 -128.7568 243.7923
1996 57.51775 -128.7568 243.7923
1997 57.51775 -128.7568 243.7923
1998 57.51775 -128.7568 243.7923
1999 57.51775 -128.7568 243.7923
2000 57.51775 -128.7568 243.7923
Result:
a) We see from the correlogram that the autocorrelations for lags 1, 2 and 3 exceed the
significance bounds, and that the autocorrelations tail off to zero after lag 3. The
autocorrelations for lags 1, 2, 3 are positive, and decrease in magnitude with increasing lag
(lag 1: 0.666, lag 2: 0.374, lag 3: 0.162).
b) From the partial auto correlogram, we see that the partial autocorrelation at lag 1 is
positive and exceeds the significance bounds (0.666), while the partial autocorrelation at lag
2 is negative and also exceeds the significance bounds (-0.126). The partial autocorrelations
tail off to zero after lag 2.
c) The time plot of forecast errors shows that the forecast errors seem to have roughly
constant variance over time. However, the time series of forecast errors seems to have a
negative mean, rather than a zero mean. We can confirm this by calculating the mean forecast
error, which turns out to be about -0.22:
d) The histogram of forecast errors (above) shows that although the mean value of the
forecast errors is negative, the distribution of forecast errors is skewed to the right compared
to a normal curve. Therefore, it seems that we cannot comfortably conclude that the forecast
errors are normally distributed with mean zero and constant variance.
Coefficients:
ar1 ar2 ma1
-0.2817 0.0529 0.3107
s.e. 0.1548 0.0081 0.1550
ARIMA(2,1,1) : 187701.5
Series: data
ARIMA(2,1,1)
Coefficients:
ar1 ar2 ma1
-0.2817 0.0529 0.3107
s.e. 0.1548 0.0081 0.1550
Q3. Aim: To forecast the traffic on Jet Rail for the next 7 months.
Code:
data=read.csv("C:\\Users\\LENOVO\\Downloads\\Train_SU63ISt.csv")
head(data)
plot.ts(data)
mymode=auto.arima(data)
mymode
auto.arima(data,ic="aic",trace=TRUE)
forecast1=forecast::forecast(mymode,level=c(95),h=24)
forecast1
plot(forecast1)
Solution:
Series: data
ARIMA(2,1,1)
Coefficients:
ar1 ar2 ma1
-0.2817 0.0529 0.3107
s.e. 0.1548 0.0081 0.1550
ARIMA(2,1,1) : 187701.5
Series: data
ARIMA(2,1,1)
Coefficients:
ar1 ar2 ma1
-0.2817 0.0529 0.3107
s.e. 0.1548 0.0081 0.1550