> library("zoo")
> library("forecast")
> library("fUnitRoots")
>
> setwd("D:/R")
> jl<-read.table("hegang2.txt")
> jl
V1
1 1.76
2 1.76
3 1.93
4 1.81
5 1.81
6 1.86
7 1.98
8 2.06
9 2.28
10 2.52
11 2.82
12 3.83
13 3.43
14 3.53
15 4.33
16 5.37
17 5.05
18 7.00
19 7.00
20 4.44
21 3.11
22 3.25
23 3.11
24 3.33
25 2.96
26 3.01
27 3.05
28 3.20
29 2.79
30 2.77
31 2.86
32 3.35
33 3.08
34 3.13
35 3.22
36 3.34
37 3.82
38 3.91
39 3.61
40 5.04
41 4.44
42 4.19
43 5.52
44 4.78
45 4.40
46 4.19
47 4.15
48 3.90
>
> x<-ts(jl,start=c(2015,1),frequency=12)
> x
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
2015 1.76 1.76 1.93 1.81 1.81 1.86 1.98 2.06 2.28 2.52 2.82 3.83
2016 3.43 3.53 4.33 5.37 5.05 7.00 7.00 4.44 3.11 3.25 3.11 3.33
2017 2.96 3.01 3.05 3.20 2.79 2.77 2.86 3.35 3.08 3.13 3.22 3.34
2018 3.82 3.91 3.61 5.04 4.44 4.19 5.52 4.78 4.40 4.19 4.15 3.90
>
> plot(x)
> acf(x)
> pacf(x)
>
> x.fit<-HoltWinters(x,gamma=F)
> x.fit
Holt-Winters exponential smoothing with trend and without seasonal component.
Call:
HoltWinters(x = x, gamma = F)
Smoothing parameters:
alpha: 1
beta : 0
gamma: FALSE
Coefficients:
[,1]
a 3.9
b 0.0
> plot(x.fit)
>
> x.fore<-forecast(x.fit,h=12)
> x.fore
Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
Jan 2019 3.9 3.0155573 4.784443 2.5473615 5.252638
Feb 2019 3.9 2.6492091 5.150791 1.9870804 5.812920
Mar 2019 3.9 2.3681002 5.431900 1.5571615 6.242839
Apr 2019 3.9 2.1311145 5.668885 1.1947231 6.605277
May 2019 3.9 1.9223259 5.877674 0.8754085 6.924592
Jun 2019 3.9 1.7335666 6.066433 0.5867260 7.213274
Jul 2019 3.9 1.5599844 6.240016 0.3212550 7.478745
Aug 2019 3.9 1.3984181 6.401582 0.0741607 7.725839
Sep 2019 3.9 1.2466718 6.553328 -0.1579154 7.957915
Oct 2019 3.9 1.1031465 6.696854 -0.3774184 8.177418
Nov 2019 3.9 0.9666353 6.833365 -0.5861942 8.386194
Dec 2019 3.9 0.8362005 6.963800 -0.7856771 8.585677
> plot(x.fore)
>
>
>
> auto.arima(x,trace=T)
ARIMA(2,1,2)(1,0,1)[12] with drift : Inf
ARIMA(0,1,0) with drift : 100.7521
ARIMA(1,1,0)(1,0,0)[12] with drift : 105.3491
ARIMA(0,1,1)(0,0,1)[12] with drift : 105.3141
ARIMA(0,1,0) : 98.78144
ARIMA(0,1,0)(1,0,0)[12] with drift : 103.0058
ARIMA(0,1,0)(0,0,1)[12] with drift : 103.0133
ARIMA(0,1,0)(1,0,1)[12] with drift : Inf
ARIMA(1,1,0) with drift : 102.977
ARIMA(0,1,1) with drift : 102.9323
ARIMA(1,1,1) with drift : 103.9286
Best model: ARIMA(0,1,0)
Series: x
ARIMA(0,1,0)
sigma^2 estimated as 0.4581: log likelihood=-48.35
AIC=98.69 AICc=98.78 BIC=100.54
>
> a<-arima(x,order=c(0,1,0))
>
> for(i in 1:2) print(Box.test(a$residual,lag=6*i))
Box-Pierce test
data: a$residual
X-squared = 5.259, df = 6, p-value = 0.5111
Box-Pierce test
data: a$residual
X-squared = 6.3729, df = 12, p-value = 0.8961
>
> x.fore1<-forecast(a,h=12)
> x.fore1
Point Forecast Lo 80 Hi 80 Lo 95 Hi 95
Jan 2019 3.9 3.0325721 4.767428 2.57338354 5.226616
Feb 2019 3.9 2.6732717 5.126728 2.02388101 5.776119
Mar 2019 3.9 2.3975708 5.402429 1.60223289 6.197767
Apr 2019 3.9 2.1651442 5.634856 1.24676708 6.553233
May 2019 3.9 1.9603723 5.839628 0.93359542 6.866405
Jun 2019 3.9 1.7752443 6.024756 0.65046659 7.149533
Jul 2019 3.9 1.6050016 6.194998 0.39010276 7.409897
Aug 2019 3.9 1.4465435 6.353457 0.14776202 7.652238
Sep 2019 3.9 1.2977164 6.502284 -0.07984938 7.879849
Oct 2019 3.9 1.1569522 6.643048 -0.29512960 8.095130
Nov 2019 3.9 1.0230672 6.776933 -0.49988904 8.299889
Dec 2019 3.9 0.8951417 6.904858 -0.69553422 8.495534
> plot(x.fore1)