source<- c(10930,10318,10595,10972,7706,6756,9092,10551,9722,10913,11151,8186,6422,
6337,11649,11652,10310,12043,7937,6476,9662,9570,9981,9331,9449,6773,6304,9355,10477,
10148,10395,11261,8713,7299,10424,10795,11069,11602,11427,9095,7707,10767,12136,12812,
12006,12528,10329,7818,11719,11683,12603,11495,13670,11337,10232,13261,13230,15535,
16837,19598,14823,11622,19391,18177,19994,14723,15694,13248,9543,12872,13101,15053,
12619,13749,10228,9725,14729,12518,14564,15085,14722,11999,9390,13481,14795,15845,
15271,14686,11054,10395,14775,14618,16029,15231,14246,12095,10473,15323,15381,14947)
测试数据的时间序列图,如下:
data<-xts(data,seq(as.POSIXct("2014-01-01"),len=length(data),by="day"))
plot(data)
通过以下代码:
data_diff1<-diff(data,differences=1)
plot(data_diff1)
data_diff2<-diff(data,differences=2)
plot(data_diff2)
acf <- acf(data_diff1,lag.max=100,plot=FALSE)
plot(acf)
pacf <- pacf(data_diff1,lag.max=100,plot=FALSE)
plot(pacf)
ARMA(p,q)模型的ACF与PACF理论模式
模型 |
ACF |
PACF |
AR(p) |
衰减趋于零(几何型或振荡型) |
p阶后截尾 |
MA(q) |
q阶后截尾 |
衰减趋于零(几何型或振荡型) |
ARMA(p,q) |
q阶后衰减趋于零(几何型或振荡型) |
p阶后衰减趋于零(几何型或振荡型) |
data.fit <- arima(data,order=c(7,1,0), seasonal=list(order=c(1,1,0), period=7))
data.fit
Series: data
ARIMA(7,1,0)(1,1,0)[7]
Coefficients:
ar1 ar2 ar3 ar4 ar5 ar6 ar7 sar1
-0.2829 -0.2128 -0.0180 0.0606 0.3164 0.0415 -0.0883 -0.5075
s.e. 0.1040 0.1076 0.1076 0.1048 0.1062 0.1066 0.1520 0.1449
sigma^2 estimated as 1589493: log likelihood=-789.34
AIC=1596.68 AICc=1598.88 BIC=1619.38
|
forecast <- forecast.Arima(data.fit,h=7,level=c(99.5))
forecast
plot.forecast(forecast)
Forecast Lo 80 Hi 80 Lo 95 Hi 95
101 15206.61 13590.892 16822.33 12735.583 17677.64
102 14654.18 12665.935 16642.42 11613.422 17694.94
103 11589.60 9388.579 13790.62 8223.428 14955.77
104 10190.69 7742.040 12639.34 6445.803 13935.58
105 14362.50 11640.733 17084.26 10199.919 18525.07
106 14785.77 11620.577 17950.96 9945.025 19626.52
107 15501.02 12049.124 18952.91 10221.802 20780.23
|
tsdiag(data.fit)
残差没有明显的自相关性
所有的P-value>0.5, 说明残差为白噪声
*最近正在看这一块的东西,有些地方还没弄太明白,尤其是公式原理,若有不正确的地方,欢迎指正。